@@ -100,9 +100,9 @@ func TestAddons(t *testing.T) {
100
100
// so we override that here to let minikube auto-detect appropriate cgroup driver
101
101
os .Setenv (constants .MinikubeForceSystemdEnv , "" )
102
102
103
- args := append ([]string {"start" , "-p" , profile , "--wait=true" , "--memory=4000" , "--alsologtostderr" , "--addons=registry" , "--addons=metrics-server" , "--addons=volumesnapshots" , "--addons=csi-hostpath-driver" , "--addons=gcp-auth" , "--addons=cloud-spanner" , "--addons=inspektor-gadget" , "--addons=storage-provisioner-rancher" , "--addons= nvidia-device-plugin" , "--addons=yakd" , "--addons=volcano" }, StartArgs ()... )
104
- if ! NoneDriver () { // none driver does not support ingress
105
- args = append (args , "--addons=ingress" , "--addons=ingress-dns" )
103
+ args := append ([]string {"start" , "-p" , profile , "--wait=true" , "--memory=4000" , "--alsologtostderr" , "--addons=registry" , "--addons=metrics-server" , "--addons=volumesnapshots" , "--addons=csi-hostpath-driver" , "--addons=gcp-auth" , "--addons=cloud-spanner" , "--addons=inspektor-gadget" , "--addons=nvidia-device-plugin" , "--addons=yakd" , "--addons=volcano" }, StartArgs ()... )
104
+ if ! NoneDriver () {
105
+ args = append (args , "--addons=ingress" , "--addons=ingress-dns" , "--addons=storage-provisioner-rancher" )
106
106
}
107
107
rr , err := Run (t , exec .CommandContext (ctx , Target (), args ... ))
108
108
if err != nil {
@@ -189,10 +189,12 @@ func TestAddons(t *testing.T) {
189
189
190
190
// validateIngressAddon tests the ingress addon by deploying a default nginx pod
191
191
func validateIngressAddon (ctx context.Context , t * testing.T , profile string ) {
192
- defer PostMortemLogs (t , profile )
193
192
if NoneDriver () {
194
193
t .Skipf ("skipping: ingress not supported" )
195
194
}
195
+ defer disableAddon (t , "ingress" , profile )
196
+ defer disableAddon (t , "ingress-dns" , profile )
197
+ defer PostMortemLogs (t , profile )
196
198
197
199
client , err := kapi .Client (profile )
198
200
if err != nil {
@@ -300,20 +302,11 @@ func validateIngressAddon(ctx context.Context, t *testing.T, profile string) {
300
302
if ! strings .Contains (rr .Stdout .String (), ip ) {
301
303
t .Errorf ("unexpected output from nslookup. stdout: %v\n stderr: %v" , rr .Stdout .String (), rr .Stderr .String ())
302
304
}
303
-
304
- rr , err = Run (t , exec .CommandContext (ctx , Target (), "-p" , profile , "addons" , "disable" , "ingress-dns" , "--alsologtostderr" , "-v=1" ))
305
- if err != nil {
306
- t .Errorf ("failed to disable ingress-dns addon. args %q : %v" , rr .Command (), err )
307
- }
308
-
309
- rr , err = Run (t , exec .CommandContext (ctx , Target (), "-p" , profile , "addons" , "disable" , "ingress" , "--alsologtostderr" , "-v=1" ))
310
- if err != nil {
311
- t .Errorf ("failed to disable ingress addon. args %q : %v" , rr .Command (), err )
312
- }
313
305
}
314
306
315
307
// validateRegistryAddon tests the registry addon
316
308
func validateRegistryAddon (ctx context.Context , t * testing.T , profile string ) {
309
+ defer disableAddon (t , "registry" , profile )
317
310
defer PostMortemLogs (t , profile )
318
311
319
312
client , err := kapi .Client (profile )
@@ -382,15 +375,11 @@ func validateRegistryAddon(ctx context.Context, t *testing.T, profile string) {
382
375
if err := retry .Expo (checkExternalAccess , 500 * time .Millisecond , Seconds (150 )); err != nil {
383
376
t .Errorf ("failed to check external access to %s: %v" , u .String (), err .Error ())
384
377
}
385
-
386
- rr , err = Run (t , exec .CommandContext (ctx , Target (), "-p" , profile , "addons" , "disable" , "registry" , "--alsologtostderr" , "-v=1" ))
387
- if err != nil {
388
- t .Errorf ("failed to disable registry addon. args %q: %v" , rr .Command (), err )
389
- }
390
378
}
391
379
392
380
// validateMetricsServerAddon tests the metrics server addon by making sure "kubectl top pods" returns a sensible result
393
381
func validateMetricsServerAddon (ctx context.Context , t * testing.T , profile string ) {
382
+ defer disableAddon (t , "metrics-server" , profile )
394
383
defer PostMortemLogs (t , profile )
395
384
396
385
client , err := kapi .Client (profile )
@@ -426,16 +415,12 @@ func validateMetricsServerAddon(ctx context.Context, t *testing.T, profile strin
426
415
if err := retry .Expo (checkMetricsServer , time .Second * 3 , Minutes (6 )); err != nil {
427
416
t .Errorf ("failed checking metric server: %v" , err .Error ())
428
417
}
429
-
430
- rr , err := Run (t , exec .CommandContext (ctx , Target (), "-p" , profile , "addons" , "disable" , "metrics-server" , "--alsologtostderr" , "-v=1" ))
431
- if err != nil {
432
- t .Errorf ("failed to disable metrics-server addon: args %q: %v" , rr .Command (), err )
433
- }
434
418
}
435
419
436
420
// validateOlmAddon tests the OLM addon
437
421
func validateOlmAddon (ctx context.Context , t * testing.T , profile string ) {
438
422
t .Skip ("Skipping OLM addon test until https://github.com/operator-framework/operator-lifecycle-manager/issues/2534 is resolved" )
423
+ defer disableAddon (t , "olm" , profile )
439
424
defer PostMortemLogs (t , profile )
440
425
start := time .Now ()
441
426
@@ -483,14 +468,12 @@ func validateOlmAddon(ctx context.Context, t *testing.T, profile string) {
483
468
if err := retry .Expo (checkOperatorInstalled , time .Second * 3 , Minutes (10 )); err != nil {
484
469
t .Errorf ("failed checking operator installed: %v" , err .Error ())
485
470
}
486
-
487
- if rr , err := Run (t , exec .CommandContext (ctx , Target (), "-p" , profile , "addons" , "disable" , "olm" , "--alsologtostderr" , "-v=1" )); err != nil {
488
- t .Errorf ("failed to disable olm addon: args %q: %v" , rr .Command (), err )
489
- }
490
471
}
491
472
492
473
// validateCSIDriverAndSnapshots tests the csi hostpath driver by creating a persistent volume, snapshotting it and restoring it.
493
474
func validateCSIDriverAndSnapshots (ctx context.Context , t * testing.T , profile string ) {
475
+ defer disableAddon (t , "csi-hostpath-driver" , profile )
476
+ defer disableAddon (t , "volumesnapshots" , profile )
494
477
defer PostMortemLogs (t , profile )
495
478
496
479
client , err := kapi .Client (profile )
@@ -579,14 +562,6 @@ func validateCSIDriverAndSnapshots(ctx context.Context, t *testing.T, profile st
579
562
if err != nil {
580
563
t .Logf ("cleanup with %s failed: %v" , rr .Command (), err )
581
564
}
582
- rr , err = Run (t , exec .CommandContext (ctx , Target (), "-p" , profile , "addons" , "disable" , "csi-hostpath-driver" , "--alsologtostderr" , "-v=1" ))
583
- if err != nil {
584
- t .Errorf ("failed to disable csi-hostpath-driver addon: args %q: %v" , rr .Command (), err )
585
- }
586
- rr , err = Run (t , exec .CommandContext (ctx , Target (), "-p" , profile , "addons" , "disable" , "volumesnapshots" , "--alsologtostderr" , "-v=1" ))
587
- if err != nil {
588
- t .Errorf ("failed to disable volumesnapshots addon: args %q: %v" , rr .Command (), err )
589
- }
590
565
}
591
566
592
567
// validateGCPAuthNamespaces validates that newly created namespaces contain the gcp-auth secret.
@@ -619,6 +594,15 @@ func validateGCPAuthNamespaces(ctx context.Context, t *testing.T, profile string
619
594
620
595
// validateGCPAuthAddon tests the GCP Auth addon with either phony or real credentials and makes sure the files are mounted into pods correctly
621
596
func validateGCPAuthAddon (ctx context.Context , t * testing.T , profile string ) {
597
+ defer func () {
598
+ disableGCPAuth := func () error {
599
+ disableAddon (t , "gcp-auth" , profile )
600
+ return nil
601
+ }
602
+ if err := retry .Expo (disableGCPAuth , Minutes (2 ), Minutes (10 ), 5 ); err != nil {
603
+ t .Errorf ("failed to disable GCP auth addon: %v" , err )
604
+ }
605
+ }()
622
606
defer PostMortemLogs (t , profile )
623
607
624
608
t .Run ("Namespaces" , func (t * testing.T ) {
@@ -707,18 +691,6 @@ func validateGCPAuthAddon(ctx context.Context, t *testing.T, profile string) {
707
691
t .Errorf ("'printenv GOOGLE_CLOUD_PROJECT' returned %s, expected %s" , got , expected )
708
692
}
709
693
710
- disableGCPAuth := func () error {
711
- _ , err = Run (t , exec .CommandContext (ctx , Target (), "-p" , profile , "addons" , "disable" , "gcp-auth" , "--alsologtostderr" , "-v=1" ))
712
- if err != nil {
713
- return err
714
- }
715
- return nil
716
- }
717
-
718
- if err := retry .Expo (disableGCPAuth , Minutes (2 ), Minutes (10 ), 5 ); err != nil {
719
- t .Errorf ("failed to disable GCP auth addon: %v" , err )
720
- }
721
-
722
694
// If we're on GCE, we have proper credentials and can test the registry secrets with an artifact registry image
723
695
if detect .IsOnGCE () && ! detect .IsCloudShell () && ! VMDriver () {
724
696
t .Skip ("skipping GCPAuth addon test until 'Permission \" artifactregistry.repositories.downloadArtifacts\" denied on resource \" projects/k8s-minikube/locations/us/repositories/test-artifacts\" (or it may not exist)' issue is resolved" )
@@ -763,6 +735,7 @@ func validateGCPAuthAddon(ctx context.Context, t *testing.T, profile string) {
763
735
}
764
736
765
737
func validateHeadlampAddon (ctx context.Context , t * testing.T , profile string ) {
738
+ defer disableAddon (t , "headlamp" , profile )
766
739
defer PostMortemLogs (t , profile )
767
740
768
741
rr , err := Run (t , exec .CommandContext (ctx , Target (), "addons" , "enable" , "headlamp" , "-p" , profile , "--alsologtostderr" , "-v=1" ))
@@ -773,26 +746,21 @@ func validateHeadlampAddon(ctx context.Context, t *testing.T, profile string) {
773
746
if _ , err := PodWait (ctx , t , profile , "headlamp" , "app.kubernetes.io/name=headlamp" , Minutes (8 )); err != nil {
774
747
t .Fatalf ("failed waiting for headlamp pod: %v" , err )
775
748
}
776
-
777
- if rr , err := Run (t , exec .CommandContext (ctx , Target (), "-p" , profile , "addons" , "disable" , "headlamp" , "--alsologtostderr" , "-v=1" )); err != nil {
778
- t .Errorf ("failed to disable headlamp addon: args %q: %v" , rr .Command (), err )
779
- }
780
749
}
781
750
782
751
// validateInspektorGadgetAddon tests the inspektor-gadget addon by ensuring the pod has come up and addon disables
783
752
func validateInspektorGadgetAddon (ctx context.Context , t * testing.T , profile string ) {
753
+ defer disableAddon (t , "inspektor-gadget" , profile )
784
754
defer PostMortemLogs (t , profile )
785
755
786
756
if _ , err := PodWait (ctx , t , profile , "gadget" , "k8s-app=gadget" , Minutes (8 )); err != nil {
787
757
t .Fatalf ("failed waiting for inspektor-gadget pod: %v" , err )
788
758
}
789
- if rr , err := Run (t , exec .CommandContext (ctx , Target (), "addons" , "disable" , "inspektor-gadget" , "-p" , profile )); err != nil {
790
- t .Errorf ("failed to disable inspektor-gadget addon: args %q : %v" , rr .Command (), err )
791
- }
792
759
}
793
760
794
761
// validateCloudSpannerAddon tests the cloud-spanner addon by ensuring the deployment and pod come up and addon disables
795
762
func validateCloudSpannerAddon (ctx context.Context , t * testing.T , profile string ) {
763
+ defer disableAddon (t , "cloud-spanner" , profile )
796
764
defer PostMortemLogs (t , profile )
797
765
798
766
client , err := kapi .Client (profile )
@@ -805,13 +773,11 @@ func validateCloudSpannerAddon(ctx context.Context, t *testing.T, profile string
805
773
if _ , err := PodWait (ctx , t , profile , "default" , "app=cloud-spanner-emulator" , Minutes (6 )); err != nil {
806
774
t .Errorf ("failed waiting for app=cloud-spanner-emulator pod: %v" , err )
807
775
}
808
- if rr , err := Run (t , exec .CommandContext (ctx , Target (), "addons" , "disable" , "cloud-spanner" , "-p" , profile )); err != nil {
809
- t .Errorf ("failed to disable cloud-spanner addon: args %q : %v" , rr .Command (), err )
810
- }
811
776
}
812
777
813
778
// validateVolcanoAddon tests the Volcano addon, makes sure the Volcano is installed into cluster.
814
779
func validateVolcanoAddon (ctx context.Context , t * testing.T , profile string ) {
780
+ defer disableAddon (t , "volcano" , profile )
815
781
defer PostMortemLogs (t , profile )
816
782
if ContainerRuntime () == "crio" {
817
783
t .Skipf ("skipping: crio not supported" )
@@ -902,19 +868,14 @@ func validateVolcanoAddon(ctx context.Context, t *testing.T, profile string) {
902
868
if _ , err := PodWait (ctx , t , profile , "my-volcano" , "volcano.sh/job-name=test-job" , Minutes (3 )); err != nil {
903
869
t .Fatalf ("failed waiting for test-local-path pod: %v" , err )
904
870
}
905
-
906
- rr , err = Run (t , exec .CommandContext (ctx , Target (), "-p" , profile , "addons" , "disable" , "volcano" , "--alsologtostderr" , "-v=1" ))
907
- if err != nil {
908
- t .Errorf ("failed to disable volcano addon: args %q: %v" , rr .Command (), err )
909
- }
910
871
}
911
872
912
873
// validateLocalPathAddon tests the functionality of the storage-provisioner-rancher addon
913
874
func validateLocalPathAddon (ctx context.Context , t * testing.T , profile string ) {
914
-
915
875
if NoneDriver () {
916
876
t .Skipf ("skip local-path test on none driver" )
917
877
}
878
+ defer disableAddon (t , "storage-provisioner-rancher" , profile )
918
879
919
880
// Create a test PVC
920
881
rr , err := Run (t , exec .CommandContext (ctx , "kubectl" , "--context" , profile , "apply" , "-f" , filepath .Join (* testdataDir , "storage-provisioner-rancher" , "pvc.yaml" )))
@@ -964,10 +925,6 @@ func validateLocalPathAddon(ctx context.Context, t *testing.T, profile string) {
964
925
if err != nil {
965
926
t .Logf ("cleanup with %s failed: %v" , rr .Command (), err )
966
927
}
967
- rr , err = Run (t , exec .CommandContext (ctx , Target (), "-p" , profile , "addons" , "disable" , "storage-provisioner-rancher" , "--alsologtostderr" , "-v=1" ))
968
- if err != nil {
969
- t .Errorf ("failed to disable storage-provisioner-rancher addon: args %q: %v" , rr .Command (), err )
970
- }
971
928
}
972
929
973
930
// validateEnablingAddonOnNonExistingCluster tests enabling an addon on a non-existing cluster
@@ -1015,3 +972,10 @@ func validateYakdAddon(ctx context.Context, t *testing.T, profile string) {
1015
972
t .Errorf ("failed to disable yakd addon: args %q: %v" , rr .Command (), err )
1016
973
}
1017
974
}
975
+
976
+ func disableAddon (t * testing.T , addon , profile string ) {
977
+ rr , err := Run (t , exec .Command (Target (), "-p" , profile , "addons" , "disable" , addon , "--alsologtostderr" , "-v=1" ))
978
+ if err != nil {
979
+ t .Errorf ("failed to disable %s addon: args %q: %v" , addon , rr .Command (), err )
980
+ }
981
+ }
0 commit comments