Skip to content

Commit bd6d67a

Browse files
authored
🌱 update-operator-dev-deployment.sh: Fail if background job fails. (#1713)
1 parent cafb6b8 commit bd6d67a

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

hack/update-operator-dev-deployment.sh

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,18 @@ if ! echo "$current_context" | grep -P '.*-admin@.*-mgt-cluster'; then
6666
fi
6767

6868
branch=$(git branch --show-current)
69+
70+
# No branch name was found. Try to get a git-tag.
6971
if [ "$branch" == "" ]; then
70-
echo "failed to get branch name"
72+
branch=$(git describe --tags --exact-match 2>/dev/null || echo "")
73+
fi
74+
75+
if [ "$branch" == "" ]; then
76+
echo "failed to find git branch/tag name"
7177
exit 1
7278
fi
7379

80+
# Build tag for container image.
7481
tag="dev-$USER-$branch"
7582
tag="$(echo -n "$tag" | tr -c 'a-zA-Z0-9_.-' '-')"
7683

@@ -81,27 +88,43 @@ image="$image_path/caph-staging:$tag"
8188
make generate-manifests
8289
kustomize build config/crd | kubectl apply -f -
8390
} &
91+
pid_generate=$!
8492

85-
# run in background2
93+
# run in background
8694
{
8795
docker build -f images/caph/Dockerfile -t "$image" .
8896
docker push "$image"
8997
} &
98+
pid_docker_push=$!
9099

91-
wait
100+
# wait for both processes and check their exit codes
101+
if ! wait $pid_generate; then
102+
echo "Error: generate-manifests/kustomize failed"
103+
exit 1
104+
fi
105+
106+
if ! wait $pid_docker_push; then
107+
echo "Error: docker build/push failed"
108+
exit 1
109+
fi
92110

111+
# Find namespace of caph deployment.
93112
ns=$(kubectl get deployments.apps -A | { grep caph-controller || true; } | cut -d' ' -f1)
94113
if [[ -z $ns ]]; then
95114
echo "failed to get namespace for caph-controller"
96115
exit 1
97116
fi
98117

118+
# Scale deployment to 1.
99119
kubectl scale --replicas=1 -n "$ns" deployment/caph-controller-manager
100120

101121
kubectl set image -n "$ns" deployment/caph-controller-manager manager="$image"
102122

123+
# Set imagePullPolicy to "Always", so that a new image (with same name/tag) gets pulled.
103124
kubectl patch deployment -n "$ns" -p '[{"op": "replace", "path": "/spec/template/spec/containers/0/imagePullPolicy", "value": "Always"}]' --type='json' caph-controller-manager
104125

126+
# If you update the image again, there might be no change the deployment spec.
127+
# Force a rollout:
105128
kubectl rollout restart -n "$ns" deployment caph-controller-manager
106129

107130
trap "echo 'Interrupted! Exiting...'; exit 1" SIGINT

0 commit comments

Comments
 (0)