-
Notifications
You must be signed in to change notification settings - Fork 38.6k
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
Add PV.Name into names of generated GCE/AWS/OpenStack volumes. #20900
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,3 +148,20 @@ func CalculateTimeoutForVolume(minimumTimeout, timeoutIncrement int, pv *api.Per | |
func RoundUpSize(volumeSizeBytes int64, allocationUnitBytes int64) int64 { | ||
return (volumeSizeBytes + allocationUnitBytes - 1) / allocationUnitBytes | ||
} | ||
|
||
// GenerateVolumeName returns a PV name with clusterName prefix. | ||
// The function should be used to generate a name of GCE PD or Cinder volume. | ||
// It basically adds "<clusterName>-dynamic-" before the PV name, | ||
// making sure the resulting string fits given length and cuts "dynamic" | ||
// if not. | ||
func GenerateVolumeName(clusterName, pvName string, maxLength int) string { | ||
prefix := clusterName + "-dynamic" | ||
pvLen := len(pvName) | ||
|
||
// cut the "<clusterName>-dynamic" to fit full pvName into maxLength | ||
// +1 for the '-' dash | ||
if pvLen+1+len(prefix) > maxLength { | ||
prefix = prefix[:maxLength-pvLen-1] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. Currently, it cannot happen - GCE has limit of 63 characters and pv.Name there has 12 characters. All the other clouds have 255 characters limit. Of course, it's not robust, but cutting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-ideal, but it should be ok, because it shouldn't happen. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Maybe add a comment explaining this, in case someone encounters it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment added, I hope it's not too confusing. |
||
} | ||
return prefix + "-" + pvName | ||
} |
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.
Where is
pv.Name
set?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.
In Provisioners of individual volume plugins, currently as
PV.GenerateName = "pv-cinder-"
. (pv-aws-, pv-gce-)E.g. https://github.com/kubernetes/kubernetes/blob/master/pkg/volume/cinder/cinder.go#L434
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.
I don't understand how the name is guaranteed to be unique then. For example, won't this make the volume name
someCluster-dynamic-pv-cinder-
?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.
A comment would help.
It is guaranteed unique because we first persist the PV with, for example,
GenerateName: "pv-aws-", objectMeta.GenerateName
We then want to use that PV name as the resource name to tie them together.
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.
Got it, thanks Mark! Yes, a comment would help.
So one more question: why set the final name in such a roundabout fashion? i.e.
NewPersistentVolumeTemplate()
will set it topv-aws-UID
thenCreateVolume(...)
will set it toclusterName-dynamic-pv-aws-UID
. Why not just set it to the final name directly inNewPersistentVolumeTemplate()
?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.
What kind of name is guaranteed to be unique in the cluster besides a new UUID? objMeta.GenerateName allows a human-readable prefix with a suffix that makes a unique name.
Also, once the PV is persisted, we get more than a name. We get a marker (with a future Provisioning Condition) that makes the provisioning process async. We use annotations today but that is better expressed as a Condition (can put meaningful status on the CLI).
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.
Makes sense, so we want/expect the name of the PV in the provider to be different then (contain more info then) the name of the API PV object.
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.
I added a note describing where pv.Name comes from.
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.
@saad-ali strictly speaking, we are assigning PV.Name from Kube to GCEPD.Name in the provider. The name field exists on both, so we think it would be beneficial for them to match.