@@ -17,10 +17,11 @@ limitations under the License.
17
17
package common_controller
18
18
19
19
import (
20
- // "errors"
20
+ "errors"
21
21
"testing"
22
22
"time"
23
23
24
+ "github.com/kubernetes-csi/external-snapshotter/v2/pkg/utils"
24
25
v1 "k8s.io/api/core/v1"
25
26
storagev1beta1 "k8s.io/api/storage/v1beta1"
26
27
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -282,6 +283,59 @@ func TestSync(t *testing.T) {
282
283
errors : noerrors ,
283
284
test : testSyncSnapshot ,
284
285
},
286
+ {
287
+ name : "5-1 - content missing finalizer is updated to have finalizer" ,
288
+ initialContents : newContentArray ("content5-1" , "snapuid5-1" , "snap5-1" , "sid5-1" , validSecretClass , "" , "" , deletionPolicy , nil , nil , false ),
289
+ expectedContents : newContentArray ("content5-1" , "snapuid5-1" , "snap5-1" , "sid5-1" , validSecretClass , "" , "" , deletionPolicy , nil , nil , true ),
290
+ initialClaims : newClaimArray ("claim5-1" , "pvc-uid5-1" , "1Gi" , "volume5-1" , v1 .ClaimBound , & classEmpty ),
291
+ initialVolumes : newVolumeArray ("volume5-1" , "pv-uid5-1" , "pv-handle5-1" , "1Gi" , "pvc-uid5-1" , "claim5-1" , v1 .VolumeBound , v1 .PersistentVolumeReclaimDelete , classEmpty ),
292
+ initialSecrets : []* v1.Secret {secret ()},
293
+ errors : noerrors ,
294
+ test : testSyncContent ,
295
+ },
296
+ {
297
+ name : "5-2 - content missing finalizer update attempt fails because of failed API call" ,
298
+ initialContents : newContentArray ("content5-2" , "snapuid5-2" , "snap5-2" , "sid5-2" , validSecretClass , "" , "" , deletionPolicy , nil , nil , false ),
299
+ expectedContents : newContentArray ("content5-2" , "snapuid5-2" , "snap5-2" , "sid5-2" , validSecretClass , "" , "" , deletionPolicy , nil , nil , false ),
300
+ initialClaims : newClaimArray ("claim5-2" , "pvc-uid5-2" , "1Gi" , "volume5-2" , v1 .ClaimBound , & classEmpty ),
301
+ initialVolumes : newVolumeArray ("volume5-2" , "pv-uid5-2" , "pv-handle5-2" , "1Gi" , "pvc-uid5-2" , "claim5-2" , v1 .VolumeBound , v1 .PersistentVolumeReclaimDelete , classEmpty ),
302
+ initialSecrets : []* v1.Secret {secret ()},
303
+ errors : []reactorError {
304
+ // Inject error to the forth client.VolumesnapshotV1beta1().VolumeSnapshots().Update call.
305
+ {"update" , "volumesnapshotcontents" , errors .New ("mock update error" )},
306
+ },
307
+ expectSuccess : false ,
308
+ test : testSyncContentError ,
309
+ },
310
+ {
311
+ name : "5-3 - snapshot deletion candidate marked for deletion" ,
312
+ initialSnapshots : newSnapshotArray ("snap5-3" , "snapuid5-3" , "claim5-3" , "" , validSecretClass , "content5-3" , & False , nil , nil , nil , false , true , & timeNowMetav1 ),
313
+ expectedSnapshots : newSnapshotArray ("snap5-3" , "snapuid5-3" , "claim5-3" , "" , validSecretClass , "content5-3" , & False , nil , nil , nil , false , true , & timeNowMetav1 ),
314
+ initialContents : newContentArray ("content5-3" , "snapuid5-3" , "snap5-3" , "sid5-3" , validSecretClass , "" , "" , deletionPolicy , nil , nil , true ),
315
+ expectedContents : withContentAnnotations (newContentArray ("content5-3" , "snapuid5-3" , "snap5-3" , "sid5-3" , validSecretClass , "" , "" , deletionPolicy , nil , nil , true ), map [string ]string {utils .AnnVolumeSnapshotBeingDeleted : "yes" }),
316
+ initialClaims : newClaimArray ("claim5-3" , "pvc-uid5-3" , "1Gi" , "volume5-3" , v1 .ClaimBound , & classEmpty ),
317
+ initialVolumes : newVolumeArray ("volume5-3" , "pv-uid5-3" , "pv-handle5-3" , "1Gi" , "pvc-uid5-3" , "claim5-3" , v1 .VolumeBound , v1 .PersistentVolumeReclaimDelete , classEmpty ),
318
+ initialSecrets : []* v1.Secret {secret ()},
319
+ expectSuccess : true ,
320
+ test : testSyncContent ,
321
+ },
322
+ {
323
+ name : "5-4 - snapshot deletion candidate fail to mark for deletion due to failed API call" ,
324
+ initialSnapshots : newSnapshotArray ("snap5-4" , "snapuid5-4" , "claim5-4" , "" , validSecretClass , "content5-4" , & False , nil , nil , nil , false , true , & timeNowMetav1 ),
325
+ expectedSnapshots : newSnapshotArray ("snap5-4" , "snapuid5-4" , "claim5-4" , "" , validSecretClass , "content5-4" , & False , nil , nil , nil , false , true , & timeNowMetav1 ),
326
+ initialContents : newContentArray ("content5-4" , "snapuid5-4" , "snap5-4" , "sid5-4" , validSecretClass , "" , "" , deletionPolicy , nil , nil , true ),
327
+ // result of the test framework - annotation is still set in memory, but update call fails.
328
+ expectedContents : withContentAnnotations (newContentArray ("content5-4" , "snapuid5-4" , "snap5-4" , "sid5-4" , validSecretClass , "" , "" , deletionPolicy , nil , nil , true ), map [string ]string {utils .AnnVolumeSnapshotBeingDeleted : "yes" }),
329
+ initialClaims : newClaimArray ("claim5-4" , "pvc-uid5-4" , "1Gi" , "volume5-4" , v1 .ClaimBound , & classEmpty ),
330
+ initialVolumes : newVolumeArray ("volume5-4" , "pv-uid5-4" , "pv-handle5-4" , "1Gi" , "pvc-uid5-4" , "claim5-4" , v1 .VolumeBound , v1 .PersistentVolumeReclaimDelete , classEmpty ),
331
+ initialSecrets : []* v1.Secret {secret ()},
332
+ errors : []reactorError {
333
+ // Inject error to the forth client.VolumesnapshotV1beta1().VolumeSnapshots().Update call.
334
+ {"update" , "volumesnapshotcontents" , errors .New ("mock update error" )},
335
+ },
336
+ expectSuccess : false ,
337
+ test : testSyncContentError ,
338
+ },
285
339
}
286
340
287
341
runSyncTests (t , tests , snapshotClasses )
0 commit comments