diff --git a/test/integration/addons_test.go b/test/integration/addons_test.go index 40e3fee39e05..3421c37c0452 100644 --- a/test/integration/addons_test.go +++ b/test/integration/addons_test.go @@ -37,6 +37,7 @@ import ( "github.com/blang/semver/v4" retryablehttp "github.com/hashicorp/go-retryablehttp" + core "k8s.io/api/core/v1" "k8s.io/minikube/pkg/kapi" "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/detect" @@ -78,7 +79,7 @@ func TestAddons(t *testing.T) { // so we override that here to let minikube auto-detect appropriate cgroup driver os.Setenv(constants.MinikubeForceSystemdEnv, "") - 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"}, StartArgs()...) + 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"}, StartArgs()...) if !NoneDriver() { // none driver does not support ingress args = append(args, "--addons=ingress", "--addons=ingress-dns") } @@ -111,6 +112,7 @@ func TestAddons(t *testing.T) { {"CSI", validateCSIDriverAndSnapshots}, {"Headlamp", validateHeadlampAddon}, {"CloudSpanner", validateCloudSpannerAddon}, + {"LocalPath", validateLocalPathAddon}, } for _, tc := range tests { tc := tc @@ -837,3 +839,64 @@ func validateCloudSpannerAddon(ctx context.Context, t *testing.T, profile string t.Errorf("failed to disable cloud-spanner addon: args %q : %v", rr.Command(), err) } } + +// validateLocalPathAddon tests the functionality of the storage-provisioner-rancher addon +func validateLocalPathAddon(ctx context.Context, t *testing.T, profile string) { + + if NoneDriver() { + t.Skipf("skip local-path test on none driver") + } + + // Create a test PVC + rr, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "apply", "-f", filepath.Join(*testdataDir, "storage-provisioner-rancher", "pvc.yaml"))) + if err != nil { + t.Fatalf("kubectl apply pvc.yaml failed: args %q: %v", rr.Command(), err) + } + + // Deploy a simple pod with PVC + rr, err = Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "apply", "-f", filepath.Join(*testdataDir, "storage-provisioner-rancher", "pod.yaml"))) + if err != nil { + t.Fatalf("kubectl apply pod.yaml failed: args %q: %v", rr.Command(), err) + } + if err := PVCWait(ctx, t, profile, "default", "test-pvc", Minutes(5)); err != nil { + t.Fatalf("failed waiting for PVC test-pvc: %v", err) + } + if _, err := PodWait(ctx, t, profile, "default", "run=test-local-path", Minutes(3)); err != nil { + t.Fatalf("failed waiting for test-local-path pod: %v", err) + } + + // Get info about PVC + rr, err = Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "get", "pvc", "test-pvc", "-o=json")) + if err != nil { + t.Fatalf("kubectl get pvc with %s failed: %v", rr.Command(), err) + } + pvc := core.PersistentVolumeClaim{} + if err := json.NewDecoder(bytes.NewReader(rr.Stdout.Bytes())).Decode(&pvc); err != nil { + t.Fatalf("failed decoding json to pvc: %v", err) + } + + rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ssh", fmt.Sprintf("cat /opt/local-path-provisioner/%s_default_test-pvc/file1", pvc.Spec.VolumeName))) + if err != nil { + t.Fatalf("ssh error: %v", err) + } + + got := rr.Stdout.String() + want := "local-path-provisioner" + if !strings.Contains(got, want) { + t.Fatalf("%v stdout = %q, want %q", rr.Command(), got, want) + } + + // Cleanup + rr, err = Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "delete", "pod", "test-local-path")) + if err != nil { + t.Logf("cleanup with %s failed: %v", rr.Command(), err) + } + rr, err = Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "delete", "pvc", "test-pvc")) + if err != nil { + t.Logf("cleanup with %s failed: %v", rr.Command(), err) + } + rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "addons", "disable", "storage-provisioner-rancher", "--alsologtostderr", "-v=1")) + if err != nil { + t.Errorf("failed to disable storage-provisioner-rancher addon: args %q: %v", rr.Command(), err) + } +} diff --git a/test/integration/testdata/storage-provisioner-rancher/pod.yaml b/test/integration/testdata/storage-provisioner-rancher/pod.yaml new file mode 100644 index 000000000000..0930c37be549 --- /dev/null +++ b/test/integration/testdata/storage-provisioner-rancher/pod.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Pod +metadata: + name: test-local-path + labels: + run: test-local-path +spec: + restartPolicy: OnFailure + containers: + - name: busybox + image: busybox:stable + command: ["sh", "-c", "echo 'local-path-provisioner' > /test/file1"] + volumeMounts: + - name: data + mountPath: /test + volumes: + - name: data + persistentVolumeClaim: + claimName: test-pvc diff --git a/test/integration/testdata/storage-provisioner-rancher/pvc.yaml b/test/integration/testdata/storage-provisioner-rancher/pvc.yaml new file mode 100644 index 000000000000..d99a27189d71 --- /dev/null +++ b/test/integration/testdata/storage-provisioner-rancher/pvc.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: test-pvc +spec: + storageClassName: local-path + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 64Mi