From 9eb912e62fd7a8f9fd7d6347b412e5b80ae98ab3 Mon Sep 17 00:00:00 2001 From: pospispa Date: Thu, 8 Dec 2016 13:35:56 +0100 Subject: [PATCH] Admin Can Specify in Which AWS Availability Zone(s) a PV Shall Be Created An admin wants to specify in which AWS 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. --- .../persistent-volume-provisioning/README.md | 5 ++-- pkg/cloudprovider/providers/aws/aws.go | 30 ++++++++++++++----- pkg/volume/aws_ebs/aws_util.go | 10 +++++++ 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/examples/persistent-volume-provisioning/README.md b/examples/persistent-volume-provisioning/README.md index 6ba72f0c9bd..124c4f088e1 100644 --- a/examples/persistent-volume-provisioning/README.md +++ b/examples/persistent-volume-provisioning/README.md @@ -25,12 +25,13 @@ metadata: provisioner: kubernetes.io/aws-ebs parameters: type: io1 - zone: us-east-1d + zones: us-east-1d, us-east-1c iopsPerGB: "10" ``` * `type`: `io1`, `gp2`, `sc1`, `st1`. See AWS docs for details. Default: `gp2`. -* `zone`: AWS zone. If not specified, a random zone from those where Kubernetes cluster has a node is chosen. +* `zone`: AWS 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 AWS 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. * `iopsPerGB`: only for `io1` volumes. I/O operations per second per GiB. AWS volume plugin multiplies this with size of requested volume to compute IOPS of the volume and caps it at 20 000 IOPS (maximum supported by AWS, see AWS docs). * `encrypted`: denotes whether the EBS volume should be encrypted or not. Valid values are `true` or `false`. * `kmsKeyId`: optional. The full Amazon Resource Name of the key to use when encrypting the volume. If none is supplied but `encrypted` is true, a key is generated by AWS. See AWS docs for valid ARN value. diff --git a/pkg/cloudprovider/providers/aws/aws.go b/pkg/cloudprovider/providers/aws/aws.go index 8d42884e146..e3dfade42f0 100644 --- a/pkg/cloudprovider/providers/aws/aws.go +++ b/pkg/cloudprovider/providers/aws/aws.go @@ -287,11 +287,14 @@ const ( // VolumeOptions specifies capacity and tags for a volume. type VolumeOptions struct { - CapacityGB int - Tags map[string]string - PVCName string - VolumeType string - AvailabilityZone string + CapacityGB int + Tags map[string]string + PVCName string + VolumeType string + ZonePresent bool + ZonesPresent bool + AvailabilityZone string + AvailabilityZones string // IOPSPerGB x CapacityGB will give total IOPS of the volume to create. // Calculated total IOPS will be capped at MaxTotalIOPS. IOPSPerGB int @@ -1675,10 +1678,23 @@ func (c *Cloud) CreateDisk(volumeOptions *VolumeOptions) (KubernetesVolumeID, er return "", fmt.Errorf("error querying for all zones: %v", err) } - createAZ := volumeOptions.AvailabilityZone - if createAZ == "" { + var createAZ string + if !volumeOptions.ZonePresent && !volumeOptions.ZonesPresent { createAZ = volume.ChooseZoneForVolume(allZones, volumeOptions.PVCName) } + if !volumeOptions.ZonePresent && volumeOptions.ZonesPresent { + if adminSetOfZones, err := volume.ZonesToSet(volumeOptions.AvailabilityZones); err != nil { + return "", err + } else { + createAZ = volume.ChooseZoneForVolume(adminSetOfZones, volumeOptions.PVCName) + } + } + if volumeOptions.ZonePresent && !volumeOptions.ZonesPresent { + if err := volume.ValidateZone(volumeOptions.AvailabilityZone); err != nil { + return "", err + } + createAZ = volumeOptions.AvailabilityZone + } var createType string var iops int64 diff --git a/pkg/volume/aws_ebs/aws_util.go b/pkg/volume/aws_ebs/aws_util.go index 72fac0635bf..bfad040c84a 100644 --- a/pkg/volume/aws_ebs/aws_util.go +++ b/pkg/volume/aws_ebs/aws_util.go @@ -91,12 +91,18 @@ func (util *AWSDiskUtil) CreateVolume(c *awsElasticBlockStoreProvisioner) (aws.K } // Apply Parameters (case-insensitive). We leave validation of // the values to the cloud provider. + volumeOptions.ZonePresent = false + volumeOptions.ZonesPresent = false for k, v := range c.options.Parameters { switch strings.ToLower(k) { case "type": volumeOptions.VolumeType = v case "zone": + volumeOptions.ZonePresent = true volumeOptions.AvailabilityZone = v + case "zones": + volumeOptions.ZonesPresent = true + volumeOptions.AvailabilityZones = v case "iopspergb": volumeOptions.IOPSPerGB, err = strconv.Atoi(v) if err != nil { @@ -114,6 +120,10 @@ func (util *AWSDiskUtil) CreateVolume(c *awsElasticBlockStoreProvisioner) (aws.K } } + if volumeOptions.ZonePresent && volumeOptions.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 if c.options.PVC.Spec.Selector != nil { return "", 0, nil, fmt.Errorf("claim.Spec.Selector is not supported for dynamic provisioning on AWS")