Skip to content

Commit cd1e5f9

Browse files
Cluster deletion improvements (#1088)
## Proposed Changes * added a small Bash wrapper that retries cluster deletion a couple of times, if it fails - this step has been flaky recently
2 parents 7af6269 + bee1d68 commit cd1e5f9

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed

cmd/generate-release/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,9 @@ func deleteCluster(deployerImage string) []*cloudbuild.BuildStep {
206206
{
207207
Id: "delete GKE cluster",
208208
Name: deployerImage,
209-
Entrypoint: "gcloud",
209+
Entrypoint: "/builder/delete-cluster.bash",
210210
Args: []string{
211-
"deployment-manager", "--quiet", "deployments", "delete", "${_CLOUDSDK_CONTAINER_CLUSTER}",
211+
"${_CLOUDSDK_CONTAINER_CLUSTER}",
212212
},
213213
},
214214
}

cmd/generate-release/main_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,9 @@ func TestDeleteCluster(t *testing.T) {
243243
testutil.AssertEqual(t, "delete GKE cluster", &cloudbuild.BuildStep{
244244
Id: "delete GKE cluster",
245245
Name: "deployer-image",
246-
Entrypoint: "gcloud",
246+
Entrypoint: "/builder/delete-cluster.bash",
247247
Args: []string{
248-
"deployment-manager", "--quiet", "deployments", "delete", "${_CLOUDSDK_CONTAINER_CLUSTER}",
248+
"${_CLOUDSDK_CONTAINER_CLUSTER}",
249249
},
250250
}, b.Steps[1])
251251
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bash
2+
3+
# This has been added to work around spurious problems with deleting GKE cluster
4+
# at the end of integration tests (usualy due to "operation in progress")
5+
6+
set -eux
7+
8+
if [ -z ${1:+x} ]; then
9+
echo "usage: $0 [CLUSTER_DEPLOYMENT]"
10+
exit 1
11+
fi
12+
13+
deployment_name=$1
14+
15+
# retry will run the command, if it fails, it will sleep and then try again:
16+
# args:
17+
# 1: command: The command to run. (required)
18+
# 2: retry_count: The number of times to attempt the command. (defaults to 3)
19+
# 3: sleep_seconds: The number of seconds to sleep after a failure. (defaults to 1)
20+
function retry() {
21+
command=${1:-x}
22+
retry_count=${2:-3}
23+
sleep_seconds=${3:-1}
24+
25+
if [ "${command}" = "x" ]; then
26+
echo "command missing"
27+
exit 1
28+
fi
29+
30+
n=0
31+
until [ "$n" -ge ${retry_count} ]
32+
do
33+
${command} && break
34+
echo "failed..."
35+
n=$((n+1))
36+
sleep ${sleep_seconds}
37+
done
38+
39+
if [ ${n} = ${retry_count} ];then
40+
echo "\"${command}\" failed too many times: (${retry_count})"
41+
exit 1
42+
fi
43+
}
44+
45+
retry "gcloud deployment-manager --quiet \
46+
deployments delete ${deployment_name}" 15 60

0 commit comments

Comments
 (0)