Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic reloading of the helper pod manifest by the provisioner #399

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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\"}]}"
Expand Down
2 changes: 2 additions & 0 deletions deploy/chart/local-path-provisioner/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions deploy/local-path-storage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: CONFIG_MOUNT_PATH
value: /etc/config/
volumes:
- name: config-volume
configMap:
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
26 changes: 26 additions & 0 deletions provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"os"

v1 "k8s.io/api/core/v1"
Expand All @@ -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
}
Expand Down