mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 23:47:50 +00:00
Add PV.Name into names of generated GCE/AWS/OSP volumes.
Volume names have now format <cluster-name>-dynamic-<pv-name>. pv-name is guaranteed to be unique in Kubernetes cluster, adding <cluster-name> ensures we don't conflict with any running cluster in the cloud project (kube-controller-manager --cluster-name=XXX). 'kubernetes' is the default cluster name.
This commit is contained in:
@@ -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]
|
||||
}
|
||||
return prefix + "-" + pvName
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user