sigs.k8s.io/blob-csi-driver@v1.24.1/test/e2e/testsuites/dynamically_provisioned_volume_unmount_tester.go (about)

     1  /*
     2  Copyright 2019 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  	"time"
    22  
    23  	"sigs.k8s.io/blob-csi-driver/pkg/blob"
    24  	"sigs.k8s.io/blob-csi-driver/test/e2e/driver"
    25  
    26  	"github.com/container-storage-interface/spec/lib/go/csi"
    27  	"github.com/onsi/ginkgo/v2"
    28  	"github.com/onsi/gomega"
    29  	v1 "k8s.io/api/core/v1"
    30  	clientset "k8s.io/client-go/kubernetes"
    31  )
    32  
    33  // DynamicallyProvisionedVolumeUnmountTest will provision required StorageClass and Deployment
    34  // Testing if the Pod can write and read to mounted volumes
    35  // Delete the volume and check whether pod could be terminated successfully
    36  type DynamicallyProvisionedVolumeUnmountTest struct {
    37  	CSIDriver              driver.DynamicPVTestDriver
    38  	Driver                 *blob.Driver
    39  	Pod                    PodDetails
    40  	PodCheck               *PodExecCheck
    41  	StorageClassParameters map[string]string
    42  }
    43  
    44  func (t *DynamicallyProvisionedVolumeUnmountTest) Run(ctx context.Context, client clientset.Interface, namespace *v1.Namespace) {
    45  	tDeployment, cleanup, volumeID := t.Pod.SetupDeployment(ctx, client, namespace, t.CSIDriver, t.StorageClassParameters)
    46  	// defer must be called here for resources not get removed before using them
    47  	for i := range cleanup {
    48  		defer cleanup[i](ctx)
    49  	}
    50  
    51  	ginkgo.By("deploying the deployment")
    52  	tDeployment.Create(ctx)
    53  
    54  	ginkgo.By("checking that the pod is running")
    55  	tDeployment.WaitForPodReady(ctx)
    56  
    57  	if t.PodCheck != nil {
    58  		time.Sleep(time.Second)
    59  		ginkgo.By("check pod exec")
    60  		tDeployment.PollForStringInPodsExec(t.PodCheck.Cmd, t.PodCheck.ExpectedString)
    61  	}
    62  
    63  	ginkgo.By("delete volume " + volumeID + " first, make sure pod could still be terminated")
    64  	_, err := t.Driver.DeleteVolume(ctx, &csi.DeleteVolumeRequest{VolumeId: volumeID})
    65  	gomega.Expect(err).NotTo(gomega.HaveOccurred())
    66  
    67  	ginkgo.By("check whether " + volumeID + " has been deleted")
    68  	multiNodeVolCap := []*csi.VolumeCapability{
    69  		{
    70  			AccessMode: &csi.VolumeCapability_AccessMode{
    71  				Mode: csi.VolumeCapability_AccessMode_MULTI_NODE_SINGLE_WRITER,
    72  			},
    73  		},
    74  	}
    75  	req := &csi.ValidateVolumeCapabilitiesRequest{
    76  		VolumeId:           volumeID,
    77  		VolumeCapabilities: multiNodeVolCap,
    78  	}
    79  	if _, err = t.Driver.ValidateVolumeCapabilities(ctx, req); err != nil {
    80  		ginkgo.By("ValidateVolumeCapabilities " + volumeID + " returned with error: " + err.Error())
    81  	}
    82  	gomega.Expect(err).To(gomega.HaveOccurred())
    83  
    84  	ginkgo.By("deleting the pod for deployment")
    85  	tDeployment.DeletePodAndWait(ctx)
    86  }