@@ -505,11 +505,8 @@ func (v *VSHandler) PreparePVC(pvcName string, prepFinalSync, copyMethodDirect b
505
505
return nil
506
506
}
507
507
508
- // This doesn't need to specifically be in VSHandler - could be useful for non-volsync scenarios?
509
- // Will look at annotations on the PVC, make sure the reconcile option from ACM is set to merge (or not exists)
510
- // and then will remove ACM annotations and also add VRG as the owner. This is to break the connection between
511
- // the appsub and the PVC itself. This way we can proceed to remove the app without the PVC being removed.
512
- // We need the PVC left behind for running the final sync or for CopyMethod Direct.
508
+ // TakePVCOwnership adds do-not-delete annotation to indicate that ACM should not delete/cleanup this pvc
509
+ // when the appsub is removed and adds VRG as owner so the PVC is garbage collected when the VRG is deleted.
513
510
func (v * VSHandler ) TakePVCOwnership (pvcName string ) (bool , error ) {
514
511
l := v .log .WithValues ("pvcName" , pvcName )
515
512
@@ -562,23 +559,6 @@ func (v *VSHandler) pvcExistsAndInUse(pvcName string, inUsePodMustBeReady bool)
562
559
return util .IsPVAttachedToNode (v .ctx , v .client , v .log , pvc )
563
560
}
564
561
565
- func (v * VSHandler ) pvcExists (pvcName string ) (bool , * corev1.PersistentVolumeClaim , error ) {
566
- pvc , err := v .getPVC (pvcName )
567
- if err != nil {
568
- if ! kerrors .IsNotFound (err ) {
569
- v .log .V (1 ).Info ("failed to get PVC" )
570
-
571
- return false , pvc , err
572
- }
573
-
574
- return false , pvc , nil
575
- }
576
-
577
- v .log .V (1 ).Info ("PVC found" )
578
-
579
- return true , pvc , nil
580
- }
581
-
582
562
func (v * VSHandler ) getPVC (pvcName string ) (* corev1.PersistentVolumeClaim , error ) {
583
563
pvc := & corev1.PersistentVolumeClaim {}
584
564
@@ -588,7 +568,7 @@ func (v *VSHandler) getPVC(pvcName string) (*corev1.PersistentVolumeClaim, error
588
568
Namespace : v .owner .GetNamespace (),
589
569
}, pvc )
590
570
if err != nil {
591
- return pvc , fmt .Errorf ("%w" , err )
571
+ return nil , fmt .Errorf ("%w" , err )
592
572
}
593
573
594
574
return pvc , nil
@@ -917,6 +897,7 @@ func (v *VSHandler) EnsurePVCfromRD(rdSpec ramendrv1alpha1.VolSyncReplicationDes
917
897
return v .validateSnapshotAndEnsurePVC (rdSpec , * vsImageRef , failoverAction )
918
898
}
919
899
900
+ //nolint:cyclop
920
901
func (v * VSHandler ) EnsurePVCforDirectCopy (ctx context.Context ,
921
902
rdSpec ramendrv1alpha1.VolSyncReplicationDestinationSpec ,
922
903
) error {
@@ -930,12 +911,12 @@ func (v *VSHandler) EnsurePVCforDirectCopy(ctx context.Context,
930
911
return fmt .Errorf ("capacity must be provided %v" , rdSpec .ProtectedPVC )
931
912
}
932
913
933
- exists , pvc , err := v .pvcExists (rdSpec .ProtectedPVC .Name )
934
- if err != nil {
914
+ pvc , err := v .getPVC (rdSpec .ProtectedPVC .Name )
915
+ if err != nil && ! kerrors . IsNotFound ( err ) {
935
916
return err
936
917
}
937
918
938
- if exists {
919
+ if pvc != nil {
939
920
return v .removeOCMAnnotationsAndUpdate (pvc )
940
921
}
941
922
@@ -2110,17 +2091,11 @@ func (v *VSHandler) DisownVolSyncManagedPVC(pvc *corev1.PersistentVolumeClaim) e
2110
2091
// TODO: Remove just the VRG ownerReference instead of blindly removing all ownerreferences.
2111
2092
// For now, this is fine, given that the VRG is the sole owner of the PVC after DR is enabled.
2112
2093
pvc .ObjectMeta .OwnerReferences = nil
2113
- v . deleteAnnotation (pvc , ACMAppSubDoNotDeleteAnnotation )
2094
+ delete (pvc . Annotations , ACMAppSubDoNotDeleteAnnotation )
2114
2095
2115
2096
return v .client .Update (v .ctx , pvc )
2116
2097
}
2117
2098
2118
- func (v * VSHandler ) deleteAnnotation (obj client.Object , annotationName string ) {
2119
- annotations := obj .GetAnnotations ()
2120
- delete (annotations , annotationName )
2121
- obj .SetAnnotations (annotations )
2122
- }
2123
-
2124
2099
func (v * VSHandler ) addBackOCMAnnotationsAndUpdate (obj client.Object , annotations map [string ]string ) error {
2125
2100
updatedAnnotations := obj .GetAnnotations ()
2126
2101
0 commit comments