Skip to content

Commit

Permalink
Label PVCs for consistency groups (#1507)
Browse files Browse the repository at this point in the history
Signed-off-by: Elena Gershkovich <elenage@il.ibm.com>
  • Loading branch information
ELENAGER committed Aug 5, 2024
1 parent ce8f88a commit a9938f4
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
55 changes: 55 additions & 0 deletions internal/controller/volumereplicationgroup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,9 @@ const (
// StorageClass label
StorageIDLabel = "ramendr.openshift.io/storageid"

// Consistency group label
ConsistencyGroupLabel = "ramendr.openshift.io/consistency-group"

// VolumeReplicationClass label
VolumeReplicationIDLabel = "ramendr.openshift.io/replicationid"

Expand Down Expand Up @@ -548,6 +551,10 @@ func (v *VRGInstance) processVRG() ctrl.Result {
return v.invalid(err, "Failed to process list of PVCs to protect", true)
}

if err := v.labelPVCsForCG(); err != nil {
return v.invalid(err, "Failed to label PVCs for consistency groups", true)
}

v.log = v.log.WithName("vrginstance").WithValues("State", v.instance.Spec.ReplicationState)
v.s3StoreAccessorsGet()

Expand Down Expand Up @@ -694,6 +701,54 @@ func (v *VRGInstance) updatePVCList() error {
return v.separatePVCsUsingStorageClassProvisioner(pvcList)
}

func (v *VRGInstance) labelPVCsForCG() error {
if v.instance.Spec.Async == nil {
return nil
}

if !rmnutil.IsCGEnabled(v.instance.GetAnnotations()) {
return nil
}

for idx := range v.volRepPVCs {
pvc := &v.volRepPVCs[idx]

if err := v.addConsistencyGroupLabel(pvc); err != nil {
return fmt.Errorf("failed to label PVC %s/%s for consistency group (%w)",
pvc.GetNamespace(), pvc.GetName(), err)
}
}

return nil
}

func (v *VRGInstance) addConsistencyGroupLabel(pvc *corev1.PersistentVolumeClaim) error {
scName := pvc.Spec.StorageClassName

if scName == nil || *scName == "" {
return fmt.Errorf("missing storage class name for PVC %s/%s", pvc.GetNamespace(), pvc.GetName())
}

storageClass := &storagev1.StorageClass{}
if err := v.reconciler.Get(v.ctx, types.NamespacedName{Name: *scName}, storageClass); err != nil {
v.log.Info(fmt.Sprintf("Failed to get the storageclass %s", *scName))

return fmt.Errorf("failed to get the storageclass with name %s (%w)", *scName, err)
}

storageID, ok := storageClass.GetLabels()[StorageIDLabel]
if !ok {
v.log.Info("Missing storageID for PVC %s/%s", pvc.GetNamespace(), pvc.GetName())

return fmt.Errorf("missing storageID for PVC %s/%s", pvc.GetNamespace(), pvc.GetName())
}

// Add label for PVC, showing that this PVC is part of consistency group
return rmnutil.NewResourceUpdater(pvc).
AddLabel(ConsistencyGroupLabel, storageID).
Update(v.ctx, v.reconciler.Client)
}

func (v *VRGInstance) updateReplicationClassList() error {
if v.vrcUpdated {
return nil
Expand Down
3 changes: 0 additions & 3 deletions internal/controller/vrg_volsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ConsistencyGroupLabel (TODO) use ConsistencyGroupLabel in PR https://github.com/RamenDR/ramen/pull/1472/files
var ConsistencyGroupLabel = "ramendr.openshift.io/consistency-group"

//nolint:gocognit,funlen,cyclop
func (v *VRGInstance) restorePVsAndPVCsForVolSync() (int, error) {
v.log.Info("VolSync: Restoring VolSync PVs")
Expand Down

0 comments on commit a9938f4

Please sign in to comment.