sigs.k8s.io/blob-csi-driver@v1.24.1/test/e2e/testsuites/dynamically_provisioned_restart_driver_tester.go (about) 1 /* 2 Copyright 2021 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package testsuites 18 19 import ( 20 "context" 21 "os" 22 "sync" 23 24 "github.com/onsi/ginkgo/v2" 25 v1 "k8s.io/api/core/v1" 26 clientset "k8s.io/client-go/kubernetes" 27 28 "sigs.k8s.io/blob-csi-driver/test/e2e/driver" 29 ) 30 31 // DynamicallyProvisionedRestartDriverTest will test to ensure that restarting driver doesn't affect pod mounting. 32 // It will mount a pod, restart the driver daemonset and ensure that the pod still has access to original volume. 33 type DynamicallyProvisionedRestartDriverTest struct { 34 CSIDriver driver.DynamicPVTestDriver 35 Pod PodDetails 36 PodCheck *PodExecCheck 37 StorageClassParameters map[string]string 38 RestartDriverFunc func() 39 } 40 41 func (t *DynamicallyProvisionedRestartDriverTest) Run(ctx context.Context, client clientset.Interface, namespace *v1.Namespace) { 42 var wg, wgPodReady sync.WaitGroup 43 var restartCompleted = make(chan struct{}) 44 45 var run = func() { 46 defer wg.Done() 47 defer ginkgo.GinkgoRecover() 48 49 tDeployment, cleanup, _ := t.Pod.SetupDeployment(ctx, client, namespace, t.CSIDriver, t.StorageClassParameters) 50 // defer must be called here for resources not get removed before using them 51 for i := range cleanup { 52 defer cleanup[i](ctx) 53 } 54 55 ginkgo.By("creating the deployment for the pod") 56 tDeployment.Create(ctx) 57 58 ginkgo.By("checking that the pod is running") 59 tDeployment.WaitForPodReady(ctx) 60 61 if t.PodCheck != nil { 62 ginkgo.By("checking if pod is able to access volume") 63 tDeployment.PollForStringInPodsExec(t.PodCheck.Cmd, t.PodCheck.ExpectedString) 64 } 65 wgPodReady.Done() 66 67 <-restartCompleted 68 ginkgo.By("driver daemonset restarted, check if pod still has access to volume") 69 if t.PodCheck != nil { 70 ginkgo.By("checking if pod still has access to volume after driver restart") 71 tDeployment.PollForStringInPodsExec(t.PodCheck.Cmd, t.PodCheck.ExpectedString) 72 } 73 } 74 75 ginkgo.By("run for nfs") 76 t.StorageClassParameters["protocol"] = "nfs" 77 wg.Add(1) 78 wgPodReady.Add(1) 79 go run() 80 81 _, useBlobfuseProxy := os.LookupEnv("ENABLE_BLOBFUSE_PROXY") 82 if useBlobfuseProxy { 83 t.StorageClassParameters["skuName"] = "Standard_LRS" 84 85 ginkgo.By("run for blobfuse") 86 t.StorageClassParameters["protocol"] = "fuse" 87 wg.Add(1) 88 wgPodReady.Add(1) 89 go run() 90 91 ginkgo.By("run for blobfuse2") 92 t.StorageClassParameters["protocol"] = "fuse2" 93 wg.Add(1) 94 wgPodReady.Add(1) 95 go run() 96 } 97 98 // wait for pod to be ready 99 wgPodReady.Wait() 100 101 // restart the driver 102 ginkgo.By("restarting the driver daemonset") 103 t.RestartDriverFunc() 104 105 // restart completed, notify all goroutine to continue checking 106 close(restartCompleted) 107 108 // wait for cleanup finish 109 wg.Wait() 110 }