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 Jan 14, 2023
1 parent c339c0c commit 6c81e58
Show file tree
Hide file tree
Showing 3 changed files with 87 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/detect"
"k8s.io/minikube/pkg/util/retry"
Expand Down Expand Up @@ -70,7 +71,7 @@ func TestAddons(t *testing.T) {
// MOCK_GOOGLE_TOKEN forces the gcp-auth webhook to use a mock token instead of trying to get a valid one from the credentials.
t.Setenv("MOCK_GOOGLE_TOKEN", "true")

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"}, 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=storage-provisioner-rancher"}, StartArgs()...)
if !NoneDriver() { // none driver does not support ingress
args = append(args, "--addons=ingress", "--addons=ingress-dns")
}
Expand Down Expand Up @@ -102,6 +103,7 @@ func TestAddons(t *testing.T) {
{"CSI", validateCSIDriverAndSnapshots},
{"Headlamp", validateHeadlampAddon},
{"CloudSpanner", validateCloudSpannerAddon},
{"LocalPath", validateLocalPathAddon},
}
for _, tc := range tests {
tc := tc
Expand Down Expand Up @@ -799,3 +801,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 := PodWait(ctx, t, profile, "default", "run=test-local-path", Minutes(3)); err != nil {
t.Fatalf("failed waiting for test-local-path pod: %v", err)
}
if err := PVCWait(ctx, t, profile, "default", "test-pvc", Minutes(5)); err != nil {
t.Fatalf("failed waiting for PVC test-pvc: %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("kubectl get pvc failed: args %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)
}
}
18 changes: 18 additions & 0 deletions test/integration/testdata/storage-provisioner-rancher/pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v1
kind: Pod
metadata:
name: test-local-path
labels:
run: test-local-path
spec:
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 6c81e58

Please sign in to comment.