Skip to content

feat: add watch-namespace flag to filter namespaces to watch for resources#175

Merged
bjosv merged 3 commits into
valkey-io:mainfrom
jdheyburn:feat/watch-namespace-flag
May 27, 2026
Merged

feat: add watch-namespace flag to filter namespaces to watch for resources#175
bjosv merged 3 commits into
valkey-io:mainfrom
jdheyburn:feat/watch-namespace-flag

Conversation

@jdheyburn

@jdheyburn jdheyburn commented May 12, 2026

Copy link
Copy Markdown
Collaborator

Closes #178

Summary

Adds a new flag --watch-namespace that will limit the resources watched by the managers. This will help to reduce memory usage in larger clusters. The flag can be specified multiple times to limit to multiple namespaces.

Features / Behaviour Changes

Lower memory use

Implementation

Limitations

Testing

Tested locally by building the image and deploying to local kind cluster.

- args:
  # ...
  - --watch-namespace=valkey-operator-system
  - --zap-log-level=4
2026-05-12T10:06:58Z    INFO    setup    Restricting cache to namespaces    {"namespaces": ["valkey-operator-system"[]}

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one issue.
  • Commit message explains what changed and why
  • Tests are added or updated.
  • Documentation files are updated.
  • I have run pre-commit locally (pre-commit run --all-files or hooks on commit)

…urces

Signed-off-by: Joseph Heyburn <jdheyburn@gmail.com>
@jdheyburn jdheyburn marked this pull request as ready for review May 12, 2026 12:56
Comment thread cmd/main.go
flag.BoolVar(&enableHTTP2, "enable-http2", false,
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
seenNamespaces := make(map[string]struct{})
flag.Func("watch-namespace", "Namespace to watch (repeatable; omit for cluster-wide)", func(s string) error {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

how can users set this watch-namespace envvar from helm or operator env? i think we need to document that part

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I've got a draft PR for the helm chart here: valkey-io/valkey-helm#172

Is that what you had in mind?

For env var, can any of these arguments today be set via env var? I hadn't had that in scope.

bjosv
bjosv previously approved these changes May 22, 2026

@bjosv bjosv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Some operators seem to only, or also, use the env. variable WATCH_NAMESPACE, like dragonfly-opeator, cnpg, OT Redis operator and cockroach-operator.
It might be a convention from the Operator SDK, and some state that its simpler with env. than injecting extra args.
An env var would need to be comma separated.

Looking at the helm chart PR which uses your args; your solution seems cleaner.

@jdheyburn

Copy link
Copy Markdown
Collaborator Author

@bjosv I wonder if there is a way to have our args defined as env vars too.

…/watch-namespace-flag

Signed-off-by: Joseph Heyburn <jdheyburn@gmail.com>
bjosv
bjosv previously approved these changes May 27, 2026

@bjosv bjosv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM
The test failed due to an ValkeyNodeFailed event, and this seem to be a pre-existing race condition during initial cluster creation

Failed to reconcile ValkeyNode: Operation cannot be fulfilled on valkeynodes.valkey.io "cluster-sample-0-1": the object has been modified; please apply your changes to the latest version and try again
Then we try again and it works then. In the future, maybe we should change this event to be skipped when its a conflict.

Comment thread cmd/main.go Outdated
Signed-off-by: Joseph Heyburn <jdheyburn@gmail.com>
@jdheyburn

Copy link
Copy Markdown
Collaborator Author

@bjosv should be ready for final review now.

For that race condition, I think we should try to replace whatever Apply is causing that with a Patch if it makes sense to.

@bjosv

bjosv commented May 27, 2026

Copy link
Copy Markdown
Collaborator

For that race condition, I think we should try to replace whatever Apply is causing that with a Patch if it makes sense to.

Ah, yes that might be a better solution. We'll see if it pops up again

@bjosv bjosv merged commit 2b7d06b into valkey-io:main May 27, 2026
8 checks passed
@jdheyburn

Copy link
Copy Markdown
Collaborator Author

Helm chart PR to support this value:

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.

Filter namespaces for the operator to watch

3 participants