Skip to content
Snippets Groups Projects
Commit 154a153c authored by Sheng Yang's avatar Sheng Yang
Browse files

Add keyword DEFAULT_PATH_FOR_NON_LISTED_NODES

In order to setup default config.
parent d913e48f
No related branches found
No related tags found
No related merge requests found
kind: ConfigMap
apiVersion: v1
metadata:
name: local-path-config
namespace: default
data:
config.json: |-
{
"nodePathMap":[
{
"node":"DEFAULT_PATH_FOR_NON_LISTED_NODES",
"paths":["/opt/local-path-provisioner"]
}
]
}
...@@ -8,12 +8,12 @@ data: ...@@ -8,12 +8,12 @@ data:
{ {
"nodePathMap":[ "nodePathMap":[
{ {
"node":"yasker-lp-dev1", "node":"DEFAULT_PATH_FOR_NON_LISTED_NODES",
"paths":["/opt", "/data1"] "paths":["/opt"]
}, },
{ {
"node":"yasker-lp-dev2", "node":"yasker-lp-dev1",
"paths":["/opt"] "paths":["/opt", "/data1"]
}, },
{ {
"node":"yasker-lp-dev3", "node":"yasker-lp-dev3",
......
...@@ -55,7 +55,7 @@ spec: ...@@ -55,7 +55,7 @@ spec:
serviceAccountName: local-path-provisioner-service-account serviceAccountName: local-path-provisioner-service-account
containers: containers:
- name: local-path-provisioner - name: local-path-provisioner
image: yasker/local-path-provisioner:63df7c1 image: yasker/local-path-provisioner:e862e16
imagePullPolicy: Always imagePullPolicy: Always
command: command:
- local-path-provisioner - local-path-provisioner
......
...@@ -19,6 +19,8 @@ import ( ...@@ -19,6 +19,8 @@ import (
const ( const (
KeyNode = "kubernetes.io/hostname" KeyNode = "kubernetes.io/hostname"
NodeDefaultNonListedNodes = "DEFAULT_PATH_FOR_NON_LISTED_NODES"
) )
var ( var (
...@@ -50,7 +52,11 @@ type Config struct { ...@@ -50,7 +52,11 @@ type Config struct {
func (c *Config) getRandomPathOnNode(node string) (string, error) { func (c *Config) getRandomPathOnNode(node string) (string, error) {
npMap := c.NodePathMap[node] npMap := c.NodePathMap[node]
if npMap == nil { if npMap == nil {
return "", fmt.Errorf("config doesn't contain node %v", node) npMap = c.NodePathMap[NodeDefaultNonListedNodes]
if npMap == nil {
return "", fmt.Errorf("config doesn't contain node %v, and no %v available", node, NodeDefaultNonListedNodes)
}
logrus.Debugf("config doesn't contain node %v, use %v instead", node, NodeDefaultNonListedNodes)
} }
paths := npMap.Paths paths := npMap.Paths
if len(paths) == 0 { if len(paths) == 0 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment