From 0b2b14d5a6e79c6be429a7022a37150c4a5fe5b7 Mon Sep 17 00:00:00 2001 From: Connor Kuehl Date: Tue, 13 Feb 2024 16:17:19 -0600 Subject: [PATCH] Parameterize config watcher loop speed This loop spins really quickly otherwise. This will allow cluster operators to choose how quickly the thin plugin reconciles the kubeconfig in the event of a stale service account token. BUG: https://github.com/k8snetworkplumbingwg/multus-cni/pull/1232 Signed-off-by: Connor Kuehl Signed-off-by: Chris Chiu --- cmd/thin_entrypoint/main.go | 7 ++++++- docs/how-to-use.md | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cmd/thin_entrypoint/main.go b/cmd/thin_entrypoint/main.go index ecab83181..6498d1844 100644 --- a/cmd/thin_entrypoint/main.go +++ b/cmd/thin_entrypoint/main.go @@ -59,6 +59,7 @@ type Options struct { ForceCNIVersion bool SkipTLSVerify bool SkipMultusConfWatch bool + WatchTimer time.Duration } const ( @@ -93,6 +94,7 @@ func (o *Options) addFlags() { fs.StringVar(&o.AdditionalBinDir, "additional-bin-dir", "", "adds binDir option to configuration (used only with --multus-conf-file=auto)") fs.BoolVar(&o.SkipTLSVerify, "skip-tls-verify", false, "skip TLS verify") fs.BoolVar(&o.ForceCNIVersion, "force-cni-version", false, "force cni version to '--cni-version' (only for e2e-kind testing)") + fs.DurationVar(&o.WatchTimer, "multus-config-watch-timer", 1*time.Second, "how long to wait before reconciling multus config") fs.MarkHidden("force-cni-version") fs.MarkHidden("skip-tls-verify") } @@ -618,13 +620,16 @@ func main() { defer cleanupMultusConf(&opt) } + watcher := time.NewTicker(opt.WatchTimer) + defer watcher.Stop() + watchChanges := opt.CleanupConfigOnExit && opt.MultusConfFile == "auto" && !opt.SkipMultusConfWatch if watchChanges { fmt.Printf("Entering watch loop...\n") masterConfigExists := true outer: - for range time.Tick(1 * time.Second) { + for range watcher.C { select { case <-ctx.Done(): // signal received break from loop diff --git a/docs/how-to-use.md b/docs/how-to-use.md index b4cdfc426..78ff3f5a0 100644 --- a/docs/how-to-use.md +++ b/docs/how-to-use.md @@ -627,6 +627,10 @@ master CNI configuration and kubeconfig. when such change detected, the script w --skip-config-watch +The poll interval of the config changes watcher is configurable with `--multus-config-watch-timer=`. Please refer to the [time.Duration](https://pkg.go.dev/time#Duration) to configure the time interval. The following example watches the config change every 5 minutes. + + --multus-config-watch-timer=5m + Additionally when using CRIO, you may wish to have the CNI config file that's used as the source for `--multus-conf-file=auto` renamed. This boolean option when set to true automatically renames the file with a `.old` suffix to the original filename. --rename-conf-file=true