Skip to content

Commit

Permalink
Watch for helper pod manifest updates
Browse files Browse the repository at this point in the history
  • Loading branch information
js185692 authored and derekbit committed May 26, 2024
1 parent 64050fb commit d7d9de5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
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

0 comments on commit d7d9de5

Please sign in to comment.