diff --git a/pkg/volume/awsebs/attacher.go b/pkg/volume/awsebs/attacher.go index 2e560bc7a6a..aa729933910 100644 --- a/pkg/volume/awsebs/attacher.go +++ b/pkg/volume/awsebs/attacher.go @@ -211,23 +211,22 @@ func (attacher *awsElasticBlockStoreAttacher) MountDevice(spec *volume.Spec, dev mounter := attacher.host.GetMounter(awsElasticBlockStorePluginName) notMnt, err := mounter.IsLikelyNotMountPoint(deviceMountPath) if err != nil { - if os.IsNotExist(err) { - dir := deviceMountPath - if runtime.GOOS == "windows" { - // On Windows, FormatAndMount will mklink (create a symbolic link) at deviceMountPath later, so don't create a - // directory at deviceMountPath now. Otherwise mklink will error: "Cannot create a file when that file already exists". - // Instead, create the parent of deviceMountPath. For example when deviceMountPath is: - // C:\var\lib\kubelet\plugins\kubernetes.io\aws-ebs\mounts\aws\us-west-2b\vol-xxx - // create us-west-2b. FormatAndMount will make vol-xxx a symlink to the drive (e.g. D:\) - dir = filepath.Dir(deviceMountPath) - } - if err := os.MkdirAll(dir, 0750); err != nil { - return fmt.Errorf("making dir %s failed with %s", dir, err) - } - notMnt = true - } else { + if !os.IsNotExist(err) { return err } + dir := deviceMountPath + if runtime.GOOS == "windows" { + // On Windows, FormatAndMount will mklink (create a symbolic link) at deviceMountPath later, so don't create a + // directory at deviceMountPath now. Otherwise mklink will error: "Cannot create a file when that file already exists". + // Instead, create the parent of deviceMountPath. For example when deviceMountPath is: + // C:\var\lib\kubelet\plugins\kubernetes.io\aws-ebs\mounts\aws\us-west-2b\vol-xxx + // create us-west-2b. FormatAndMount will make vol-xxx a symlink to the drive (e.g. D:\) + dir = filepath.Dir(deviceMountPath) + } + if err := os.MkdirAll(dir, 0750); err != nil { + return fmt.Errorf("making dir %s failed with %s", dir, err) + } + notMnt = true } volumeSource, readOnly, err := getVolumeSource(spec) @@ -235,7 +234,7 @@ func (attacher *awsElasticBlockStoreAttacher) MountDevice(spec *volume.Spec, dev return err } - options := []string{} + var options []string if readOnly { options = append(options, "ro") } diff --git a/pkg/volume/awsebs/aws_ebs.go b/pkg/volume/awsebs/aws_ebs.go index c50e8e03635..0f135179e3d 100644 --- a/pkg/volume/awsebs/aws_ebs.go +++ b/pkg/volume/awsebs/aws_ebs.go @@ -534,10 +534,10 @@ func (c *awsElasticBlockStoreProvisioner) Provision(selectedNode *v1.Node, allow pv.Spec.AccessModes = c.plugin.GetAccessModes() } - requirements := make([]v1.NodeSelectorRequirement, 0) + requirements := make([]v1.NodeSelectorRequirement, 0, len(labels)) if len(labels) != 0 { if pv.Labels == nil { - pv.Labels = make(map[string]string) + pv.Labels = make(map[string]string, len(labels)) } for k, v := range labels { pv.Labels[k] = v diff --git a/pkg/volume/awsebs/aws_util.go b/pkg/volume/awsebs/aws_util.go index d7804f1f581..61429e325e3 100644 --- a/pkg/volume/awsebs/aws_util.go +++ b/pkg/volume/awsebs/aws_util.go @@ -218,7 +218,7 @@ func verifyDevicePath(devicePaths []string) (string, error) { // This is more interesting on GCE (where we are able to identify volumes under /dev/disk-by-id) // Here it is mostly about applying the partition path func getDiskByIDPaths(volumeID aws.KubernetesVolumeID, partition string, devicePath string) []string { - devicePaths := []string{} + var devicePaths []string if devicePath != "" { devicePaths = append(devicePaths, devicePath) }