From 2c6fb0e528b437514d06df1bd125c2f615b6529e Mon Sep 17 00:00:00 2001 From: Jeremy Scott Date: Thu, 25 Apr 2024 13:47:29 +0100 Subject: [PATCH 1/3] Watch for helper pod manifest updates --- deploy/local-path-storage.yaml | 2 ++ main.go | 1 + provisioner.go | 26 ++++++++++++++++++++++++++ util.go | 4 ++-- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/deploy/local-path-storage.yaml b/deploy/local-path-storage.yaml index c6527a746..cfae8b58c 100644 --- a/deploy/local-path-storage.yaml +++ b/deploy/local-path-storage.yaml @@ -104,6 +104,8 @@ spec: valueFrom: fieldRef: fieldPath: metadata.namespace + - name: CONFIG_MOUNT_PATH + value: "/etc/config/" volumes: - name: config-volume configMap: diff --git a/main.go b/main.go index 728cf0df1..cddd4097c 100644 --- a/main.go +++ b/main.go @@ -48,6 +48,7 @@ var ( DefaultProvisioningRetryCount = pvController.DefaultFailedProvisionThreshold FlagDeletionRetryCount = "deletion-retry-count" DefaultDeletionRetryCount = pvController.DefaultFailedDeleteThreshold + EnvConfigMountPath = "CONFIG_MOUNT_PATH" ) func cmdNotFound(c *cli.Context, command string) { diff --git a/provisioner.go b/provisioner.go index 797df703c..e12485325 100644 --- a/provisioner.go +++ b/provisioner.go @@ -169,6 +169,29 @@ func (p *LocalPathProvisioner) refreshConfig() error { return err } +func (p *LocalPathProvisioner) refreshHelperPod() error { + p.configMutex.Lock() + defer p.configMutex.Unlock() + + helperPodFile, envExists := os.LookupEnv(EnvConfigMountPath) + if !envExists { + return nil + } + + helperPodFile = filepath.Join(helperPodFile, DefaultHelperPodFile) + newHelperPod, err := loadFile(helperPodFile) + if err != nil { + return err + } + + p.helperPod, err = loadHelperPodFile(newHelperPod) + if err != nil { + return err + } + + return nil +} + func (p *LocalPathProvisioner) watchAndRefreshConfig() { go func() { ticker := time.NewTicker(ConfigFileCheckInterval) @@ -179,6 +202,9 @@ func (p *LocalPathProvisioner) watchAndRefreshConfig() { if err := p.refreshConfig(); err != nil { logrus.Errorf("failed to load the new config file: %v", err) } + if err := p.refreshHelperPod(); err != nil { + logrus.Errorf("failed to load the new helper pod manifest: %v", err) + } case <-p.ctx.Done(): logrus.Infof("stop watching config file") return diff --git a/util.go b/util.go index 0a0b5415d..d1301c922 100644 --- a/util.go +++ b/util.go @@ -3,7 +3,7 @@ package main import ( "encoding/json" "fmt" - "io/ioutil" + "io" "os" v1 "k8s.io/api/core/v1" @@ -16,7 +16,7 @@ func loadFile(filepath string) (string, error) { return "", err } defer f.Close() - helperPodYaml, err := ioutil.ReadAll(f) + helperPodYaml, err := io.ReadAll(f) if err != nil { return "", err } From b1a4cd23868178a2d776f189955acaa658b166a7 Mon Sep 17 00:00:00 2001 From: Jeremy Scott Date: Thu, 9 May 2024 13:40:39 +0100 Subject: [PATCH 2/3] Add config mount path env to deployments in deploy directory --- deploy/chart/local-path-provisioner/templates/deployment.yaml | 2 ++ deploy/local-path-storage.yaml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/deploy/chart/local-path-provisioner/templates/deployment.yaml b/deploy/chart/local-path-provisioner/templates/deployment.yaml index 37021a922..9c6833068 100644 --- a/deploy/chart/local-path-provisioner/templates/deployment.yaml +++ b/deploy/chart/local-path-provisioner/templates/deployment.yaml @@ -72,6 +72,8 @@ spec: env: - name: POD_NAMESPACE value: {{ .Release.Namespace }} + - name: CONFIG_MOUNT_PATH + value: /etc/config/ resources: {{- toYaml .Values.resources | nindent 12 }} volumes: diff --git a/deploy/local-path-storage.yaml b/deploy/local-path-storage.yaml index cfae8b58c..f109aa14f 100644 --- a/deploy/local-path-storage.yaml +++ b/deploy/local-path-storage.yaml @@ -105,7 +105,7 @@ spec: fieldRef: fieldPath: metadata.namespace - name: CONFIG_MOUNT_PATH - value: "/etc/config/" + value: /etc/config/ volumes: - name: config-volume configMap: From 37a6be2b4c7518e9f89398dfd7b916ea9650253d Mon Sep 17 00:00:00 2001 From: Jeremy Scott Date: Thu, 9 May 2024 14:51:27 +0100 Subject: [PATCH 3/3] Update readme with provisioner reloading helper pod manifest --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 04a580b8d..7ccae2ad5 100644 --- a/README.md +++ b/README.md @@ -236,7 +236,12 @@ The scripts receive their input as environment variables: #### Reloading -The provisioner supports automatic configuration reloading. Users can change the configuration using `kubectl apply` or `kubectl edit` with config map `local-path-config`. There is a delay between when the user updates the config map and the provisioner picking it up. +The provisioner supports automatic configuration reloading. Users can change the configuration using `kubectl apply` or `kubectl edit` with config map `local-path-config`. There is a delay between when the user updates the config map and the provisioner picking it up. In order for this to occur for updates made to the helper pod manifest, the following environment variable must be added to the provisioner container. If not, then the manifest used for the helper pod will be the same as what was in the config map when the provisioner was last restarted/deployed. + +```yaml +- name: CONFIG_MOUNT_PATH + value: /etc/config/ +``` When the provisioner detects the configuration changes, it will try to load the new configuration. Users can observe it in the log >time="2018-10-03T05:56:13Z" level=debug msg="Applied config: {\"nodePathMap\":[{\"node\":\"DEFAULT_PATH_FOR_NON_LISTED_NODES\",\"paths\":[\"/opt/local-path-provisioner\"]},{\"node\":\"yasker-lp-dev1\",\"paths\":[\"/opt\",\"/data1\"]},{\"node\":\"yasker-lp-dev3\"}]}"