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:
Jan Safranek
2016-02-12 09:46:59 +01:00
parent b5c12d10b8
commit 1d0b1c227b
12 changed files with 86 additions and 18 deletions

View File

@@ -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
}