@@ -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/detect"
42
43
"k8s.io/minikube/pkg/util/retry"
@@ -70,7 +71,7 @@ func TestAddons(t *testing.T) {
70
71
// MOCK_GOOGLE_TOKEN forces the gcp-auth webhook to use a mock token instead of trying to get a valid one from the credentials.
71
72
t .Setenv ("MOCK_GOOGLE_TOKEN" , "true" )
72
73
73
- 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 ()... )
74
+ 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 ()... )
74
75
if ! NoneDriver () { // none driver does not support ingress
75
76
args = append (args , "--addons=ingress" , "--addons=ingress-dns" )
76
77
}
@@ -102,6 +103,7 @@ func TestAddons(t *testing.T) {
102
103
{"CSI" , validateCSIDriverAndSnapshots },
103
104
{"Headlamp" , validateHeadlampAddon },
104
105
{"CloudSpanner" , validateCloudSpannerAddon },
106
+ {"LocalPath" , validateLocalPathAddon },
105
107
}
106
108
for _ , tc := range tests {
107
109
tc := tc
@@ -799,3 +801,59 @@ func validateCloudSpannerAddon(ctx context.Context, t *testing.T, profile string
799
801
t .Errorf ("failed to disable cloud-spanner addon: args %q : %v" , rr .Command (), err )
800
802
}
801
803
}
804
+
805
+ // validateLocalPathAddon tests the functionality of the storage-provisioner-rancher addon
806
+ func validateLocalPathAddon (ctx context.Context , t * testing.T , profile string ) {
807
+ // Create a test PVC
808
+ rr , err := Run (t , exec .CommandContext (ctx , "kubectl" , "--context" , profile , "apply" , "-f" , filepath .Join (* testdataDir , "storage-provisioner-rancher" , "pvc.yaml" )))
809
+ if err != nil {
810
+ t .Fatalf ("kubectl apply pvc.yaml failed: args %q: %v" , rr .Command (), err )
811
+ }
812
+
813
+ // Deploy a simple pod with PVC
814
+ rr , err = Run (t , exec .CommandContext (ctx , "kubectl" , "--context" , profile , "apply" , "-f" , filepath .Join (* testdataDir , "storage-provisioner-rancher" , "pod.yaml" )))
815
+ if err != nil {
816
+ t .Fatalf ("kubectl apply pod.yaml failed: args %q: %v" , rr .Command (), err )
817
+ }
818
+ if _ , err := PodWait (ctx , t , profile , "default" , "run=test-local-path" , Minutes (3 )); err != nil {
819
+ t .Fatalf ("failed waiting for test-local-path pod: %v" , err )
820
+ }
821
+ if err := PVCWait (ctx , t , profile , "default" , "test-pvc" , Minutes (5 )); err != nil {
822
+ t .Fatalf ("failed waiting for PVC test-pvc: %v" , err )
823
+ }
824
+
825
+ // Get info about PVC
826
+ rr , err = Run (t , exec .CommandContext (ctx , "kubectl" , "--context" , profile , "get" , "pvc" , "test-pvc" , "-o=json" ))
827
+ if err != nil {
828
+ t .Fatalf ("kubectl get pvc with %s failed: %v" , rr .Command (), err )
829
+ }
830
+ pvc := core.PersistentVolumeClaim {}
831
+ if err := json .NewDecoder (bytes .NewReader (rr .Stdout .Bytes ())).Decode (& pvc ); err != nil {
832
+ t .Fatalf ("kubectl get pvc failed: args %v" , err )
833
+ }
834
+
835
+ 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 )))
836
+ if err != nil {
837
+ t .Fatalf ("ssh error: %v" , err )
838
+ }
839
+
840
+ got := rr .Stdout .String ()
841
+ want := "local-path-provisioner"
842
+ if ! strings .Contains (got , want ) {
843
+ t .Fatalf ("%v stdout = %q, want %q" , rr .Command (), got , want )
844
+ }
845
+
846
+ // Cleanup
847
+ rr , err = Run (t , exec .CommandContext (ctx , "kubectl" , "--context" , profile , "delete" , "pod" , "test-local-path" ))
848
+ if err != nil {
849
+ t .Logf ("cleanup with %s failed: %v" , rr .Command (), err )
850
+ }
851
+ rr , err = Run (t , exec .CommandContext (ctx , "kubectl" , "--context" , profile , "delete" , "pvc" , "test-pvc" ))
852
+ if err != nil {
853
+ t .Logf ("cleanup with %s failed: %v" , rr .Command (), err )
854
+ }
855
+ rr , err = Run (t , exec .CommandContext (ctx , Target (), "-p" , profile , "addons" , "disable" , "storage-provisioner-rancher" , "--alsologtostderr" , "-v=1" ))
856
+ if err != nil {
857
+ t .Errorf ("failed to disable storage-provisioner-rancher addon: args %q: %v" , rr .Command (), err )
858
+ }
859
+ }
0 commit comments