@@ -37,6 +37,7 @@ import (
37
37
38
38
"github.com/blang/semver/v4"
39
39
retryablehttp "github.com/hashicorp/go-retryablehttp"
40
+ core "k8s.io/api/core/v1"
40
41
"k8s.io/minikube/pkg/kapi"
41
42
"k8s.io/minikube/pkg/minikube/constants"
42
43
"k8s.io/minikube/pkg/minikube/detect"
@@ -78,7 +79,7 @@ func TestAddons(t *testing.T) {
78
79
// so we override that here to let minikube auto-detect appropriate cgroup driver
79
80
os .Setenv (constants .MinikubeForceSystemdEnv , "" )
80
81
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 ()... )
82
83
if ! NoneDriver () { // none driver does not support ingress
83
84
args = append (args , "--addons=ingress" , "--addons=ingress-dns" )
84
85
}
@@ -111,6 +112,7 @@ func TestAddons(t *testing.T) {
111
112
{"CSI" , validateCSIDriverAndSnapshots },
112
113
{"Headlamp" , validateHeadlampAddon },
113
114
{"CloudSpanner" , validateCloudSpannerAddon },
115
+ {"LocalPath" , validateLocalPathAddon },
114
116
}
115
117
for _ , tc := range tests {
116
118
tc := tc
@@ -837,3 +839,59 @@ func validateCloudSpannerAddon(ctx context.Context, t *testing.T, profile string
837
839
t .Errorf ("failed to disable cloud-spanner addon: args %q : %v" , rr .Command (), err )
838
840
}
839
841
}
842
+
843
+ // validateLocalPathAddon tests the functionality of the storage-provisioner-rancher addon
844
+ func validateLocalPathAddon (ctx context.Context , t * testing.T , profile string ) {
845
+ // Create a test PVC
846
+ rr , err := Run (t , exec .CommandContext (ctx , "kubectl" , "--context" , profile , "apply" , "-f" , filepath .Join (* testdataDir , "storage-provisioner-rancher" , "pvc.yaml" )))
847
+ if err != nil {
848
+ t .Fatalf ("kubectl apply pvc.yaml failed: args %q: %v" , rr .Command (), err )
849
+ }
850
+
851
+ // Deploy a simple pod with PVC
852
+ rr , err = Run (t , exec .CommandContext (ctx , "kubectl" , "--context" , profile , "apply" , "-f" , filepath .Join (* testdataDir , "storage-provisioner-rancher" , "pod.yaml" )))
853
+ if err != nil {
854
+ t .Fatalf ("kubectl apply pod.yaml failed: args %q: %v" , rr .Command (), err )
855
+ }
856
+ if _ , err := PodWait (ctx , t , profile , "default" , "run=test-local-path" , Minutes (3 )); err != nil {
857
+ t .Fatalf ("failed waiting for test-local-path pod: %v" , err )
858
+ }
859
+ if err := PVCWait (ctx , t , profile , "default" , "test-pvc" , Minutes (5 )); err != nil {
860
+ t .Fatalf ("failed waiting for PVC test-pvc: %v" , err )
861
+ }
862
+
863
+ // Get info about PVC
864
+ rr , err = Run (t , exec .CommandContext (ctx , "kubectl" , "--context" , profile , "get" , "pvc" , "test-pvc" , "-o=json" ))
865
+ if err != nil {
866
+ t .Fatalf ("kubectl get pvc with %s failed: %v" , rr .Command (), err )
867
+ }
868
+ pvc := core.PersistentVolumeClaim {}
869
+ if err := json .NewDecoder (bytes .NewReader (rr .Stdout .Bytes ())).Decode (& pvc ); err != nil {
870
+ t .Fatalf ("failed decoding json to pvc: %v" , err )
871
+ }
872
+
873
+ 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 )))
874
+ if err != nil {
875
+ t .Fatalf ("ssh error: %v" , err )
876
+ }
877
+
878
+ got := rr .Stdout .String ()
879
+ want := "local-path-provisioner"
880
+ if ! strings .Contains (got , want ) {
881
+ t .Fatalf ("%v stdout = %q, want %q" , rr .Command (), got , want )
882
+ }
883
+
884
+ // Cleanup
885
+ rr , err = Run (t , exec .CommandContext (ctx , "kubectl" , "--context" , profile , "delete" , "pod" , "test-local-path" ))
886
+ if err != nil {
887
+ t .Logf ("cleanup with %s failed: %v" , rr .Command (), err )
888
+ }
889
+ rr , err = Run (t , exec .CommandContext (ctx , "kubectl" , "--context" , profile , "delete" , "pvc" , "test-pvc" ))
890
+ if err != nil {
891
+ t .Logf ("cleanup with %s failed: %v" , rr .Command (), err )
892
+ }
893
+ rr , err = Run (t , exec .CommandContext (ctx , Target (), "-p" , profile , "addons" , "disable" , "storage-provisioner-rancher" , "--alsologtostderr" , "-v=1" ))
894
+ if err != nil {
895
+ t .Errorf ("failed to disable storage-provisioner-rancher addon: args %q: %v" , rr .Command (), err )
896
+ }
897
+ }
0 commit comments