From 643e4dd3082e64e0feb3ca230893d237e8229344 Mon Sep 17 00:00:00 2001 From: Benamar Mekhissi Date: Thu, 12 Sep 2024 06:57:31 -0400 Subject: [PATCH] Ensure VGS name contains at most 63 characters Signed-off-by: Benamar Mekhissi --- internal/controller/cephfscg/cghandler.go | 4 ++-- internal/controller/cephfscg/volumegroupsourcehandler.go | 9 ++------- internal/controller/util/misc.go | 9 +++++++++ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/internal/controller/cephfscg/cghandler.go b/internal/controller/cephfscg/cghandler.go index bf3ef0e94..e778bd098 100644 --- a/internal/controller/cephfscg/cghandler.go +++ b/internal/controller/cephfscg/cghandler.go @@ -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, @@ -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, diff --git a/internal/controller/cephfscg/volumegroupsourcehandler.go b/internal/controller/cephfscg/volumegroupsourcehandler.go index a6d386148..940b92e2c 100644 --- a/internal/controller/cephfscg/volumegroupsourcehandler.go +++ b/internal/controller/cephfscg/volumegroupsourcehandler.go @@ -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, @@ -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 } @@ -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, diff --git a/internal/controller/util/misc.go b/internal/controller/util/misc.go index 8aca8315e..da2dab237 100644 --- a/internal/controller/util/misc.go +++ b/internal/controller/util/misc.go @@ -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 +}