Skip to content

Commit 254f8d4

Browse files
authored
Remove 'kubectl convert' (#35)
* Remove 'kubectl convert' * Remove test info * Fix yaml parsing * Bump version
1 parent 7af420c commit 254f8d4

File tree

2 files changed

+15
-33
lines changed

2 files changed

+15
-33
lines changed

cf-deploy-kubernetes.sh

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,5 @@
11
#!/bin/bash
22

3-
parse_yaml() {
4-
local prefix=$2
5-
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
6-
sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
7-
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
8-
awk -F$fs '{
9-
indent = length($1)/2;
10-
vname[indent] = $2;
11-
for (i in vname) {if (i > indent) {delete vname[i]}}
12-
if (length($3) > 0) {
13-
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
14-
printf("%s%s%s=%s\n", "'$prefix'",vn, $2, $3);
15-
}
16-
}'
17-
}
18-
19-
20-
objects() {
21-
parse_yaml $1 | awk -F"=" '/metadata_name=/ && i==1 {print (NF>1)? $NF : " "; i=0} /kind=/{printf (NF>1)? $NF : "";printf " "; i=1}'
22-
}
23-
24-
253
fatal() {
264
echo "ERROR: $1"
275
exit 1
@@ -98,25 +76,29 @@ DEPLOYMENT_FILE=${deployment_file}-$(date '+%y-%m-%d_%H-%M-%S').yml
9876
$(dirname $0)/template.sh "$deployment_file" > "$DEPLOYMENT_FILE" || fatal "Failed to apply deployment template on $deployment_file"
9977

10078

101-
echo "---> Kubernetes objects to deploy in $deployment_file :"
79+
echo -e "\n\n---> Kubernetes objects to deploy in $deployment_file :"
10280
KUBECTL_OBJECTS=/tmp/deployment.objects
103-
kubectl convert -f "$DEPLOYMENT_FILE" --local=true --no-headers=true -o=custom-columns="KIND:{.kind},NAME:{.metadata.name}" > >(tee $KUBECTL_OBJECTS) 2>${KUBECTL_OBJECTS}.errors
81+
kubectl apply \
82+
--context "${KUBECONTEXT}" \
83+
--namespace "${KUBERNETES_NAMESPACE}" \
84+
--dry-run \
85+
-f "$DEPLOYMENT_FILE" \
86+
-o go-template \
87+
--template '{{ if .items }}{{ range .items }}{{ printf "%-30s%-50s\n" .kind .metadata.name}}{{end}}{{else}}{{ printf "%-30s%-50s\n" .kind .metadata.name}}{{end}}' \
88+
> >(tee $KUBECTL_OBJECTS) 2>${KUBECTL_OBJECTS}.errors
89+
10490
if [ $? != 0 ]; then
105-
cat ${KUBECTL_OBJECTS}.errors
106-
echo "Failed to parse $deployment_file with kubectl... "
107-
echo "Using alternative parsing method... "
108-
truncate -s 0 $KUBECTL_OBJECTS
109-
objects $DEPLOYMENT_FILE | tee $KUBECTL_OBJECTS
91+
echo -e "\nERROR Failed to parse ${deployment_file}"
92+
cat ${KUBECTL_OBJECTS}.errors
11093
fi
11194

11295
DEPLOYMENT_NAME=$(awk '/^Deployment /{a=$2}END{print a}' $KUBECTL_OBJECTS)
11396

114-
echo "---> Submitting a deployment to Kubernetes by
97+
echo -e "\n\n---> Submitting a deployment to Kubernetes by
11598
kubectl --context "${KUBECONTEXT}" --namespace "${KUBERNETES_NAMESPACE}" $KUBECTL_ACTION "
11699
kubectl --context "${KUBECONTEXT}" --namespace "${KUBERNETES_NAMESPACE}" $KUBECTL_ACTION -f "$DEPLOYMENT_FILE" || fatal "Deployment submitting Failed"
117100

118101
if [ -n "$DEPLOYMENT_NAME" ]; then
119102
echo "---> Waiting for a successful deployment/${DEPLOYMENT_NAME} status to namespace ${KUBERNETES_NAMESPACE} ..."
120103
timeout -s SIGTERM $KUBERNETES_DEPLOYMENT_TIMEOUT kubectl --context "${KUBECONTEXT}" --namespace "${KUBERNETES_NAMESPACE}" rollout status deployment/"${DEPLOYMENT_NAME}" || fatal "Deployment Failed"
121-
fi
122-
104+
fi

service.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version: 16.1.0
1+
version: 16.1.1

0 commit comments

Comments
 (0)