-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Conversation
1895f02
to
9af6cbe
Compare
9af6cbe
to
e8aeb0d
Compare
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)) | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
rook/pkg/operator/k8sutil/volume.go
Lines 35 to 74 in 80a96f8
// 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 | |
} |
core: revert increase storage deviceset name limit to 50 (backport #14362)
Checklist: