From 007787405d4acc800f4e67a91d4df2a7c1c99b0d Mon Sep 17 00:00:00 2001 From: Lorenzo Faresin Date: Mon, 16 Aug 2021 15:44:42 +0200 Subject: [PATCH] fixed https://github.com/kubernetes-sigs/nfs-subdir-external-provisioner/pull/121#discussion_r682744736 and https://github.com/kubernetes-sigs/nfs-subdir-external-provisioner/pull/121#discussion_r682746429 --- .../provisioner.go | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/cmd/nfs-subdir-external-provisioner/provisioner.go b/cmd/nfs-subdir-external-provisioner/provisioner.go index aa7d31d9..f5225d84 100644 --- a/cmd/nfs-subdir-external-provisioner/provisioner.go +++ b/cmd/nfs-subdir-external-provisioner/provisioner.go @@ -112,26 +112,30 @@ func (p *nfsProvisioner) Provision(ctx context.Context, options controller.Provi createMode := os.FileMode(0777) annotationCreateMode, exists := metadata.annotations["nfs.io/createMode"] - if exists { - annotationCreateModeUInt, _ := strconv.ParseUint(annotationCreateMode, 8, 32) - createMode = os.FileMode(annotationCreateModeUInt) - } + if exists { + annotationCreateModeUInt, err := strconv.ParseUint(annotationCreateMode, 8, 32) + if err != nil { + glog.Warningf("nfs.io/createMode %s not parsable, skipped", annotationCreateMode) + } else { + createMode = os.FileMode(annotationCreateModeUInt) + } + } - createUID := "0" - annotationCreateUID, exists := metadata.annotations["nfs.io/createUID"] - if exists { - createUID = annotationCreateUID - } - createGID := "0" - annotationCreateGID, exists := metadata.annotations["nfs.io/createGID"] - if exists { - createGID = annotationCreateGID - } + createUID := "0" + annotationCreateUID, exists := metadata.annotations["nfs.io/createUID"] + if exists { + createUID = annotationCreateUID + } + createGID := "0" + annotationCreateGID, exists := metadata.annotations["nfs.io/createGID"] + if exists { + createGID = annotationCreateGID + } - uid, _ := strconv.Atoi(createUID) - gid, _ := strconv.Atoi(createGID) + uid, _ := strconv.Atoi(createUID) + gid, _ := strconv.Atoi(createGID) - glog.V(4).Infof("creating path %s with %#o mode, %d UID, %d GID", fullPath, createMode, uid, gid) + glog.V(4).Infof("creating path %s with %#o mode, %d UID, %d GID", fullPath, createMode, uid, gid) if err := os.MkdirAll(fullPath, createMode); err != nil { return nil, controller.ProvisioningFinished, errors.New("unable to create directory to provision new pv: " + err.Error()) }