Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: Add controller sharding capability based on label selector #525

Merged
merged 1 commit into from
Mar 28, 2023

Conversation

stefanprodan
Copy link
Member

@stefanprodan stefanprodan commented Mar 28, 2023

Add --watch-label-selector flag to controller runtime. When specified the controller's reconcilers will only watch for changes of those resources with matching labels.

To restrict the controller watch, the selector exposed by this package must be wired in each controller's cache manager.

This enables horizontal scaling of Flux controllers, where each controller can be deployed multiple times with a unique label selector which is used as the sharding key.

For example, to shard the reconciliation of HelmReleases in a cluster, user will deploy two extra helm-controller instances:

  • Deployment/helm-controller with --watch-label-selector=sharding.fluxcd.io/shard notin (shard1, shard2)
  • Deployment/helm-controller-1 with --watch-label-selector=sharding.fluxcd.io/shard=shard1
  • Deployment/helm-controller-2 with --watch-label-selector=sharding.fluxcd.io/shard=shard2

By labeling HelmReleases with sharding.fluxcd.io/shard, users can spread the load between helm-controller-1 and helm-controller-2 by setting the label value to shard1 or shard2. HelmReleases which don't have the sharding.fluxcd.io/shard label, will be reconcile by the helm-controller default instance.

Sharding source-controller works the same but users will have to create a matching Kubernetes Service for each SC deployment, then set the Service name in storage address flag. Example:

  • Deployment+Service source-controller-1 with:
--storage-adv-addr=source-controller-1.$(RUNTIME_NAMESPACE).svc.cluster.local.
--watch-label-selector=sharding.fluxcd.io/shard=shard1
  • Deployment+Service source-controller-2 with:
--storage-adv-addr=source-controller-2.$(RUNTIME_NAMESPACE).svc.cluster.local.
--watch-label-selector=sharding.fluxcd.io/shard=shard12

@stefanprodan stefanprodan added enhancement New feature or request area/runtime Controller runtime related issues and pull requests labels Mar 28, 2023
@stefanprodan stefanprodan force-pushed the watch-label-selector branch 2 times, most recently from 0e79601 to b04bc0c Compare March 28, 2023 12:49
@stefanprodan stefanprodan changed the title runtime: Add reconciler sharding capability based on label selector runtime: Add controller sharding capability based on label selector Mar 28, 2023
runtime/controller/watch.go Outdated Show resolved Hide resolved
@stefanprodan stefanprodan force-pushed the watch-label-selector branch from b04bc0c to 978f119 Compare March 28, 2023 13:56
@stefanprodan
Copy link
Member Author

I've tested this with source-controller and passing the label selector to the cache manager works flawlessly 🎉

runtime/predicates/match_labels.go Outdated Show resolved Hide resolved
runtime/controller/watch.go Outdated Show resolved Hide resolved
@stefanprodan stefanprodan force-pushed the watch-label-selector branch from 978f119 to f6e8e6c Compare March 28, 2023 17:04
Add `--watch-label-selector` flag to runtime. When specified the reconcilers will only watch for changes of those resources with matching labels. This enables horizontal scaling of Flux controller, where each controller can be deployed multiple times with a unique label selector which is used as the sharding key.

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
@stefanprodan stefanprodan force-pushed the watch-label-selector branch from f6e8e6c to 909e778 Compare March 28, 2023 17:28
Copy link
Member

@hiddeco hiddeco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks for following through with the nits 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/runtime Controller runtime related issues and pull requests enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants