Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
Signed-off-by: Elena Gershkovich <[email protected]>
  • Loading branch information
ELENAGER committed Jul 22, 2024
1 parent 4985ab3 commit 2f4eee7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
36 changes: 18 additions & 18 deletions internal/controller/volumereplicationgroup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,20 +726,7 @@ func (v *VRGInstance) updatePVCListForCG() error {
for idx := range v.volRepPVCs {
pvc := &v.volRepPVCs[idx]

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)
}

if err := v.addConsistencyGroupLabel(pvc, storageClass); err != nil {
if err := v.addConsistencyGroupLabel(pvc); err != nil {
return fmt.Errorf("failed to mark PVC %s/%s for consistency group (%w)",
pvc.GetNamespace(), pvc.GetName(), err)
}
Expand All @@ -748,12 +735,25 @@ func (v *VRGInstance) updatePVCListForCG() error {
return nil
}

func (v *VRGInstance) addConsistencyGroupLabel(pvc *corev1.PersistentVolumeClaim,
storageClass *storagev1.StorageClass,
) error {
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 {
return nil
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
Expand Down
8 changes: 4 additions & 4 deletions internal/controller/vrg_volrep.go
Original file line number Diff line number Diff line change
Expand Up @@ -947,9 +947,9 @@ func (v *VRGInstance) reconcileMissingVR(pvc *corev1.PersistentVolumeClaim, log
func (v *VRGInstance) buildVolumeGroupReplicationName(pvc *corev1.PersistentVolumeClaim) (string, error) {
storageID, ok := pvc.GetLabels()[ConsistencyGroupLabel]
if !ok {
v.log.Info("Missing storage class name for PVC %s/%s", pvc.GetNamespace(), pvc.GetName())
v.log.Info("Missing storageID for PVC %s/%s", pvc.GetNamespace(), pvc.GetName())

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

vgrName := storageID + "-vgr"
Expand Down Expand Up @@ -1347,9 +1347,9 @@ func (v *VRGInstance) createVR(vrNamespacedName types.NamespacedName,

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

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

volRep, err = v.createVolumeGroupReplication(storageID, vrNamespacedName, state)
Expand Down

0 comments on commit 2f4eee7

Please sign in to comment.