From 0ecdc072796cf8535046d81d50be7f71070695f5 Mon Sep 17 00:00:00 2001 From: Sharif Elgamal Date: Fri, 2 Apr 2021 11:15:53 -0700 Subject: [PATCH 1/3] Fix gcp-auth tests for cloud shell --- pkg/minikube/detect/detect.go | 6 ++++++ test/integration/addons_test.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/minikube/detect/detect.go b/pkg/minikube/detect/detect.go index 1bcacb86b7..9e26bf628f 100644 --- a/pkg/minikube/detect/detect.go +++ b/pkg/minikube/detect/detect.go @@ -37,3 +37,9 @@ func IsOnGCE() bool { return resp.Header.Get("Metadata-Flavor") == "Google" } + +// IsCloudShell determines whether minikube is running inside CloudShell +func IsCloudShell() bool { + _, e := os.LookupEnv("CLOUDSHELL_ENVIRONMENT") + return e +} diff --git a/test/integration/addons_test.go b/test/integration/addons_test.go index 556ca9e6ef..6cd7e3b223 100644 --- a/test/integration/addons_test.go +++ b/test/integration/addons_test.go @@ -87,7 +87,7 @@ func TestAddons(t *testing.T) { } else { if !strings.Contains(rr.Output(), "It seems that you are running in GCE") { t.Errorf("Unexpected error message: %v", rr.Output()) - } else { + } else if !detect.IsCloudShell() { // ok, use force here since we are in GCE // do not use --force unless absolutely necessary args = append(args, "--force") From 4a280f609913d75286c0e5f84c220eb3e37c8f57 Mon Sep 17 00:00:00 2001 From: Sharif Elgamal Date: Fri, 2 Apr 2021 13:02:18 -0700 Subject: [PATCH 2/3] adding dummy creds back for cloud shell --- test/integration/addons_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/addons_test.go b/test/integration/addons_test.go index 6cd7e3b223..ca51263655 100644 --- a/test/integration/addons_test.go +++ b/test/integration/addons_test.go @@ -47,7 +47,7 @@ func TestAddons(t *testing.T) { defer Cleanup(t, profile, cancel) // We don't need a dummy file is we're on GCE - if !detect.IsOnGCE() { + if !detect.IsOnGCE() || detect.IsCloudShell() { // Set an env var to point to our dummy credentials file err := os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", filepath.Join(*testdataDir, "gcp-creds.json")) defer os.Unsetenv("GOOGLE_APPLICATION_CREDENTIALS") From c9c9c68af32debd113c0de1e0359c1155a5b230e Mon Sep 17 00:00:00 2001 From: Sharif Elgamal Date: Mon, 5 Apr 2021 10:12:13 -0700 Subject: [PATCH 3/3] find the right combination of if statements --- test/integration/addons_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/integration/addons_test.go b/test/integration/addons_test.go index ca51263655..2e49b96a85 100644 --- a/test/integration/addons_test.go +++ b/test/integration/addons_test.go @@ -87,7 +87,7 @@ func TestAddons(t *testing.T) { } else { if !strings.Contains(rr.Output(), "It seems that you are running in GCE") { t.Errorf("Unexpected error message: %v", rr.Output()) - } else if !detect.IsCloudShell() { + } else { // ok, use force here since we are in GCE // do not use --force unless absolutely necessary args = append(args, "--force") @@ -589,7 +589,7 @@ func validateGCPAuthAddon(ctx context.Context, t *testing.T, profile string) { t.Errorf("'printenv GOOGLE_APPLICATION_CREDENTIALS' returned %s, expected %s", got, expected) } - if !detect.IsOnGCE() { + if !detect.IsOnGCE() || detect.IsCloudShell() { // Make sure the file contents are correct rr, err = Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "exec", names[0], "--", "/bin/sh", "-c", "cat /google-app-creds.json")) if err != nil { @@ -622,7 +622,7 @@ func validateGCPAuthAddon(ctx context.Context, t *testing.T, profile string) { got = strings.TrimSpace(rr.Stdout.String()) expected = "this_is_fake" - if detect.IsOnGCE() { + if detect.IsOnGCE() && !detect.IsCloudShell() { expected = "k8s-minikube" } if got != expected { @@ -630,7 +630,7 @@ func validateGCPAuthAddon(ctx context.Context, t *testing.T, profile string) { } // If we're on GCE, we have proper credentials and can test the registry secrets with an artifact registry image - if detect.IsOnGCE() { + if detect.IsOnGCE() && !detect.IsCloudShell() { _, err = Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "apply", "-f", filepath.Join(*testdataDir, "private-image.yaml"))) if err != nil { t.Fatalf("print env project: %v", err)