Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Label PVCs for consistency groups #1507

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Member

@BenamarMk BenamarMk Aug 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am just mentioning a conversation we had in another PR here: #1472 (comment)

This works for now. We will just have one CG per DRPC.

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
Loading