mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 06:27:05 +00:00
Admin Can Specify in Which GCE Availability Zone(s) a PV Shall Be Created
An admin wants to specify in which GCE availability zone(s) users may create persistent volumes using dynamic provisioning. That's why the admin can now configure in StorageClass object a comma separated list of zones. Dynamically created PVs for PVCs that use the StorageClass are created in one of the configured zones.
This commit is contained in:
parent
dd17d620d7
commit
d73c0d649d
@ -45,11 +45,12 @@ metadata:
|
|||||||
provisioner: kubernetes.io/gce-pd
|
provisioner: kubernetes.io/gce-pd
|
||||||
parameters:
|
parameters:
|
||||||
type: pd-standard
|
type: pd-standard
|
||||||
zone: us-central1-a
|
zones: us-central1-a, us-central1-b
|
||||||
```
|
```
|
||||||
|
|
||||||
* `type`: `pd-standard` or `pd-ssd`. Default: `pd-ssd`
|
* `type`: `pd-standard` or `pd-ssd`. Default: `pd-ssd`
|
||||||
* `zone`: GCE zone. If not specified, a random zone in the same region as controller-manager will be chosen.
|
* `zone`: GCE zone. If neither zone nor zones is specified, volumes are generally round-robin-ed across all active zones where Kubernetes cluster has a node. Note: zone and zones parameters must not be used at the same time.
|
||||||
|
* `zones`: a comma separated list of GCE zone(s). If neither zone nor zones is specified, volumes are generally round-robin-ed across all active zones where Kubernetes cluster has a node. Note: zone and zones parameters must not be used at the same time.
|
||||||
|
|
||||||
#### vSphere
|
#### vSphere
|
||||||
|
|
||||||
|
@ -86,33 +86,55 @@ func (gceutil *GCEDiskUtil) CreateVolume(c *gcePersistentDiskProvisioner) (strin
|
|||||||
// Apply Parameters (case-insensitive). We leave validation of
|
// Apply Parameters (case-insensitive). We leave validation of
|
||||||
// the values to the cloud provider.
|
// the values to the cloud provider.
|
||||||
diskType := ""
|
diskType := ""
|
||||||
zone := ""
|
configuredZone := ""
|
||||||
|
configuredZones := ""
|
||||||
|
zonePresent := false
|
||||||
|
zonesPresent := false
|
||||||
for k, v := range c.options.Parameters {
|
for k, v := range c.options.Parameters {
|
||||||
switch strings.ToLower(k) {
|
switch strings.ToLower(k) {
|
||||||
case "type":
|
case "type":
|
||||||
diskType = v
|
diskType = v
|
||||||
case "zone":
|
case "zone":
|
||||||
zone = v
|
zonePresent = true
|
||||||
|
configuredZone = v
|
||||||
|
case "zones":
|
||||||
|
zonesPresent = true
|
||||||
|
configuredZones = v
|
||||||
default:
|
default:
|
||||||
return "", 0, nil, fmt.Errorf("invalid option %q for volume plugin %s", k, c.plugin.GetPluginName())
|
return "", 0, nil, fmt.Errorf("invalid option %q for volume plugin %s", k, c.plugin.GetPluginName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if zonePresent && zonesPresent {
|
||||||
|
return "", 0, nil, fmt.Errorf("both zone and zones StorageClass parameters must not be used at the same time")
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: implement PVC.Selector parsing
|
// TODO: implement PVC.Selector parsing
|
||||||
if c.options.PVC.Spec.Selector != nil {
|
if c.options.PVC.Spec.Selector != nil {
|
||||||
return "", 0, nil, fmt.Errorf("claim.Spec.Selector is not supported for dynamic provisioning on GCE")
|
return "", 0, nil, fmt.Errorf("claim.Spec.Selector is not supported for dynamic provisioning on GCE")
|
||||||
}
|
}
|
||||||
|
|
||||||
if zone == "" {
|
var zones sets.String
|
||||||
// No zone specified, choose one randomly in the same region as the
|
if !zonePresent && !zonesPresent {
|
||||||
// node is running.
|
zones, err = cloud.GetAllZones()
|
||||||
zones, err := cloud.GetAllZones()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(2).Infof("error getting zone information from GCE: %v", err)
|
glog.V(2).Infof("error getting zone information from GCE: %v", err)
|
||||||
return "", 0, nil, err
|
return "", 0, nil, err
|
||||||
}
|
}
|
||||||
zone = volume.ChooseZoneForVolume(zones, c.options.PVC.Name)
|
|
||||||
}
|
}
|
||||||
|
if !zonePresent && zonesPresent {
|
||||||
|
if zones, err = volume.ZonesToSet(configuredZones); err != nil {
|
||||||
|
return "", 0, nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if zonePresent && !zonesPresent {
|
||||||
|
if err := volume.ValidateZone(configuredZone); err != nil {
|
||||||
|
return "", 0, nil, err
|
||||||
|
}
|
||||||
|
zones = make(sets.String)
|
||||||
|
zones.Insert(configuredZone)
|
||||||
|
}
|
||||||
|
zone := volume.ChooseZoneForVolume(zones, c.options.PVC.Name)
|
||||||
|
|
||||||
err = cloud.CreateDisk(name, diskType, zone, int64(requestGB), *c.options.CloudTags)
|
err = cloud.CreateDisk(name, diskType, zone, int64(requestGB), *c.options.CloudTags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user