From d2d1bb2d632b096c898f154d54a37623cbced598 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. Signed-off-by: Connor Kuehl --- cmd/thin_entrypoint/main.go | 8 ++++++-- docs/how-to-use.md | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cmd/thin_entrypoint/main.go b/cmd/thin_entrypoint/main.go index 5f32a87de..3e74cacb1 100644 --- a/cmd/thin_entrypoint/main.go +++ b/cmd/thin_entrypoint/main.go @@ -57,6 +57,7 @@ type Options struct { AdditionalBinDir string ForceCNIVersion bool SkipTLSVerify bool + WatchTimer time.Duration } const ( @@ -90,6 +91,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") } @@ -594,9 +596,12 @@ func main() { fmt.Printf("multus config file is created.\n") } + watcher := time.NewTicker(opt.WatchTimer) + defer watcher.Stop() + if opt.CleanupConfigOnExit && opt.MultusConfFile == "auto" { fmt.Printf("Entering watch loop...\n") - for { + for range watcher.C { // Check kubeconfig and update if different (i.e. service account updated) caHash, saTokenHash, err = opt.createKubeConfig(caHash, saTokenHash) if err != nil { @@ -625,7 +630,6 @@ func main() { fmt.Fprintf(os.Stderr, "failed to create multus config: %v\n", err) return } - time.Sleep(1 * time.Second) } } else { // sleep infinitely diff --git a/docs/how-to-use.md b/docs/how-to-use.md index 566275c4b..7fe8e79cb 100644 --- a/docs/how-to-use.md +++ b/docs/how-to-use.md @@ -634,3 +634,7 @@ Sometimes, you may wish to not have the entrypoint copy the binary file onto the If you wish to have auto configuration use the `readinessindicatorfile` in the configuration, you can use the `--readiness-indicator-file` to express which file should be used as the readiness indicator. --readiness-indicator-file=/path/to/file + +The thin plugin will reconcile its kubeconfig and config file every second when using `--cleanup-config-on-exit` and `--multus-conf-file=auto`. The config poll interval is configurable with `--multus-config-watch-timer=` + + --multus-config-watch-timer=5m