From d670a5a8947e08a05e82603f5b8d4067c10c0606 Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Tue, 23 Jul 2019 15:15:45 +0200 Subject: [PATCH] Rename `--registry-poll-interval` The flag `--registry-poll-interval` used to control how often fluxd would scan image repos for new images, and consequently update any automated workloads. This has not been true for some time: it now just controls the second part, while images are scanned on a different schedule. The name is a persistent source of confusion. Therefore: introduce a new flag `--automation-interval`, and make `--registry-poll-interval` a synonym so as not to break things suddenly, and deprecate the latter so as to encourage people to change it. --- cmd/fluxd/main.go | 19 +++++++++++++----- daemon/daemon.go | 2 +- daemon/images.go | 4 ++-- daemon/loop.go | 42 +++++++++++++++++++-------------------- site/daemon.md | 3 ++- site/faq.md | 2 +- test/flux-deploy-all.yaml | 2 +- 7 files changed, 42 insertions(+), 32 deletions(-) diff --git a/cmd/fluxd/main.go b/cmd/fluxd/main.go index 25e07c2b0..15b0aef4f 100644 --- a/cmd/fluxd/main.go +++ b/cmd/fluxd/main.go @@ -140,6 +140,7 @@ func main() { memcachedTimeout = fs.Duration("memcached-timeout", time.Second, "maximum time to wait before giving up on memcached requests.") memcachedService = fs.String("memcached-service", "memcached", "SRV service used to discover memcache servers.") + automationInterval = fs.Duration("automation-interval", 5*time.Minute, "period at which to check for image updates for automated workloads") registryPollInterval = fs.Duration("registry-poll-interval", 5*time.Minute, "period at which to check for updated images") registryRPS = fs.Float64("registry-rps", 50, "maximum registry requests per second per host") registryBurst = fs.Int("registry-burst", defaultRemoteConnections, "maximum number of warmer connections to remote and memcache") @@ -182,6 +183,7 @@ func main() { ) fs.MarkDeprecated("registry-cache-expiry", "no longer used; cache entries are expired adaptively according to how often they change") fs.MarkDeprecated("k8s-namespace-whitelist", "changed to --k8s-allow-namespace, use that instead") + fs.MarkDeprecated("registry-poll-interval", "changed to --automation-interval, use that instead") var kubeConfig *string { @@ -245,6 +247,13 @@ func main() { k8sruntime.ErrorHandlers = []func(error){logErrorUnlessAccessRelated} // Argument validation + // Maintain backwards compatibility with the --registry-poll-interval + // flag, but only if the --automation-interval is not set to a custom + // (non default) value. + if fs.Changed("registry-poll-interval") && !fs.Changed("automation-interval") { + *automationInterval = *registryPollInterval + } + // Sort out values for the git tag and notes ref. There are // running deployments that assume the defaults as given, so don't // mess with those unless explicitly told. @@ -595,10 +604,10 @@ func main() { Logger: log.With(logger, "component", "daemon"), ManifestGenerationEnabled: *manifestGeneration, LoopVars: &daemon.LoopVars{ - SyncInterval: *syncInterval, - RegistryPollInterval: *registryPollInterval, - GitTimeout: *gitTimeout, - GitVerifySignatures: *gitVerifySignatures, + SyncInterval: *syncInterval, + AutomationInterval: *automationInterval, + GitTimeout: *gitTimeout, + GitVerifySignatures: *gitVerifySignatures, }, } @@ -634,7 +643,7 @@ func main() { shutdownWg.Add(1) go daemon.Loop(shutdown, shutdownWg, log.With(logger, "component", "sync-loop")) - cacheWarmer.Notify = daemon.AskForImagePoll + cacheWarmer.Notify = daemon.AskForAutomatedWorkloadImageUpdates cacheWarmer.Priority = daemon.ImageRefresh cacheWarmer.Trace = *registryTrace shutdownWg.Add(1) diff --git a/daemon/daemon.go b/daemon/daemon.go index e7189ea2a..1aa437219 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -463,7 +463,7 @@ func (d *Daemon) updatePolicies(spec update.Spec, updates resource.PolicyUpdates return result, err } if anythingAutomated { - d.AskForImagePoll() + d.AskForAutomatedWorkloadImageUpdates() } var err error diff --git a/daemon/images.go b/daemon/images.go index b046703d2..951968adb 100644 --- a/daemon/images.go +++ b/daemon/images.go @@ -13,8 +13,8 @@ import ( "github.com/weaveworks/flux/update" ) -func (d *Daemon) pollForNewImages(logger log.Logger) { - logger.Log("msg", "polling images") +func (d *Daemon) pollForNewAutomatedWorkloadImages(logger log.Logger) { + logger.Log("msg", "polling for new images for automated workloads") ctx := context.Background() diff --git a/daemon/loop.go b/daemon/loop.go index c9106ad98..7d5fc4a4f 100644 --- a/daemon/loop.go +++ b/daemon/loop.go @@ -12,20 +12,20 @@ import ( ) type LoopVars struct { - SyncInterval time.Duration - RegistryPollInterval time.Duration - GitTimeout time.Duration - GitVerifySignatures bool - - initOnce sync.Once - syncSoon chan struct{} - pollImagesSoon chan struct{} + SyncInterval time.Duration + AutomationInterval time.Duration + GitTimeout time.Duration + GitVerifySignatures bool + + initOnce sync.Once + syncSoon chan struct{} + automatedWorkloadsSoon chan struct{} } func (loop *LoopVars) ensureInit() { loop.initOnce.Do(func() { loop.syncSoon = make(chan struct{}, 1) - loop.pollImagesSoon = make(chan struct{}, 1) + loop.automatedWorkloadsSoon = make(chan struct{}, 1) }) } @@ -38,7 +38,7 @@ func (d *Daemon) Loop(stop chan struct{}, wg *sync.WaitGroup, logger log.Logger) syncTimer := time.NewTimer(d.SyncInterval) // Similarly checking to see if any controllers have new images // available. - imagePollTimer := time.NewTimer(d.RegistryPollInterval) + automatedWorkloadTimer := time.NewTimer(d.AutomationInterval) // Keep track of current, verified (if signature verification is // enabled), HEAD, so we can know when to treat a repo @@ -49,26 +49,26 @@ func (d *Daemon) Loop(stop chan struct{}, wg *sync.WaitGroup, logger log.Logger) // In-memory sync tag state lastKnownSyncTag := &lastKnownSyncTag{logger: logger, syncTag: d.GitConfig.SyncTag} - // Ask for a sync, and to poll images, straight away + // Ask for a sync, and to check d.AskForSync() - d.AskForImagePoll() + d.AskForAutomatedWorkloadImageUpdates() for { select { case <-stop: logger.Log("stopping", "true") return - case <-d.pollImagesSoon: - if !imagePollTimer.Stop() { + case <-d.automatedWorkloadsSoon: + if !automatedWorkloadTimer.Stop() { select { - case <-imagePollTimer.C: + case <-automatedWorkloadTimer.C: default: } } - d.pollForNewImages(logger) - imagePollTimer.Reset(d.RegistryPollInterval) - case <-imagePollTimer.C: - d.AskForImagePoll() + d.pollForNewAutomatedWorkloadImages(logger) + automatedWorkloadTimer.Reset(d.AutomationInterval) + case <-automatedWorkloadTimer.C: + d.AskForAutomatedWorkloadImageUpdates() case <-d.syncSoon: if !syncTimer.Stop() { select { @@ -150,10 +150,10 @@ func (d *LoopVars) AskForSync() { } // Ask for an image poll, or if there's one waiting, let that happen. -func (d *LoopVars) AskForImagePoll() { +func (d *LoopVars) AskForAutomatedWorkloadImageUpdates() { d.ensureInit() select { - case d.pollImagesSoon <- struct{}{}: + case d.automatedWorkloadsSoon <- struct{}{}: default: } } diff --git a/site/daemon.md b/site/daemon.md index 64007edf0..d823ca582 100644 --- a/site/daemon.md +++ b/site/daemon.md @@ -68,12 +68,13 @@ fluxd requires setup and offers customization though a multitude of flags. | **syncing:** control over how config is applied to the cluster | --sync-interval | `5m` | apply the git config to the cluster at least this often. New commits may provoke more frequent syncs | --sync-garbage-collection | `false` | experimental: when set, fluxd will delete resources that it created, but are no longer present in git (see [garbage collection](./garbagecollection.md)) +| **automation (of image updates):** +| --automation-interval | `5m` | period at which to check for image updates for automated workloads | **registry cache:** (none of these need overriding, usually) | --memcached-hostname | `memcached` | hostname for memcached service to use for caching image metadata | --memcached-timeout | `1s` | maximum time to wait before giving up on memcached requests | --memcached-service | `memcached` | SRV service used to discover memcache servers | --registry-cache-expiry | `1h` | Duration to keep cached registry tag info. Must be < 1 month. -| --registry-poll-interval | `5m` | period at which to poll registry for new images | --registry-rps | `200` | maximum registry requests per second per host | --registry-burst | `125` | maximum number of warmer connections to remote and memcache | --registry-insecure-host | [] | registry hosts to use HTTP for (instead of HTTPS) diff --git a/site/faq.md b/site/faq.md index 573fc6292..0f8c4e159 100644 --- a/site/faq.md +++ b/site/faq.md @@ -196,7 +196,7 @@ See also by default. The latter default is quite conservative, so you can try lowering it -(it's set with the flag `--registry-poll-interval`). +(it's set with the flag `--automation-interval`). Please don't _increase_ the rate limiting numbers (`--registry-rps` and `--registry-burst`) -- it's possible to get blacklisted by image diff --git a/test/flux-deploy-all.yaml b/test/flux-deploy-all.yaml index 8af30e1ef..0ac072d25 100644 --- a/test/flux-deploy-all.yaml +++ b/test/flux-deploy-all.yaml @@ -94,5 +94,5 @@ spec: - --git-url=ssh://docker@MINIKUBE_IP:/home/docker/flux.git - --git-branch=master # Tune up to make tests run quicker - - --registry-poll-interval=60s + - --automation-interval=60s - --git-poll-interval=60s