|
| 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 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +Unless required by applicable law or agreed to in writing, software |
| 9 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +See the License for the specific language governing permissions and |
| 12 | +limitations under the License. |
| 13 | +*/ |
| 14 | + |
| 15 | +package testsuites |
| 16 | + |
| 17 | +import ( |
| 18 | + "github.com/kubernetes-sigs/azuredisk-csi-driver/pkg/azuredisk" |
| 19 | + "github.com/kubernetes-sigs/azuredisk-csi-driver/test/e2e/driver" |
| 20 | + |
| 21 | + "k8s.io/api/core/v1" |
| 22 | + clientset "k8s.io/client-go/kubernetes" |
| 23 | +) |
| 24 | + |
| 25 | +// DynamicallyProvisionedReclaimPolicyTest will provision required PV(s) and PVC(s) |
| 26 | +// Testing the correct behavior for different reclaimPolicies |
| 27 | +type DynamicallyProvisionedReclaimPolicyTest struct { |
| 28 | + CSIDriver driver.DynamicPVTestDriver |
| 29 | + Volumes []VolumeDetails |
| 30 | + Azuredisk *azuredisk.Driver |
| 31 | +} |
| 32 | + |
| 33 | +func (t *DynamicallyProvisionedReclaimPolicyTest) Run(client clientset.Interface, namespace *v1.Namespace) { |
| 34 | + for _, volume := range t.Volumes { |
| 35 | + tpvc, _ := volume.SetupDynamicPersistentVolumeClaim(client, namespace, t.CSIDriver) |
| 36 | + |
| 37 | + // will delete the PVC |
| 38 | + // will also wait for PV to be deleted when reclaimPolicy=Delete |
| 39 | + tpvc.Cleanup() |
| 40 | + // first check PV stills exists, then manually delete it |
| 41 | + if tpvc.ReclaimPolicy() == v1.PersistentVolumeReclaimRetain { |
| 42 | + tpvc.WaitForPersistentVolumePhase(v1.VolumeReleased) |
| 43 | + tpvc.DeleteBoundPersistentVolume() |
| 44 | + tpvc.DeleteBackingVolume(t.Azuredisk) |
| 45 | + } |
| 46 | + } |
| 47 | +} |
0 commit comments