Skip to content

Commit

Permalink
Add integration test for storage-provisioner-rancher addon
Browse files Browse the repository at this point in the history
  • Loading branch information
presztak committed Sep 12, 2023
1 parent cd887c6 commit 8209b3f
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
60 changes: 59 additions & 1 deletion test/integration/addons_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -111,6 +112,7 @@ func TestAddons(t *testing.T) {
{"CSI", validateCSIDriverAndSnapshots},
{"Headlamp", validateHeadlampAddon},
{"CloudSpanner", validateCloudSpannerAddon},
{"LocalPath", validateLocalPathAddon},
}
for _, tc := range tests {
tc := tc
Expand Down Expand Up @@ -837,3 +839,59 @@ 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) {
// 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)
}
}
19 changes: 19 additions & 0 deletions test/integration/testdata/storage-provisioner-rancher/pod.yaml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions test/integration/testdata/storage-provisioner-rancher/pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: test-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 64Mi

0 comments on commit 8209b3f

Please sign in to comment.