Skip to content
Snippets Groups Projects
Commit f14a6b3b authored by Sameer Mene's avatar Sameer Mene Committed by Derek Su
Browse files

check the path is present in nodePathMap

parent bbc042b3
No related branches found
No related tags found
No related merge requests found
......@@ -251,7 +251,7 @@ A few things to note; the annotation for the `StorageClass` will apply to all vo
### Storage classes
If more than one `paths` are specified in the `nodePathMap` the path is chosen randomly. To make the provisioner choose a specific path, use a `storageClass` defined with a parameter called `path`.
If more than one `paths` are specified in the `nodePathMap` the path is chosen randomly. To make the provisioner choose a specific path, use a `storageClass` defined with a parameter called `nodePath`. Note that this path should be defined in the `nodePathMap`
```
apiVersion: storage.k8s.io/v1
......@@ -260,7 +260,7 @@ metadata:
name: ssd-local-path
provisioner: cluster.local/local-path-provisioner
parameters:
path: /data/ssd
nodePath: /data/ssd
volumeBindingMode: WaitForFirstConsumer
reclaimPolicy: Delete
```
......
......@@ -166,7 +166,7 @@ func (p *LocalPathProvisioner) watchAndRefreshConfig() {
}()
}
func (p *LocalPathProvisioner) getRandomPathOnNode(node string) (string, error) {
func (p *LocalPathProvisioner) getPathOnNode(node string, requestedPath string) (string, error) {
p.configMutex.RLock()
defer p.configMutex.RUnlock()
......@@ -196,6 +196,14 @@ func (p *LocalPathProvisioner) getRandomPathOnNode(node string) (string, error)
if len(paths) == 0 {
return "", fmt.Errorf("no local path available on node %v", node)
}
// if a particular path was requested by storage class
if requestedPath != "" {
if _, ok := paths[requestedPath]; !ok {
return "", fmt.Errorf("config doesn't contain path %v on node %v", requestedPath, node)
}
return requestedPath, nil
}
// if no particular path was requested, choose a random one
path := ""
for path = range paths {
break
......@@ -254,13 +262,13 @@ func (p *LocalPathProvisioner) Provision(ctx context.Context, opts pvController.
// This clause works only with sharedFS
nodeName = node.Name
}
var basePath string
basePath, err = p.getRandomPathOnNode(nodeName)
var requestedPath string
if storageClass.Parameters != nil {
if _, ok := storageClass.Parameters["path"]; ok {
basePath = storageClass.Parameters["path"]
if _, ok := storageClass.Parameters["nodePath"]; ok {
requestedPath = storageClass.Parameters["nodePath"]
}
}
basePath, err := p.getPathOnNode(nodeName, requestedPath)
if err != nil {
return nil, pvController.ProvisioningFinished, err
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment