github.com/jmclong/azuredisk-csi-driver@v0.7.0/test/e2e/testsuites/dynamically_provisioned_reclaim_policy_tester.go (about) 1 /* 2 Copyright 2020 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/pkg/azuredisk" 21 "sigs.k8s.io/azuredisk-csi-driver/test/e2e/driver" 22 23 v1 "k8s.io/api/core/v1" 24 storagev1 "k8s.io/api/storage/v1" 25 clientset "k8s.io/client-go/kubernetes" 26 ) 27 28 // DynamicallyProvisionedReclaimPolicyTest will provision required PV(s) and PVC(s) 29 // Testing the correct behavior for different reclaimPolicies 30 type DynamicallyProvisionedReclaimPolicyTest struct { 31 CSIDriver driver.DynamicPVTestDriver 32 Volumes []VolumeDetails 33 Azuredisk *azuredisk.Driver 34 } 35 36 func (t *DynamicallyProvisionedReclaimPolicyTest) Run(client clientset.Interface, namespace *v1.Namespace) { 37 for _, volume := range t.Volumes { 38 // Force volume binding mode to immediate so the PV can be provisioned without a pod 39 volumeBindingMode := storagev1.VolumeBindingImmediate 40 volume.VolumeBindingMode = &volumeBindingMode 41 tpvc, _ := volume.SetupDynamicPersistentVolumeClaim(client, namespace, t.CSIDriver) 42 43 // will delete the PVC 44 // will also wait for PV to be deleted when reclaimPolicy=Delete 45 tpvc.Cleanup() 46 // first check PV stills exists, then manually delete it 47 if tpvc.ReclaimPolicy() == v1.PersistentVolumeReclaimRetain { 48 tpvc.WaitForPersistentVolumePhase(v1.VolumeReleased) 49 tpvc.DeleteBoundPersistentVolume() 50 tpvc.DeleteBackingVolume(t.Azuredisk) 51 } 52 } 53 }