From b8e203661b0b2d3be35342be8869de2125782ebc Mon Sep 17 00:00:00 2001 From: zhoumiao Date: Wed, 31 Mar 2021 21:23:20 +0800 Subject: [PATCH] prevent mounting of root directory If storageClass enable pathPattern like: `pathPattern: "${.PVC.annotations.nfs.io/storage-path}"` but pvc without annotation would make empty `customPath` and create a pv with nfs root path. --- cmd/nfs-subdir-external-provisioner/provisioner.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/nfs-subdir-external-provisioner/provisioner.go b/cmd/nfs-subdir-external-provisioner/provisioner.go index 4f2ec6a9..2d357c11 100644 --- a/cmd/nfs-subdir-external-provisioner/provisioner.go +++ b/cmd/nfs-subdir-external-provisioner/provisioner.go @@ -104,8 +104,10 @@ func (p *nfsProvisioner) Provision(ctx context.Context, options controller.Provi pathPattern, exists := options.StorageClass.Parameters["pathPattern"] if exists { customPath := metadata.stringParser(pathPattern) - path = filepath.Join(p.path, customPath) - fullPath = filepath.Join(mountPath, customPath) + if customPath != "" { + path = filepath.Join(p.path, customPath) + fullPath = filepath.Join(mountPath, customPath) + } } glog.V(4).Infof("creating path %s", fullPath)