github.com/jmclong/azuredisk-csi-driver@v0.7.0/test/e2e/testsuites/dynamically_provisioned_volume_cloning_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  	"sigs.k8s.io/azuredisk-csi-driver/test/e2e/driver"
    21  
    22  	"github.com/onsi/ginkgo"
    23  	v1 "k8s.io/api/core/v1"
    24  	clientset "k8s.io/client-go/kubernetes"
    25  )
    26  
    27  // DynamicallyProvisionedVolumeCloningTest will provision required StorageClass(es), PVC(s) and Pod(s)
    28  type DynamicallyProvisionedVolumeCloningTest struct {
    29  	CSIDriver           driver.DynamicPVTestDriver
    30  	Pod                 PodDetails
    31  	PodWithClonedVolume PodDetails
    32  }
    33  
    34  func (t *DynamicallyProvisionedVolumeCloningTest) Run(client clientset.Interface, namespace *v1.Namespace) {
    35  	// create the storageClass
    36  	tsc, tscCleanup := t.Pod.Volumes[0].CreateStorageClass(client, namespace, t.CSIDriver)
    37  	defer tscCleanup()
    38  
    39  	// create the pod
    40  	t.Pod.Volumes[0].StorageClass = tsc.storageClass
    41  	tpod, cleanups := t.Pod.SetupWithDynamicVolumes(client, namespace, t.CSIDriver)
    42  	for i := range cleanups {
    43  		defer cleanups[i]()
    44  	}
    45  
    46  	ginkgo.By("deploying the pod")
    47  	tpod.Create()
    48  	defer tpod.Cleanup()
    49  	ginkgo.By("checking that the pod's command exits with no error")
    50  	tpod.WaitForSuccess()
    51  
    52  	ginkgo.By("cloning existing volume")
    53  	clonedVolume := t.Pod.Volumes[0]
    54  	clonedVolume.DataSource = &DataSource{
    55  		Name: tpod.pod.Spec.Volumes[0].VolumeSource.PersistentVolumeClaim.ClaimName,
    56  		Kind: VolumePVCKind,
    57  	}
    58  	clonedVolume.StorageClass = tsc.storageClass
    59  	t.PodWithClonedVolume.Volumes = []VolumeDetails{clonedVolume}
    60  	tpod, cleanups = t.PodWithClonedVolume.SetupWithDynamicVolumes(client, namespace, t.CSIDriver)
    61  	for i := range cleanups {
    62  		defer cleanups[i]()
    63  	}
    64  
    65  	ginkgo.By("deploying a second pod with cloned volume")
    66  	tpod.Create()
    67  	defer tpod.Cleanup()
    68  	ginkgo.By("checking that the pod's command exits with no error")
    69  	tpod.WaitForSuccess()
    70  }