Skip to content

Commit

Permalink
Parameterize config watcher loop speed
Browse files Browse the repository at this point in the history
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 <connor.kuehl@suse.com>
  • Loading branch information
Connor Kuehl committed Mar 22, 2024
1 parent 0fd3fa7 commit d2d1bb2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cmd/thin_entrypoint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type Options struct {
AdditionalBinDir string
ForceCNIVersion bool
SkipTLSVerify bool
WatchTimer time.Duration
}

const (
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions docs/how-to-use.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<duration>`

--multus-config-watch-timer=5m

0 comments on commit d2d1bb2

Please sign in to comment.