Merge pull request #10979 from sharifelgamal/cloud-shell-gcp
Fix gcp-auth tests for cloud shellpull/10993/head
commit
9c250ca486
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue