@@ -489,16 +489,16 @@ func SetVolumeSnapshotContentDeletionPolicy(
489489 vscName string ,
490490 crClient crclient.Client ,
491491 policy snapshotv1api.DeletionPolicy ,
492- ) error {
492+ ) ( * snapshotv1api. VolumeSnapshotContent , error ) {
493493 vsc := new (snapshotv1api.VolumeSnapshotContent )
494494 if err := crClient .Get (context .TODO (), crclient.ObjectKey {Name : vscName }, vsc ); err != nil {
495- return err
495+ return nil , err
496496 }
497497
498498 originVSC := vsc .DeepCopy ()
499499 vsc .Spec .DeletionPolicy = policy
500500
501- return crClient .Patch (context .TODO (), vsc , crclient .MergeFrom (originVSC ))
501+ return vsc , crClient .Patch (context .TODO (), vsc , crclient .MergeFrom (originVSC ))
502502}
503503
504504// CleanupVolumeSnapshot deletes the VolumeSnapshot and the associated VolumeSnapshotContent. It will make sure the
@@ -523,7 +523,7 @@ func CleanupVolumeSnapshot(
523523 if vs .Status != nil && vs .Status .BoundVolumeSnapshotContentName != nil {
524524 // we patch the DeletionPolicy of the VolumeSnapshotContent to set it to Delete.
525525 // This ensures that the volume snapshot in the storage provider is also deleted.
526- err := SetVolumeSnapshotContentDeletionPolicy (
526+ _ , err := SetVolumeSnapshotContentDeletionPolicy (
527527 * vs .Status .BoundVolumeSnapshotContentName ,
528528 crClient ,
529529 snapshotv1api .VolumeSnapshotContentDelete ,
@@ -544,7 +544,6 @@ func CleanupVolumeSnapshot(
544544
545545func DeleteReadyVolumeSnapshot (
546546 vs snapshotv1api.VolumeSnapshot ,
547- vsc snapshotv1api.VolumeSnapshotContent ,
548547 client crclient.Client ,
549548 logger logrus.FieldLogger ,
550549) {
@@ -557,11 +556,15 @@ func DeleteReadyVolumeSnapshot(
557556 return
558557 }
559558
559+ var vsc * snapshotv1api.VolumeSnapshotContent
560+
560561 if vs .Status != nil && vs .Status .BoundVolumeSnapshotContentName != nil {
562+ var err error
563+
561564 // Patch the DeletionPolicy of the VolumeSnapshotContent to set it to Retain.
562565 // This ensures that the volume snapshot in the storage provider is kept.
563- if err : = SetVolumeSnapshotContentDeletionPolicy (
564- vsc . Name ,
566+ if vsc , err = SetVolumeSnapshotContentDeletionPolicy (
567+ * vs . Status . BoundVolumeSnapshotContentName ,
565568 client ,
566569 snapshotv1api .VolumeSnapshotContentRetain ,
567570 ); err != nil {
@@ -570,7 +573,7 @@ func DeleteReadyVolumeSnapshot(
570573 return
571574 }
572575
573- if err := client .Delete (context .TODO (), & vsc ); err != nil {
576+ if err := client .Delete (context .TODO (), vsc ); err != nil {
574577 logger .WithError (err ).Warnf ("Failed to delete the VolumeSnapshotContent %s" , vsc .Name )
575578 }
576579 }
0 commit comments