|
| 1 | +/* |
| 2 | +Copyright 2024 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 common_controller |
| 18 | + |
| 19 | +import ( |
| 20 | + "testing" |
| 21 | + |
| 22 | + crdv1 "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumesnapshot/v1" |
| 23 | + "github.com/kubernetes-csi/external-snapshotter/v8/pkg/utils" |
| 24 | + v1 "k8s.io/api/core/v1" |
| 25 | +) |
| 26 | + |
| 27 | +func TestDeleteGroupSnapshotSync(t *testing.T) { |
| 28 | + tests := []controllerTest{ |
| 29 | + { |
| 30 | + name: "2-1 - group snapshot have been deleted, but no content was present - no op", |
| 31 | + initialGroupSnapshots: newGroupSnapshotArray( |
| 32 | + "group-snap-1-1", "group-snapuid1-1", map[string]string{ |
| 33 | + "app.kubernetes.io/name": "postgresql", |
| 34 | + }, |
| 35 | + "", classGold, "groupsnapcontent-group-snapuid1-1", &False, nil, nil, false, false, &timeNowMetav1, |
| 36 | + ), |
| 37 | + expectedGroupSnapshots: newGroupSnapshotArray( |
| 38 | + "group-snap-1-1", "group-snapuid1-1", map[string]string{ |
| 39 | + "app.kubernetes.io/name": "postgresql", |
| 40 | + }, |
| 41 | + "", classGold, "groupsnapcontent-group-snapuid1-1", &False, nil, nil, false, false, &timeNowMetav1, |
| 42 | + ), |
| 43 | + initialGroupContents: nil, |
| 44 | + expectedGroupContents: nil, |
| 45 | + initialClaims: withClaimLabels( |
| 46 | + newClaimCoupleArray("claim1-1", "pvc-uid6-1", "1Gi", "volume6-1", v1.ClaimBound, &classGold), |
| 47 | + map[string]string{ |
| 48 | + "app.kubernetes.io/name": "postgresql", |
| 49 | + }), |
| 50 | + initialVolumes: newVolumeCoupleArray("volume6-1", "pv-uid6-1", "pv-handle6-1", "1Gi", "pvc-uid6-1", "claim1-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classGold), |
| 51 | + errors: noerrors, |
| 52 | + test: testSyncGroupSnapshot, |
| 53 | + expectSuccess: true, |
| 54 | + }, |
| 55 | + { |
| 56 | + name: "2-2 - dynamic group snapshot have been deleted, was not provisioned, no-op", |
| 57 | + initialGroupSnapshots: newGroupSnapshotArray( |
| 58 | + "group-snap-1-1", "group-snapuid1-1", map[string]string{ |
| 59 | + "app.kubernetes.io/name": "postgresql", |
| 60 | + }, |
| 61 | + "", classGold, "", nil, nil, nil, true, false, &timeNowMetav1, |
| 62 | + ), |
| 63 | + expectedGroupSnapshots: newGroupSnapshotArray( |
| 64 | + "group-snap-1-1", "group-snapuid1-1", map[string]string{ |
| 65 | + "app.kubernetes.io/name": "postgresql", |
| 66 | + }, |
| 67 | + "", classGold, "", nil, nil, nil, true, false, &timeNowMetav1, |
| 68 | + ), |
| 69 | + initialGroupContents: nil, |
| 70 | + expectedGroupContents: nil, |
| 71 | + initialClaims: withClaimLabels( |
| 72 | + newClaimCoupleArray("claim1-1", "pvc-uid6-1", "1Gi", "volume6-1", v1.ClaimBound, &classGold), |
| 73 | + map[string]string{ |
| 74 | + "app.kubernetes.io/name": "postgresql", |
| 75 | + }), |
| 76 | + initialVolumes: nil, |
| 77 | + errors: noerrors, |
| 78 | + test: testSyncGroupSnapshot, |
| 79 | + expectSuccess: true, |
| 80 | + }, |
| 81 | + { |
| 82 | + name: "2-3 - pre-provisioned group snapshot have been deleted, retention policy set to retain - set 'being deleted' annotation", |
| 83 | + initialGroupSnapshots: withGroupSnapshotFinalizers( |
| 84 | + newGroupSnapshotArray( |
| 85 | + "group-snap-1-1", "group-snapuid1-1", map[string]string{ |
| 86 | + "app.kubernetes.io/name": "postgresql", |
| 87 | + }, |
| 88 | + "", classGold, "groupsnapcontent-group-snapuid1-1", &False, nil, nil, false, false, &timeNowMetav1, |
| 89 | + ), |
| 90 | + utils.VolumeGroupSnapshotBoundFinalizer, |
| 91 | + ), |
| 92 | + expectedGroupSnapshots: newGroupSnapshotArray( |
| 93 | + "group-snap-1-1", "group-snapuid1-1", map[string]string{ |
| 94 | + "app.kubernetes.io/name": "postgresql", |
| 95 | + }, |
| 96 | + "", classGold, "groupsnapcontent-group-snapuid1-1", &False, nil, nil, false, false, &timeNowMetav1, |
| 97 | + ), |
| 98 | + initialGroupContents: newGroupSnapshotContentArray( |
| 99 | + "groupsnapcontent-group-snapuid1-1", "group-snapuid1-1", "group-snap-1-1", "group-snapshot-handle", classGold, []string{ |
| 100 | + "1-pv-handle6-1", |
| 101 | + "2-pv-handle6-1", |
| 102 | + }, "", crdv1.VolumeSnapshotContentRetain, nil, false, false, |
| 103 | + ), |
| 104 | + expectedGroupContents: withGroupContentAnnotations( |
| 105 | + newGroupSnapshotContentArray( |
| 106 | + "groupsnapcontent-group-snapuid1-1", "group-snapuid1-1", "group-snap-1-1", "group-snapshot-handle", classGold, []string{ |
| 107 | + "1-pv-handle6-1", |
| 108 | + "2-pv-handle6-1", |
| 109 | + }, "", crdv1.VolumeSnapshotContentRetain, nil, false, false, |
| 110 | + ), |
| 111 | + map[string]string{ |
| 112 | + utils.AnnVolumeGroupSnapshotBeingDeleted: "yes", |
| 113 | + }, |
| 114 | + ), |
| 115 | + initialClaims: withClaimLabels( |
| 116 | + newClaimCoupleArray("claim1-1", "pvc-uid6-1", "1Gi", "volume6-1", v1.ClaimBound, &classGold), |
| 117 | + map[string]string{ |
| 118 | + "app.kubernetes.io/name": "postgresql", |
| 119 | + }), |
| 120 | + initialVolumes: newVolumeCoupleArray("volume6-1", "pv-uid6-1", "pv-handle6-1", "1Gi", "pvc-uid6-1", "claim1-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classGold), |
| 121 | + errors: noerrors, |
| 122 | + test: testSyncGroupSnapshot, |
| 123 | + expectSuccess: true, |
| 124 | + }, |
| 125 | + { |
| 126 | + name: "2-4 - pre-provisioned snapshot have been deleted, retention policy set to delete - volume snapshot content will be deleted", |
| 127 | + initialGroupSnapshots: withGroupSnapshotFinalizers( |
| 128 | + newGroupSnapshotArray( |
| 129 | + "group-snap-1-1", "group-snapuid1-1", map[string]string{ |
| 130 | + "app.kubernetes.io/name": "postgresql", |
| 131 | + }, |
| 132 | + "", classGold, "groupsnapcontent-group-snapuid1-1", &False, nil, nil, false, false, &timeNowMetav1, |
| 133 | + ), |
| 134 | + utils.VolumeGroupSnapshotBoundFinalizer, |
| 135 | + ), |
| 136 | + expectedGroupSnapshots: withGroupSnapshotFinalizers( |
| 137 | + newGroupSnapshotArray( |
| 138 | + "group-snap-1-1", "group-snapuid1-1", map[string]string{ |
| 139 | + "app.kubernetes.io/name": "postgresql", |
| 140 | + }, |
| 141 | + "", classGold, "groupsnapcontent-group-snapuid1-1", &False, nil, nil, false, false, &timeNowMetav1, |
| 142 | + ), |
| 143 | + utils.VolumeGroupSnapshotBoundFinalizer, |
| 144 | + ), |
| 145 | + initialGroupContents: newGroupSnapshotContentArray( |
| 146 | + "groupsnapcontent-group-snapuid1-1", "group-snapuid1-1", "group-snap-1-1", "group-snapshot-handle", classGold, []string{ |
| 147 | + "1-pv-handle6-1", |
| 148 | + "2-pv-handle6-1", |
| 149 | + }, "", crdv1.VolumeSnapshotContentDelete, nil, false, false, |
| 150 | + ), |
| 151 | + expectedGroupContents: nil, |
| 152 | + initialClaims: withClaimLabels( |
| 153 | + newClaimCoupleArray("claim1-1", "pvc-uid6-1", "1Gi", "volume6-1", v1.ClaimBound, &classGold), |
| 154 | + map[string]string{ |
| 155 | + "app.kubernetes.io/name": "postgresql", |
| 156 | + }), |
| 157 | + initialVolumes: newVolumeCoupleArray("volume6-1", "pv-uid6-1", "pv-handle6-1", "1Gi", "pvc-uid6-1", "claim1-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classGold), |
| 158 | + errors: noerrors, |
| 159 | + test: testSyncGroupSnapshot, |
| 160 | + expectSuccess: true, |
| 161 | + }, |
| 162 | + } |
| 163 | + runSyncTests(t, tests, nil, groupSnapshotClasses) |
| 164 | +} |
0 commit comments