sigs.k8s.io/blob-csi-driver@v1.24.1/test/e2e/testsuites/dynamically_provisioned_delete_pod_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  
    22  	"sigs.k8s.io/blob-csi-driver/test/e2e/driver"
    23  
    24  	"github.com/onsi/ginkgo/v2"
    25  	v1 "k8s.io/api/core/v1"
    26  	clientset "k8s.io/client-go/kubernetes"
    27  )
    28  
    29  // DynamicallyProvisionedDeletePodTest will provision required StorageClass and Deployment
    30  // Testing if the Pod can write and read to mounted volumes
    31  // Deleting a pod, and again testing if the Pod can write and read to mounted volumes
    32  type DynamicallyProvisionedDeletePodTest struct {
    33  	CSIDriver              driver.DynamicPVTestDriver
    34  	Pod                    PodDetails
    35  	PodCheck               *PodExecCheck
    36  	StorageClassParameters map[string]string
    37  }
    38  
    39  type PodExecCheck struct {
    40  	Cmd            []string
    41  	ExpectedString string
    42  }
    43  
    44  func (t *DynamicallyProvisionedDeletePodTest) Run(ctx context.Context, client clientset.Interface, namespace *v1.Namespace) {
    45  	tDeployment, cleanup, _ := 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  	ginkgo.By("deleting the pod for deployment")
    58  	tDeployment.DeletePodAndWait(ctx)
    59  
    60  	ginkgo.By("checking again that the pod is running")
    61  	tDeployment.WaitForPodReady(ctx)
    62  
    63  	if t.PodCheck != nil {
    64  		ginkgo.By("checking pod exec")
    65  		tDeployment.Exec(t.PodCheck.Cmd, t.PodCheck.ExpectedString)
    66  	}
    67  }