-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for restart controller on ConfigMap change
This change adds support for restarting the main controller when a config change has been detected on disk from change in the ConfigMap. The implementation adds a ConfigWatcher go routine which will check the if the config has been updated by loading from disk and comparing with what is currently used. If change is detected, it will signal to the controller to restart with the updated config. This change will enhance the deployment and rollout story for the provisioner as updates to the ConfigMap will be picked up automatically by the provisioner without needing to explicitly restart the pod itself. Signed-off By: Yibo Zhuang <yibzhuang@gmail.com>
- Loading branch information
1 parent
1cc3374
commit d16939b
Showing
4 changed files
with
117 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package config_watcher | ||
|
||
import ( | ||
"reflect" | ||
"time" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/klog/v2" | ||
|
||
"sigs.k8s.io/sig-storage-local-static-provisioner/pkg/common" | ||
) | ||
|
||
type ConfigWatcher struct { | ||
configPath string | ||
resyncPeriod time.Duration | ||
lastAppliedConfig common.ProvisionerConfiguration | ||
} | ||
|
||
func NewConfigWatcher(configPath string, resyncPeriod time.Duration, config common.ProvisionerConfiguration) *ConfigWatcher { | ||
return &ConfigWatcher{ | ||
configPath: configPath, | ||
resyncPeriod: resyncPeriod, | ||
lastAppliedConfig: config, | ||
} | ||
} | ||
|
||
func (cw *ConfigWatcher) Run(restartController chan<- common.ProvisionerConfiguration) { | ||
for { | ||
select { | ||
case <-time.After(cw.resyncPeriod): | ||
provisionerConfig := common.ProvisionerConfiguration{ | ||
StorageClassConfig: make(map[string]common.MountConfig), | ||
MinResyncPeriod: metav1.Duration{Duration: 5 * time.Minute}, | ||
} | ||
if err := common.LoadProvisionerConfigs(cw.configPath, &provisionerConfig); err != nil { | ||
klog.Fatalf("Error parsing Provisioner's configuration: %#v. Exiting...\n", err) | ||
} | ||
|
||
if !reflect.DeepEqual(cw.lastAppliedConfig, provisionerConfig) { | ||
klog.Infof("Loaded and detected updated configuration: %+v", provisionerConfig) | ||
klog.Infof("Signalling controller to restart to pick up updated configuration...") | ||
|
||
restartController <- provisionerConfig | ||
cw.lastAppliedConfig = provisionerConfig | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters