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 12, 2024
1 parent a8615c1 commit a3756dd
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions internal/controller/cephfscg/volumegroupsourcehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,32 @@ func NewVolumeGroupSourceHandler(

return &volumeGroupSourceHandler{
Client: client,
VolumeGroupSnapshotName: fmt.Sprintf(VolumeGroupSnapshotNameFormat, rgs.Name),
VolumeGroupSnapshotName: BuildVGSName(rgs.Name),
VolumeGroupSnapshotNamespace: rgs.Namespace,
VolumeGroupSnapshotClassName: rgs.Spec.VolumeGroupSnapshotClassName,
VolumeGroupLabel: rgs.Spec.VolumeGroupSnapshotSource,
VolsyncKeySecretName: volsync.GetVolSyncPSKSecretNameFromVRGName(vrgName),
DefaultCephFSCSIDriverName: defaultCephFSCSIDriverName,
Logger: logger.WithName("VolumeGroupSourceHandler").
WithValues("VolumeGroupSnapshotName", fmt.Sprintf(VolumeGroupSnapshotNameFormat, rgs.Name)).
WithValues("VolumeGroupSnapshotName", BuildVGSName(rgs.Name)).
WithValues("VolumeGroupSnapshotNamespace", rgs.Namespace),
}
}

func BuildVGSName(name string) string {
const maxLen = 63

vgsName := fmt.Sprintf(VolumeGroupSnapshotNameFormat, name)

// If the name is already less than the max, then return the already built name
if len(vgsName) <= maxLen {
return vgsName
}

// Otherwise, trim it up to maxLen
return vgsName[:maxLen]
}

// CreateOrUpdateVolumeGroupSnapshot create or update a VolumeGroupSnapshot
func (h *volumeGroupSourceHandler) CreateOrUpdateVolumeGroupSnapshot(
ctx context.Context, owner metav1.Object,
Expand Down Expand Up @@ -136,7 +150,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 @@ -502,11 +516,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

0 comments on commit a3756dd

Please sign in to comment.