@@ -47,62 +47,36 @@ func TestAddons(t *testing.T) {
47
47
defer Cleanup (t , profile , cancel )
48
48
49
49
setupSucceeded := t .Run ("Setup" , func (t * testing.T ) {
50
- // We don't need a dummy file is we're on GCE
51
- if ! detect .IsOnGCE () || detect .IsCloudShell () {
52
- // Set an env var to point to our dummy credentials file
53
- err := os .Setenv ("GOOGLE_APPLICATION_CREDENTIALS" , filepath .Join (* testdataDir , "gcp-creds.json" ))
54
- t .Cleanup (func () {
55
- os .Unsetenv ("GOOGLE_APPLICATION_CREDENTIALS" )
56
- })
57
- if err != nil {
58
- t .Fatalf ("Failed setting GOOGLE_APPLICATION_CREDENTIALS env var: %v" , err )
59
- }
50
+ // Set an env var to point to our dummy credentials file
51
+ // don't use t.Setenv because we sometimes manually unset the env var later manually
52
+ err := os .Setenv ("GOOGLE_APPLICATION_CREDENTIALS" , filepath .Join (* testdataDir , "gcp-creds.json" ))
53
+ t .Cleanup (func () {
54
+ os .Unsetenv ("GOOGLE_APPLICATION_CREDENTIALS" )
55
+ })
56
+ if err != nil {
57
+ t .Fatalf ("Failed setting GOOGLE_APPLICATION_CREDENTIALS env var: %v" , err )
58
+ }
60
59
61
- err = os .Setenv ("GOOGLE_CLOUD_PROJECT" , "this_is_fake" )
62
- t .Cleanup (func () {
63
- os .Unsetenv ("GOOGLE_CLOUD_PROJECT" )
64
- })
65
- if err != nil {
66
- t .Fatalf ("Failed setting GOOGLE_CLOUD_PROJECT env var: %v" , err )
67
- }
60
+ err = os .Setenv ("GOOGLE_CLOUD_PROJECT" , "this_is_fake" )
61
+ t .Cleanup (func () {
62
+ os .Unsetenv ("GOOGLE_CLOUD_PROJECT" )
63
+ })
64
+ if err != nil {
65
+ t .Fatalf ("Failed setting GOOGLE_CLOUD_PROJECT env var: %v" , err )
68
66
}
69
67
70
- args := append ([]string {"start" , "-p" , profile , "--wait=true" , "--memory=4000" , "--alsologtostderr" , "--addons=registry" , "--addons=metrics-server" , "--addons=olm" , "--addons=volumesnapshots" , "--addons=csi-hostpath-driver" }, StartArgs ()... )
68
+ args := append ([]string {"start" , "-p" , profile , "--wait=true" , "--memory=4000" , "--alsologtostderr" , "--addons=registry" , "--addons=metrics-server" , "--addons=olm" , "--addons=volumesnapshots" , "--addons=csi-hostpath-driver" , "--addons=gcp-auth" }, StartArgs ()... )
71
69
if ! NoneDriver () { // none driver does not support ingress
72
70
args = append (args , "--addons=ingress" , "--addons=ingress-dns" )
73
71
}
74
72
if ! arm64Platform () {
75
73
args = append (args , "--addons=helm-tiller" )
76
74
}
77
- if ! detect .IsOnGCE () {
78
- args = append (args , "--addons=gcp-auth" )
79
- }
80
75
rr , err := Run (t , exec .CommandContext (ctx , Target (), args ... ))
81
76
if err != nil {
82
77
t .Fatalf ("%s failed: %v" , rr .Command (), err )
83
78
}
84
79
85
- // If we're running the integration tests on GCE, which is frequently the case, first check to make sure we exit out properly,
86
- // then use force to actually test using creds.
87
- if detect .IsOnGCE () {
88
- args = []string {"-p" , profile , "addons" , "enable" , "gcp-auth" }
89
- rr , err := Run (t , exec .CommandContext (ctx , Target (), args ... ))
90
- if err != nil {
91
- t .Errorf ("%s failed: %v" , rr .Command (), err )
92
- } else {
93
- if ! detect .IsCloudShell () && ! strings .Contains (rr .Output (), "It seems that you are running in GCE" ) {
94
- t .Errorf ("Unexpected error message: %v" , rr .Output ())
95
- } else {
96
- // ok, use force here since we are in GCE
97
- // do not use --force unless absolutely necessary
98
- args = append (args , "--force" )
99
- rr , err := Run (t , exec .CommandContext (ctx , Target (), args ... ))
100
- if err != nil {
101
- t .Errorf ("%s failed: %v" , rr .Command (), err )
102
- }
103
- }
104
- }
105
- }
106
80
})
107
81
108
82
if ! setupSucceeded {
@@ -669,15 +643,34 @@ func validateGCPAuthAddon(ctx context.Context, t *testing.T, profile string) {
669
643
670
644
got = strings .TrimSpace (rr .Stdout .String ())
671
645
expected = "this_is_fake"
672
- if detect .IsOnGCE () && ! detect .IsCloudShell () {
673
- expected = "k8s-minikube"
674
- }
646
+
675
647
if got != expected {
676
648
t .Errorf ("'printenv GOOGLE_CLOUD_PROJECT' returned %s, expected %s" , got , expected )
677
649
}
678
650
651
+ disableGCPAuth := func () error {
652
+ _ , err = Run (t , exec .CommandContext (ctx , Target (), "-p" , profile , "addons" , "disable" , "gcp-auth" , "--alsologtostderr" , "-v=1" ))
653
+ if err != nil {
654
+ return err
655
+ }
656
+ return nil
657
+ }
658
+
659
+ if err := retry .Expo (disableGCPAuth , Minutes (2 ), Minutes (10 ), 5 ); err != nil {
660
+ t .Errorf ("failed to disable GCP auth addon: %v" , err )
661
+ }
662
+
679
663
// If we're on GCE, we have proper credentials and can test the registry secrets with an artifact registry image
680
664
if detect .IsOnGCE () && ! detect .IsCloudShell () {
665
+ os .Unsetenv ("GOOGLE_APPLICATION_CREDENTIALS" )
666
+ os .Unsetenv ("GOOGLE_CLOUD_PROJECT" )
667
+ args := []string {"-p" , profile , "addons" , "enable" , "gcp-auth" }
668
+ rr , err := Run (t , exec .CommandContext (ctx , Target (), args ... ))
669
+ if err != nil {
670
+ t .Errorf ("%s failed: %v" , rr .Command (), err )
671
+ } else if ! strings .Contains (rr .Output (), "It seems that you are running in GCE" ) {
672
+ t .Errorf ("Unexpected error message: %v" , rr .Output ())
673
+ }
681
674
_ , err = Run (t , exec .CommandContext (ctx , "kubectl" , "--context" , profile , "apply" , "-f" , filepath .Join (* testdataDir , "private-image.yaml" )))
682
675
if err != nil {
683
676
t .Fatalf ("print env project: %v" , err )
@@ -696,23 +689,9 @@ func validateGCPAuthAddon(ctx context.Context, t *testing.T, profile string) {
696
689
t .Fatalf ("print env project: %v" , err )
697
690
}
698
691
699
- // Make sure the pod is up and running, which means we successfully pulled the private image down
700
- // 8 minutes, because 4 is not enough for images to pull in all cases.
701
692
_ , err = PodWait (ctx , t , profile , "default" , "integration-test=private-image-eu" , Minutes (8 ))
702
693
if err != nil {
703
694
t .Fatalf ("wait for private image: %v" , err )
704
695
}
705
696
}
706
-
707
- disableGCPAuth := func () error {
708
- _ , err = Run (t , exec .CommandContext (ctx , Target (), "-p" , profile , "addons" , "disable" , "gcp-auth" , "--alsologtostderr" , "-v=1" ))
709
- if err != nil {
710
- return err
711
- }
712
- return nil
713
- }
714
-
715
- if err := retry .Expo (disableGCPAuth , Minutes (2 ), Minutes (10 ), 5 ); err != nil {
716
- t .Errorf ("failed to disable GCP auth addon: %v" , err )
717
- }
718
697
}
0 commit comments