From e1a5e8537a64799731380ec1bceac7937ef092e9 Mon Sep 17 00:00:00 2001 From: demoManito <1430482733@qq.com> Date: Mon, 5 Sep 2022 18:53:52 +0800 Subject: [PATCH] optimize ifelse --- pkg/volume/awsebs/attacher.go | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/pkg/volume/awsebs/attacher.go b/pkg/volume/awsebs/attacher.go index 2e560bc7a6a..31b66d89e9e 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)