Skip to content

Commit 48cea9d

Browse files
Merge pull request #13 from codefresh-io/k8s-custom-res
Fix custom objects in yaml
2 parents 19d4be7 + e7cb154 commit 48cea9d

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

cf-deploy-kubernetes.sh

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
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+
325
fatal() {
426
echo "ERROR: $1"
527
exit 1
@@ -55,7 +77,10 @@ KUBECTL_OBJECTS=/tmp/deployment.objects
5577
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
5678
if [ $? != 0 ]; then
5779
cat ${KUBECTL_OBJECTS}.errors
58-
fatal "Failed to parse $deployment_file "
80+
echo "Failed to parse $deployment_file with kubectl... "
81+
echo "Using alternative parsing method... "
82+
truncate -s 0 $KUBECTL_OBJECTS
83+
objects $DEPLOYMENT_FILE | tee $KUBECTL_OBJECTS
5984
fi
6085

6186
DEPLOYMENT_NAME=$(awk '/^Deployment /{a=$2}END{print a}' $KUBECTL_OBJECTS)
@@ -68,3 +93,4 @@ if [ -n "$DEPLOYMENT_NAME" ]; then
6893
echo "---> Waiting for a successful deployment/${DEPLOYMENT_NAME} status to namespace ${KUBERNETES_NAMESPACE} ..."
6994
timeout -s SIGTERM -t $KUBERNETES_DEPLOYMENT_TIMEOUT kubectl --context "${KUBECONTEXT}" --namespace "${KUBERNETES_NAMESPACE}" rollout status deployment/"${DEPLOYMENT_NAME}" || fatal "Deployment Failed"
7095
fi
96+

0 commit comments

Comments
 (0)