Skip to content

Commit b623c21

Browse files
authored
testing: Add defer to disable addon to start of each addon test (#19715)
* testing: Add defer to disable addon to start of each addon test * only start storage-provisioner-rancher for non-none drivers
1 parent 5242aba commit b623c21

File tree

1 file changed

+32
-68
lines changed

1 file changed

+32
-68
lines changed

test/integration/addons_test.go

+32-68
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ func TestAddons(t *testing.T) {
100100
// so we override that here to let minikube auto-detect appropriate cgroup driver
101101
os.Setenv(constants.MinikubeForceSystemdEnv, "")
102102

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")
106106
}
107107
rr, err := Run(t, exec.CommandContext(ctx, Target(), args...))
108108
if err != nil {
@@ -189,10 +189,12 @@ func TestAddons(t *testing.T) {
189189

190190
// validateIngressAddon tests the ingress addon by deploying a default nginx pod
191191
func validateIngressAddon(ctx context.Context, t *testing.T, profile string) {
192-
defer PostMortemLogs(t, profile)
193192
if NoneDriver() {
194193
t.Skipf("skipping: ingress not supported")
195194
}
195+
defer disableAddon(t, "ingress", profile)
196+
defer disableAddon(t, "ingress-dns", profile)
197+
defer PostMortemLogs(t, profile)
196198

197199
client, err := kapi.Client(profile)
198200
if err != nil {
@@ -300,20 +302,11 @@ func validateIngressAddon(ctx context.Context, t *testing.T, profile string) {
300302
if !strings.Contains(rr.Stdout.String(), ip) {
301303
t.Errorf("unexpected output from nslookup. stdout: %v\nstderr: %v", rr.Stdout.String(), rr.Stderr.String())
302304
}
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-
}
313305
}
314306

315307
// validateRegistryAddon tests the registry addon
316308
func validateRegistryAddon(ctx context.Context, t *testing.T, profile string) {
309+
defer disableAddon(t, "registry", profile)
317310
defer PostMortemLogs(t, profile)
318311

319312
client, err := kapi.Client(profile)
@@ -382,15 +375,11 @@ func validateRegistryAddon(ctx context.Context, t *testing.T, profile string) {
382375
if err := retry.Expo(checkExternalAccess, 500*time.Millisecond, Seconds(150)); err != nil {
383376
t.Errorf("failed to check external access to %s: %v", u.String(), err.Error())
384377
}
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-
}
390378
}
391379

392380
// validateMetricsServerAddon tests the metrics server addon by making sure "kubectl top pods" returns a sensible result
393381
func validateMetricsServerAddon(ctx context.Context, t *testing.T, profile string) {
382+
defer disableAddon(t, "metrics-server", profile)
394383
defer PostMortemLogs(t, profile)
395384

396385
client, err := kapi.Client(profile)
@@ -426,16 +415,12 @@ func validateMetricsServerAddon(ctx context.Context, t *testing.T, profile strin
426415
if err := retry.Expo(checkMetricsServer, time.Second*3, Minutes(6)); err != nil {
427416
t.Errorf("failed checking metric server: %v", err.Error())
428417
}
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-
}
434418
}
435419

436420
// validateOlmAddon tests the OLM addon
437421
func validateOlmAddon(ctx context.Context, t *testing.T, profile string) {
438422
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)
439424
defer PostMortemLogs(t, profile)
440425
start := time.Now()
441426

@@ -483,14 +468,12 @@ func validateOlmAddon(ctx context.Context, t *testing.T, profile string) {
483468
if err := retry.Expo(checkOperatorInstalled, time.Second*3, Minutes(10)); err != nil {
484469
t.Errorf("failed checking operator installed: %v", err.Error())
485470
}
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-
}
490471
}
491472

492473
// validateCSIDriverAndSnapshots tests the csi hostpath driver by creating a persistent volume, snapshotting it and restoring it.
493474
func validateCSIDriverAndSnapshots(ctx context.Context, t *testing.T, profile string) {
475+
defer disableAddon(t, "csi-hostpath-driver", profile)
476+
defer disableAddon(t, "volumesnapshots", profile)
494477
defer PostMortemLogs(t, profile)
495478

496479
client, err := kapi.Client(profile)
@@ -579,14 +562,6 @@ func validateCSIDriverAndSnapshots(ctx context.Context, t *testing.T, profile st
579562
if err != nil {
580563
t.Logf("cleanup with %s failed: %v", rr.Command(), err)
581564
}
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-
}
590565
}
591566

592567
// 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
619594

620595
// validateGCPAuthAddon tests the GCP Auth addon with either phony or real credentials and makes sure the files are mounted into pods correctly
621596
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+
}()
622606
defer PostMortemLogs(t, profile)
623607

624608
t.Run("Namespaces", func(t *testing.T) {
@@ -707,18 +691,6 @@ func validateGCPAuthAddon(ctx context.Context, t *testing.T, profile string) {
707691
t.Errorf("'printenv GOOGLE_CLOUD_PROJECT' returned %s, expected %s", got, expected)
708692
}
709693

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-
722694
// If we're on GCE, we have proper credentials and can test the registry secrets with an artifact registry image
723695
if detect.IsOnGCE() && !detect.IsCloudShell() && !VMDriver() {
724696
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) {
763735
}
764736

765737
func validateHeadlampAddon(ctx context.Context, t *testing.T, profile string) {
738+
defer disableAddon(t, "headlamp", profile)
766739
defer PostMortemLogs(t, profile)
767740

768741
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) {
773746
if _, err := PodWait(ctx, t, profile, "headlamp", "app.kubernetes.io/name=headlamp", Minutes(8)); err != nil {
774747
t.Fatalf("failed waiting for headlamp pod: %v", err)
775748
}
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-
}
780749
}
781750

782751
// validateInspektorGadgetAddon tests the inspektor-gadget addon by ensuring the pod has come up and addon disables
783752
func validateInspektorGadgetAddon(ctx context.Context, t *testing.T, profile string) {
753+
defer disableAddon(t, "inspektor-gadget", profile)
784754
defer PostMortemLogs(t, profile)
785755

786756
if _, err := PodWait(ctx, t, profile, "gadget", "k8s-app=gadget", Minutes(8)); err != nil {
787757
t.Fatalf("failed waiting for inspektor-gadget pod: %v", err)
788758
}
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-
}
792759
}
793760

794761
// validateCloudSpannerAddon tests the cloud-spanner addon by ensuring the deployment and pod come up and addon disables
795762
func validateCloudSpannerAddon(ctx context.Context, t *testing.T, profile string) {
763+
defer disableAddon(t, "cloud-spanner", profile)
796764
defer PostMortemLogs(t, profile)
797765

798766
client, err := kapi.Client(profile)
@@ -805,13 +773,11 @@ func validateCloudSpannerAddon(ctx context.Context, t *testing.T, profile string
805773
if _, err := PodWait(ctx, t, profile, "default", "app=cloud-spanner-emulator", Minutes(6)); err != nil {
806774
t.Errorf("failed waiting for app=cloud-spanner-emulator pod: %v", err)
807775
}
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-
}
811776
}
812777

813778
// validateVolcanoAddon tests the Volcano addon, makes sure the Volcano is installed into cluster.
814779
func validateVolcanoAddon(ctx context.Context, t *testing.T, profile string) {
780+
defer disableAddon(t, "volcano", profile)
815781
defer PostMortemLogs(t, profile)
816782
if ContainerRuntime() == "crio" {
817783
t.Skipf("skipping: crio not supported")
@@ -902,19 +868,14 @@ func validateVolcanoAddon(ctx context.Context, t *testing.T, profile string) {
902868
if _, err := PodWait(ctx, t, profile, "my-volcano", "volcano.sh/job-name=test-job", Minutes(3)); err != nil {
903869
t.Fatalf("failed waiting for test-local-path pod: %v", err)
904870
}
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-
}
910871
}
911872

912873
// validateLocalPathAddon tests the functionality of the storage-provisioner-rancher addon
913874
func validateLocalPathAddon(ctx context.Context, t *testing.T, profile string) {
914-
915875
if NoneDriver() {
916876
t.Skipf("skip local-path test on none driver")
917877
}
878+
defer disableAddon(t, "storage-provisioner-rancher", profile)
918879

919880
// Create a test PVC
920881
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) {
964925
if err != nil {
965926
t.Logf("cleanup with %s failed: %v", rr.Command(), err)
966927
}
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-
}
971928
}
972929

973930
// validateEnablingAddonOnNonExistingCluster tests enabling an addon on a non-existing cluster
@@ -1015,3 +972,10 @@ func validateYakdAddon(ctx context.Context, t *testing.T, profile string) {
1015972
t.Errorf("failed to disable yakd addon: args %q: %v", rr.Command(), err)
1016973
}
1017974
}
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

Comments
 (0)