Skip to content

feat: add WATCH_LABEL_SELECTOR env var to filter reconciled objects by label#7816

Open
rossanorbr wants to merge 2 commits into
kedacore:mainfrom
rossanorbr:feat/watch-label-selector
Open

feat: add WATCH_LABEL_SELECTOR env var to filter reconciled objects by label#7816
rossanorbr wants to merge 2 commits into
kedacore:mainfrom
rossanorbr:feat/watch-label-selector

Conversation

@rossanorbr

@rossanorbr rossanorbr commented Jun 2, 2026

Copy link
Copy Markdown

Adds a WATCH_LABEL_SELECTOR environment variable that scopes which ScaledObjects, ScaledJobs, TriggerAuthentications and ClusterTriggerAuthentications an operator instance reconciles, based on labels on those resources.

Mirrors the existing WATCH_NAMESPACE env var, but filters by label instead of by namespace. Empty or unset means watch everything (current behaviour, backward compatible). When set, accepts the standard Kubernetes label selector syntax:

  • equality: environment=production
  • set notation: tier in (gold,silver), !canary

Filtering happens at two layers:

  • cache.ByObject{Label: selector} so non-matching objects never enter the informer cache.
  • predicate.LabelSelectorPredicate on the four controllers so events for non-matching objects are dropped before reconciliation.

The HPA cache is filtered too. KEDA copies the ScaledObject labels onto the HPA, and the operator uses Owns(HPA) to enqueue reconciles, so the HPA cache has to follow the same filter to keep partitioning correct.

Checklist

  • When introducing a new scaler, I agree with the scaling governance policy
  • I have verified that my change is according to the deprecations & breaking changes policy
  • Tests have been added (if applicable)
  • Ensure make generate-scalers-schema has been run to update any outdated generated files
  • Changelog has been updated and is aligned with our changelog requirements, only when the change impacts end users
  • A PR is opened to update our Helm chart (repo) (if applicable, ie. when deployment manifests are modified)
  • A PR is opened to update the documentation on (repo) (if applicable)
  • Commits are signed with Developer Certificate of Origin (DCO - learn more)

Fixes #7738

Relates to kedacore/charts#864
Relates to kedacore/keda-docs#1785

@rossanorbr rossanorbr requested a review from a team as a code owner June 2, 2026 08:23
@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown

Thank you for your contribution! 🙏

Please understand that we will do our best to review your PR and give you feedback as soon as possible, but please bear with us if it takes a little longer as expected.

While you are waiting, make sure to:

  • Add an entry in our changelog in alphabetical order and link related issue
  • Update the documentation, if needed
  • Add unit & e2e tests for your changes
  • GitHub checks are passing
  • Is the DCO check failing? Here is how you can fix DCO issues

Once the initial tests are successful, a KEDA member will ensure that the e2e tests are run. Once the e2e tests have been successfully completed, the PR may be merged at a later date. Please be patient.

Learn more about our contribution guide.

@keda-automation keda-automation requested a review from a team June 2, 2026 08:23
@snyk-io

snyk-io Bot commented Jun 2, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

…y label

Adds WATCH_LABEL_SELECTOR environment variable that scopes which
ScaledObjects, ScaledJobs, TriggerAuthentications and
ClusterTriggerAuthentications an operator instance reconciles, based on
labels on those resources. Mirrors WATCH_NAMESPACE but filters by label
instead of by namespace.

Empty or unset preserves current behaviour. When set, filtering happens
at the informer cache level (cache.ByObject{Label: selector}) and at the
controller predicate level (predicate.LabelSelectorPredicate). The HPA
cache is filtered too since KEDA copies SO labels onto the HPA and
Owns(HPA) reconciles parent SOs.

Closes kedacore#7738

Signed-off-by: Rossano Bestteti <rossanorbr@gmail.com>
@rossanorbr rossanorbr force-pushed the feat/watch-label-selector branch from 8b8a7b3 to ffdc215 Compare June 2, 2026 08:34
rossanorbr added a commit to rossanorbr/charts that referenced this pull request Jun 2, 2026
Adds a `watchLabelSelector` chart value that maps to the
`WATCH_LABEL_SELECTOR` env var on the operator Deployment.

Mirrors the existing `watchNamespace` value, but filters reconciled
objects by label instead of by namespace. Default is empty
(backward compatible: no label-based filtering).

Relates to kedacore/keda#7816

Signed-off-by: Rossano Bestteti <rossanorbr@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add WATCH_LABEL_SELECTOR env var to filter reconciled objects by label

1 participant