Skip to content
Snippets Groups Projects
Commit 3a7f4378 authored by nicktming's avatar nicktming Committed by Sheng Yang
Browse files

fix configmap name hardcode

parent fc79f07d
No related branches found
No related tags found
No related merge requests found
...@@ -71,8 +71,9 @@ default values. ...@@ -71,8 +71,9 @@ default values.
| `nodeSelector` | Node labels for Local Path Provisioner pod assignment | `{}` | | `nodeSelector` | Node labels for Local Path Provisioner pod assignment | `{}` |
| `tolerations` | Node taints to tolerate | `[]` | | `tolerations` | Node taints to tolerate | `[]` |
| `affinity` | Pod affinity | `{}` | | `affinity` | Pod affinity | `{}` |
| `setup` | Configuration of script to execute setup operations on each node | #!/bin/sh<br>path=$1<br>mkdir -m 0777 -p ${path} | | `configmap.setup` | Configuration of script to execute setup operations on each node | #!/bin/sh<br>path=$1<br>mkdir -m 0777 -p ${path} |
| `teardown` | Configuration of script to execute teardown operations on each node | #!/bin/sh<br>path=$1<br>rm -rf ${path} | | `configmap.teardown` | Configuration of script to execute teardown operations on each node | #!/bin/sh<br>path=$1<br>rm -rf ${path} |
| `configmap.name` | configmap name | `local-path-config` |
Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example, Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example,
......
apiVersion: v1 apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
name: {{ include "local-path-provisioner.fullname" . }} name: {{ .Values.configmap.name }}
labels: labels:
{{ include "local-path-provisioner.labels" . | indent 4 }} {{ include "local-path-provisioner.labels" . | indent 4 }}
data: data:
...@@ -12,6 +12,6 @@ data: ...@@ -12,6 +12,6 @@ data:
"nodePathMap": {{ .Values.nodePathMap | toPrettyJson | nindent 8 }} "nodePathMap": {{ .Values.nodePathMap | toPrettyJson | nindent 8 }}
} }
setup: |- setup: |-
{{ .Values.setup | nindent 4 }} {{ .Values.configmap.setup | nindent 4 }}
teardown: |- teardown: |-
{{ .Values.teardown | nindent 4 }} {{ .Values.configmap.teardown | nindent 4 }}
...@@ -46,7 +46,7 @@ spec: ...@@ -46,7 +46,7 @@ spec:
volumes: volumes:
- name: config-volume - name: config-volume
configMap: configMap:
name: {{ include "local-path-provisioner.fullname" . }} name: {{ .Values.configmap.name }}
{{- with .Values.nodeSelector }} {{- with .Values.nodeSelector }}
nodeSelector: nodeSelector:
{{- toYaml . | nindent 8 }} {{- toYaml . | nindent 8 }}
......
...@@ -79,6 +79,10 @@ tolerations: [] ...@@ -79,6 +79,10 @@ tolerations: []
affinity: {} affinity: {}
configmap:
# specify the config map name
name: local-path-config
# specify the custom script for setup and teardown
setup: |- setup: |-
#!/bin/sh #!/bin/sh
path=$1 path=$1
...@@ -88,3 +92,4 @@ teardown: |- ...@@ -88,3 +92,4 @@ teardown: |-
#!/bin/sh #!/bin/sh
path=$1 path=$1
rm -rf ${path} rm -rf ${path}
...@@ -35,6 +35,7 @@ var ( ...@@ -35,6 +35,7 @@ var (
DefaultKubeConfigFilePath = ".kube/config" DefaultKubeConfigFilePath = ".kube/config"
DefaultConfigFileKey = "config.json" DefaultConfigFileKey = "config.json"
DefaultConfigMapName = "local-path-config" DefaultConfigMapName = "local-path-config"
FlagConfigMapName = "configmap-name"
) )
func cmdNotFound(c *cli.Context, command string) { func cmdNotFound(c *cli.Context, command string) {
...@@ -87,6 +88,11 @@ func StartCmd() cli.Command { ...@@ -87,6 +88,11 @@ func StartCmd() cli.Command {
Usage: "Paths to a kubeconfig. Only required when it is out-of-cluster.", Usage: "Paths to a kubeconfig. Only required when it is out-of-cluster.",
Value: "", Value: "",
}, },
cli.StringFlag{
Name: FlagConfigMapName,
Usage: "Required. Specify configmap name.",
Value: DefaultConfigMapName,
},
}, },
Action: func(c *cli.Context) { Action: func(c *cli.Context) {
if err := startDaemon(c); err != nil { if err := startDaemon(c); err != nil {
...@@ -118,8 +124,8 @@ func loadConfig(kubeconfig string) (*rest.Config, error) { ...@@ -118,8 +124,8 @@ func loadConfig(kubeconfig string) (*rest.Config, error) {
return clientcmd.BuildConfigFromFlags("", kubeconfig) return clientcmd.BuildConfigFromFlags("", kubeconfig)
} }
func findConfigFileFromConfigMap(kubeClient clientset.Interface, namespace string) (string, error) { func findConfigFileFromConfigMap(kubeClient clientset.Interface, namespace, configMapName string) (string, error) {
cm, err := kubeClient.CoreV1().ConfigMaps(namespace).Get(DefaultConfigMapName, metav1.GetOptions{}) cm, err := kubeClient.CoreV1().ConfigMaps(namespace).Get(configMapName, metav1.GetOptions{})
if err != nil { if err != nil {
return "", err return "", err
} }
...@@ -157,11 +163,15 @@ func startDaemon(c *cli.Context) error { ...@@ -157,11 +163,15 @@ func startDaemon(c *cli.Context) error {
if namespace == "" { if namespace == "" {
return fmt.Errorf("invalid empty flag %v", FlagNamespace) return fmt.Errorf("invalid empty flag %v", FlagNamespace)
} }
configMapName := c.String(FlagConfigMapName)
if configMapName == "" {
return fmt.Errorf("invalid empty flag %v", FlagConfigMapName)
}
configFile := c.String(FlagConfigFile) configFile := c.String(FlagConfigFile)
if configFile == "" { if configFile == "" {
configFile, err = findConfigFileFromConfigMap(kubeClient, namespace) configFile, err = findConfigFileFromConfigMap(kubeClient, namespace, configMapName)
if err != nil { if err != nil {
return fmt.Errorf("invalid empty flag %v and it also does not exist at ConfigMap %v/%v", FlagConfigFile, namespace, DefaultConfigMapName) return fmt.Errorf("invalid empty flag %v and it also does not exist at ConfigMap %v/%v with err: %v", FlagConfigFile, namespace, configMapName, err)
} }
} }
helperImage := c.String(FlagHelperImage) helperImage := c.String(FlagHelperImage)
...@@ -169,7 +179,7 @@ func startDaemon(c *cli.Context) error { ...@@ -169,7 +179,7 @@ func startDaemon(c *cli.Context) error {
return fmt.Errorf("invalid empty flag %v", FlagHelperImage) return fmt.Errorf("invalid empty flag %v", FlagHelperImage)
} }
provisioner, err := NewProvisioner(stopCh, kubeClient, configFile, namespace, helperImage) provisioner, err := NewProvisioner(stopCh, kubeClient, configFile, namespace, helperImage, configMapName)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -47,6 +47,7 @@ type LocalPathProvisioner struct { ...@@ -47,6 +47,7 @@ type LocalPathProvisioner struct {
config *Config config *Config
configData *ConfigData configData *ConfigData
configFile string configFile string
configMapName string
configMutex *sync.RWMutex configMutex *sync.RWMutex
} }
...@@ -67,7 +68,7 @@ type Config struct { ...@@ -67,7 +68,7 @@ type Config struct {
NodePathMap map[string]*NodePathMap NodePathMap map[string]*NodePathMap
} }
func NewProvisioner(stopCh chan struct{}, kubeClient *clientset.Clientset, configFile, namespace, helperImage string) (*LocalPathProvisioner, error) { func NewProvisioner(stopCh chan struct{}, kubeClient *clientset.Clientset, configFile, namespace, helperImage, configMapName string) (*LocalPathProvisioner, error) {
p := &LocalPathProvisioner{ p := &LocalPathProvisioner{
stopCh: stopCh, stopCh: stopCh,
...@@ -79,6 +80,7 @@ func NewProvisioner(stopCh chan struct{}, kubeClient *clientset.Clientset, confi ...@@ -79,6 +80,7 @@ func NewProvisioner(stopCh chan struct{}, kubeClient *clientset.Clientset, confi
config: nil, config: nil,
configFile: configFile, configFile: configFile,
configData: nil, configData: nil,
configMapName: configMapName,
configMutex: &sync.RWMutex{}, configMutex: &sync.RWMutex{},
} }
if err := p.refreshConfig(); err != nil { if err := p.refreshConfig(); err != nil {
...@@ -368,7 +370,7 @@ func (p *LocalPathProvisioner) createHelperPod(action ActionType, cmdsForPath [] ...@@ -368,7 +370,7 @@ func (p *LocalPathProvisioner) createHelperPod(action ActionType, cmdsForPath []
VolumeSource: v1.VolumeSource{ VolumeSource: v1.VolumeSource{
ConfigMap: &v1.ConfigMapVolumeSource{ ConfigMap: &v1.ConfigMapVolumeSource{
LocalObjectReference: v1.LocalObjectReference{ LocalObjectReference: v1.LocalObjectReference{
Name: "local-path-config", Name: p.configMapName,
}, },
Items: []v1.KeyToPath{ Items: []v1.KeyToPath{
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment