@@ -30,8 +30,8 @@ const (
3030)
3131
3232const (
33- KeyNode = "kubernetes.io/hostname"
34- customPathAnnotation = "rancher.io/customPath "
33+ KeyNode = "kubernetes.io/hostname"
34+ customFolderNameAnnotation = "rancher.io/customFolderName "
3535
3636 NodeDefaultNonListedNodes = "DEFAULT_PATH_FOR_NON_LISTED_NODES"
3737
@@ -46,6 +46,7 @@ const (
4646
4747const (
4848 defaultCmdTimeoutSeconds = 120
49+ defaultFolderExpression = "{{.pv.name}}-{{.namespace}}-{{.pvc.name}}"
4950)
5051
5152var (
@@ -78,6 +79,7 @@ type ConfigData struct {
7879 NodePathMap []* NodePathMapData `json:"nodePathMap,omitempty"`
7980 CmdTimeoutSeconds int `json:"cmdTimeoutSeconds,omitempty"`
8081 SharedFileSystemPath string `json:"sharedFileSystemPath,omitempty"`
82+ FolderExpression string `json:"folderExpression,omitempty"`
8183}
8284
8385type NodePathMap struct {
@@ -88,6 +90,7 @@ type Config struct {
8890 NodePathMap map [string ]* NodePathMap
8991 CmdTimeoutSeconds int
9092 SharedFileSystemPath string
93+ FolderExpression string
9194}
9295
9396func NewProvisioner (ctx context.Context , kubeClient * clientset.Clientset ,
@@ -259,17 +262,20 @@ func (p *LocalPathProvisioner) Provision(ctx context.Context, opts pvController.
259262 }
260263
261264 name := opts .PVName
262- folderName := strings .Join ([]string {name , opts .PVC .Namespace , opts .PVC .Name }, "_" )
263-
265+ folderName := ""
266+ if pvc .GetAnnotations ()[customFolderNameAnnotation ] != "" {
267+ folderName = pvc .GetAnnotations ()[customFolderNameAnnotation ]
268+ } else {
269+ folderName := strings .Replace (p .config .FolderExpression , "{{.namespace}}" , opts .PVC .Namespace , - 1 )
270+ folderName = strings .Replace (folderName , "{{.pvName}}" , name , - 1 )
271+ folderName = strings .Replace (folderName , "{{.pvcName}}" , opts .PVC .Name , - 1 )
272+ }
264273 path := filepath .Join (basePath , folderName )
265274 if nodeName == "" {
266275 logrus .Infof ("Creating volume %v at %v" , name , path )
267276 } else {
268277 logrus .Infof ("Creating volume %v at %v:%v" , name , nodeName , path )
269278 }
270- if pvc .GetAnnotations ()[customPathAnnotation ] != "" {
271- path = pvc .GetAnnotations ()[customPathAnnotation ]
272- }
273279 storage := pvc .Spec .Resources .Requests [v1 .ResourceName (v1 .ResourceStorage )]
274280 provisionCmd := []string {"/bin/sh" , "/script/setup" }
275281 if err := p .createHelperPod (ActionTypeCreate , provisionCmd , volumeOptions {
@@ -656,5 +662,10 @@ func canonicalizeConfig(data *ConfigData) (cfg *Config, err error) {
656662 } else {
657663 cfg .CmdTimeoutSeconds = defaultCmdTimeoutSeconds
658664 }
665+ if data .FolderExpression != "" {
666+ cfg .FolderExpression = data .FolderExpression
667+ } else {
668+ cfg .FolderExpression = defaultFolderExpression
669+ }
659670 return cfg , nil
660671}
0 commit comments