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

core: revert increase storage deviceset name limit to 50 #14362

Merged
merged 2 commits into from
Jun 21, 2024

Conversation

subhamkrai
Copy link
Contributor

Checklist:

  • Commit Message Formatting: Commit titles and messages follow guidelines in the developer guide.
  • Reviewed the developer guide on Submitting a Pull Request
  • Pending release notes updated with breaking and/or notable changes for the next minor release.
  • Documentation has been updated, if necessary.
  • Unit tests have been added, if necessary.
  • Integration tests have been added, if necessary.

This reverts commit 1dcc99e.

Signed-off-by: subhamkrai <srai@redhat.com>
This reverts commit 6f5cc9b.

Signed-off-by: subhamkrai <srai@redhat.com>
Comment on lines -301 to -304
pvcID := fmt.Sprintf("%s-%s-%d", deviceSetName, cleanName, setIndex)
if len(pvcID) > 62 {
return "", fmt.Errorf("the OSD PVC name requested is %q (length %d) is too long and must be less than 63 characters, shorten either the storageClassDeviceSet name or the storage class name", pvcID, len(pvcID))
}
Copy link
Member

Choose a reason for hiding this comment

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

From my read of the code, this pvcID is used in the generateName field of a PersistentVolumeClaim object. If that's the case, isn't this check still valuable to users? We don't want to allow users to input names that are so long that Rook's install breaks.

Copy link
Member

@BlaineEXE BlaineEXE Jun 21, 2024

Choose a reason for hiding this comment

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

After chat with Subham, I understand that the bigger overall issue that is that even if the deviceSetName is limited to 50 chars, the pvcTemplateName can still be up to 62/63 chars. It would be better to fix this by hashing some portion of the name if it exceeds 62 chars.

With just the 50-char limit, the case where the deviceSetName is 51 chars but the pvcTemplateName is only 3 chars should still be valid (less than 63 chars), but the commit being reverted would block that if users have this upgrade condition.

With deviceSetName limited to 50 chars, and pvcTemplateName to 63, this could be up to 113 chars long just with those 2. Then 2 dashes (-), and an index that in theory could be 4 chars long in a ridiculous cluster. That's 119 chars.

To really fix this issue, we have to reduce these 119 chars to 62. If necessary, we can stop using the PVC ID (name) as a static value and instead use labels to Get() the right PVC later using labels like pvcTemplateName=X, deviceSetName=Y, deviceSetIndex=Z.

Let's take this revert, and then make a follow up issue and PR to reduce the naming. A version of this function's hash strategy might be appropriate:

// PathToVolumeName converts a path to a valid volume name
func PathToVolumeName(path string) string {
// kubernetes volume names must match this regex: [a-z0-9]([-a-z0-9]*[a-z0-9])?
sanitized := make([]rune, 0, len(path))
for _, c := range path {
switch {
case '0' <= c && c <= '9':
fallthrough
case 'a' <= c && c <= 'z':
sanitized = append(sanitized, c)
continue
case 'A' <= c && c <= 'Z':
// convert upper to lower case
sanitized = append(sanitized, c+('a'-'A'))
default:
// convert any non alphanum char to a hyphen
sanitized = append(sanitized, '-')
}
}
volumeName := string(sanitized)
// trim any leading/trailing hyphens
volumeName = strings.TrimPrefix(volumeName, "-")
volumeName = strings.TrimSuffix(volumeName, "-")
if len(volumeName) > validation.DNS1123LabelMaxLength {
// keep an equal sample of the original name from both the beginning and from the end,
// and add some characters from a hash of the full name to help prevent name collisions.
// Make room for 3 hyphens in the middle (~ellipsis) and 1 hyphen to separate the hash.
hashLength := 8
sampleLength := int((validation.DNS1123LabelMaxLength - hashLength - 3 - 1) / 2)
first := volumeName[0:sampleLength]
last := volumeName[len(volumeName)-sampleLength:]
hash := Hash(volumeName)
volumeName = fmt.Sprintf("%s---%s-%s", first, last, hash[0:hashLength])
}
return volumeName
}

@BlaineEXE BlaineEXE merged commit d1e4f96 into rook:master Jun 21, 2024
53 checks passed
mergify bot added a commit that referenced this pull request Jun 21, 2024
core: revert increase storage deviceset name limit to 50 (backport #14362)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants