Skip to content

Commit

Permalink
Ensure VGS name contains at most 63 characters
Browse files Browse the repository at this point in the history
Signed-off-by: Benamar Mekhissi <[email protected]>
  • Loading branch information
Benamar Mekhissi committed Sep 14, 2024
1 parent f51b389 commit 643e4dd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions internal/controller/cephfscg/cghandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (c *cgHandler) CreateOrUpdateReplicationGroupDestination(
replicationGroupDestinationName, replicationGroupDestinationNamespace string,
rdSpecsInGroup []ramendrv1alpha1.VolSyncReplicationDestinationSpec,
) (*ramendrv1alpha1.ReplicationGroupDestination, error) {
replicationGroupDestinationName += c.cgName
replicationGroupDestinationName = util.TrimToK8sResourceNameLength(replicationGroupDestinationName + c.cgName)

log := c.logger.WithName("CreateOrUpdateReplicationGroupDestination").
WithValues("ReplicationGroupDestinationName", replicationGroupDestinationName,
Expand Down Expand Up @@ -144,7 +144,7 @@ func (c *cgHandler) CreateOrUpdateReplicationGroupSource(
replicationGroupSourceName, replicationGroupSourceNamespace string,
runFinalSync bool,
) (*ramendrv1alpha1.ReplicationGroupSource, bool, error) {
replicationGroupSourceName += c.cgName
replicationGroupSourceName = util.TrimToK8sResourceNameLength(replicationGroupSourceName + c.cgName)

log := c.logger.WithName("CreateOrUpdateReplicationGroupSource").
WithValues("ReplicationGroupSourceName", replicationGroupSourceName,
Expand Down
9 changes: 2 additions & 7 deletions internal/controller/cephfscg/volumegroupsourcehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func NewVolumeGroupSourceHandler(
) VolumeGroupSourceHandler {
vrgName := rgs.GetLabels()[volsync.VRGOwnerNameLabel]

vgsName := BuildVGSName(rgs.Name)
vgsName := util.TrimToK8sResourceNameLength(fmt.Sprintf(VolumeGroupSnapshotNameFormat, rgs.Name))

return &volumeGroupSourceHandler{
Client: client,
Expand Down Expand Up @@ -138,7 +138,7 @@ func (h *volumeGroupSourceHandler) CreateOrUpdateVolumeGroupSnapshot(
return err
}

logger.Info("VolumeGroupSnapshot successfully be created or updated", "operation", op)
logger.Info("VolumeGroupSnapshot successfully created or updated", "operation", op)

return nil
}
Expand Down Expand Up @@ -504,11 +504,6 @@ func (h *volumeGroupSourceHandler) CheckReplicationSourceForRestoredPVCsComplete
return true, nil
}

var GetPVCFromVolumeSnapshot func(
ctx context.Context, k8sClient client.Client, vsName string,
vsNamespace string, vgs *vgsv1alphfa1.VolumeGroupSnapshot,
) (*corev1.PersistentVolumeClaim, error)

func GetPVCfromStorageHandle(
ctx context.Context,
k8sClient client.Client,
Expand Down
9 changes: 9 additions & 0 deletions internal/controller/util/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,12 @@ func IsCGEnabled(annotations map[string]string) bool {

return annotations[IsCGEnabledAnnotation] == "true"
}

func TrimToK8sResourceNameLength(name string) string {
const maxLength = 63
if len(name) > maxLength {
return name[:maxLength]
}

return name
}

0 comments on commit 643e4dd

Please sign in to comment.