Skip to content

Commit a51423d

Browse files
committed
Add integration test for storage-provisioner-rancher addon
1 parent 0fb290e commit a51423d

File tree

3 files changed

+94
-1
lines changed

3 files changed

+94
-1
lines changed

test/integration/addons_test.go

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737

3838
"github.com/blang/semver/v4"
3939
retryablehttp "github.com/hashicorp/go-retryablehttp"
40+
core "k8s.io/api/core/v1"
4041
"k8s.io/minikube/pkg/kapi"
4142
"k8s.io/minikube/pkg/minikube/constants"
4243
"k8s.io/minikube/pkg/minikube/detect"
@@ -78,7 +79,7 @@ func TestAddons(t *testing.T) {
7879
// so we override that here to let minikube auto-detect appropriate cgroup driver
7980
os.Setenv(constants.MinikubeForceSystemdEnv, "")
8081

81-
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()...)
82+
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()...)
8283
if !NoneDriver() { // none driver does not support ingress
8384
args = append(args, "--addons=ingress", "--addons=ingress-dns")
8485
}
@@ -111,6 +112,7 @@ func TestAddons(t *testing.T) {
111112
{"CSI", validateCSIDriverAndSnapshots},
112113
{"Headlamp", validateHeadlampAddon},
113114
{"CloudSpanner", validateCloudSpannerAddon},
115+
{"LocalPath", validateLocalPathAddon},
114116
}
115117
for _, tc := range tests {
116118
tc := tc
@@ -837,3 +839,64 @@ func validateCloudSpannerAddon(ctx context.Context, t *testing.T, profile string
837839
t.Errorf("failed to disable cloud-spanner addon: args %q : %v", rr.Command(), err)
838840
}
839841
}
842+
843+
// validateLocalPathAddon tests the functionality of the storage-provisioner-rancher addon
844+
func validateLocalPathAddon(ctx context.Context, t *testing.T, profile string) {
845+
846+
if NoneDriver() {
847+
t.Skipf("skip local-path test on none driver")
848+
}
849+
850+
// Create a test PVC
851+
rr, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "apply", "-f", filepath.Join(*testdataDir, "storage-provisioner-rancher", "pvc.yaml")))
852+
if err != nil {
853+
t.Fatalf("kubectl apply pvc.yaml failed: args %q: %v", rr.Command(), err)
854+
}
855+
856+
// Deploy a simple pod with PVC
857+
rr, err = Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "apply", "-f", filepath.Join(*testdataDir, "storage-provisioner-rancher", "pod.yaml")))
858+
if err != nil {
859+
t.Fatalf("kubectl apply pod.yaml failed: args %q: %v", rr.Command(), err)
860+
}
861+
if err := PVCWait(ctx, t, profile, "default", "test-pvc", Minutes(5)); err != nil {
862+
t.Fatalf("failed waiting for PVC test-pvc: %v", err)
863+
}
864+
if _, err := PodWait(ctx, t, profile, "default", "run=test-local-path", Minutes(3)); err != nil {
865+
t.Fatalf("failed waiting for test-local-path pod: %v", err)
866+
}
867+
868+
// Get info about PVC
869+
rr, err = Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "get", "pvc", "test-pvc", "-o=json"))
870+
if err != nil {
871+
t.Fatalf("kubectl get pvc with %s failed: %v", rr.Command(), err)
872+
}
873+
pvc := core.PersistentVolumeClaim{}
874+
if err := json.NewDecoder(bytes.NewReader(rr.Stdout.Bytes())).Decode(&pvc); err != nil {
875+
t.Fatalf("failed decoding json to pvc: %v", err)
876+
}
877+
878+
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)))
879+
if err != nil {
880+
t.Fatalf("ssh error: %v", err)
881+
}
882+
883+
got := rr.Stdout.String()
884+
want := "local-path-provisioner"
885+
if !strings.Contains(got, want) {
886+
t.Fatalf("%v stdout = %q, want %q", rr.Command(), got, want)
887+
}
888+
889+
// Cleanup
890+
rr, err = Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "delete", "pod", "test-local-path"))
891+
if err != nil {
892+
t.Logf("cleanup with %s failed: %v", rr.Command(), err)
893+
}
894+
rr, err = Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "delete", "pvc", "test-pvc"))
895+
if err != nil {
896+
t.Logf("cleanup with %s failed: %v", rr.Command(), err)
897+
}
898+
rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "addons", "disable", "storage-provisioner-rancher", "--alsologtostderr", "-v=1"))
899+
if err != nil {
900+
t.Errorf("failed to disable storage-provisioner-rancher addon: args %q: %v", rr.Command(), err)
901+
}
902+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: test-local-path
5+
labels:
6+
run: test-local-path
7+
spec:
8+
restartPolicy: OnFailure
9+
containers:
10+
- name: busybox
11+
image: busybox:stable
12+
command: ["sh", "-c", "echo 'local-path-provisioner' > /test/file1"]
13+
volumeMounts:
14+
- name: data
15+
mountPath: /test
16+
volumes:
17+
- name: data
18+
persistentVolumeClaim:
19+
claimName: test-pvc
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: PersistentVolumeClaim
3+
metadata:
4+
name: test-pvc
5+
spec:
6+
storageClassName: local-path
7+
accessModes:
8+
- ReadWriteOnce
9+
resources:
10+
requests:
11+
storage: 64Mi

0 commit comments

Comments
 (0)