Skip to content

Commit 7c87cfc

Browse files
committed
Handle non existent cluster down gracefully
1 parent 848a92d commit 7c87cfc

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

test/k8s-integration/cluster.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@ func clusterDownGKE(gceZone, gceRegion string) error {
4949
return err
5050
}
5151

52-
cmd := exec.Command("gcloud", "container", "clusters", "delete", *gkeTestClusterName,
53-
locationArg, locationVal, "--quiet")
54-
err = runCommand("Bringing Down E2E Cluster on GKE", cmd)
55-
if err != nil {
52+
klog.Infof("Bringing down GKE cluster %v, location arg %v, location val %v", *gkeTestClusterName, locationArg, locationVal)
53+
out, err := exec.Command("gcloud", "container", "clusters", "delete", *gkeTestClusterName,
54+
locationArg, locationVal, "--quiet").CombinedOutput()
55+
klog.Infof("cluster delete output:\n%v", string(out))
56+
if err != nil && !isNotFoundError(string(out)) {
5657
return fmt.Errorf("failed to bring down kubernetes e2e cluster on gke: %v", err)
5758
}
59+
5860
return nil
5961
}
6062

@@ -152,6 +154,7 @@ func clusterUpGKE(gceZone, gceRegion string, numNodes int, imageType string, use
152154
return fmt.Errorf("failed to check for previous test cluster: %v %s", err, out)
153155
}
154156
if len(out) > 0 {
157+
klog.Infof("cluster list output: %v", string(out))
155158
klog.Infof("Detected previous cluster %s. Deleting so a new one can be created...", *gkeTestClusterName)
156159
err = clusterDownGKE(gceZone, gceRegion)
157160
if err != nil {
@@ -406,3 +409,7 @@ func isGKEDeploymentInstalledByDefault(clusterVersion string) bool {
406409
cv.lessThan(mustParseVersion("1.19.0")) ||
407410
cv.atLeast(mustParseVersion("1.19.3-gke.2100"))
408411
}
412+
413+
func isNotFoundError(errstr string) bool {
414+
return strings.Contains(strings.ToLower(errstr), "code=404")
415+
}

0 commit comments

Comments
 (0)