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 <[email protected]>
  • Loading branch information
Connor Kuehl committed Feb 26, 2024
1 parent 5f0b4cd commit 9d5b8e4
Showing 1 changed file with 6 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.Minute, "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

0 comments on commit 9d5b8e4

Please sign in to comment.