Skip to content

feat(main): add --watch-namespace to scope the manager cache#341

Open
K.J. Valencik (kjvalencik) wants to merge 1 commit into
cozystack:mainfrom
kjvalencik:kj/watch-namespaces
Open

feat(main): add --watch-namespace to scope the manager cache#341
K.J. Valencik (kjvalencik) wants to merge 1 commit into
cozystack:mainfrom
kjvalencik:kj/watch-namespaces

Conversation

@kjvalencik

Copy link
Copy Markdown

Motivation

The manager's controller-runtime cache defaults to cluster-wide watches for every secondary resource it owns (Pods, PVCs, Services, Jobs, PDBs). On large clusters, caching every pod in the cluster can OOM-kill the manager against the chart's default 128Mi limit — even when only a handful of namespaces contain etcd clusters. docs/installation.md previously called this out as an unexposed follow-up.

Related: #199

Changes

  • New --watch-namespace flag, defaulting to $WATCH_NAMESPACE (operator-sdk convention): a comma-separated namespace list wired into the manager's Cache.DefaultNamespaces. Empty/unset keeps today's watch-everything behavior.
  • Chart: manager.watchNamespaces (list) renders the WATCH_NAMESPACE env var onto the manager container. Unset by default.
  • Docs: installation.md RBAC section and chart-values table updated.

RBAC

Intentionally untouched — the existing ClusterRole authorizes the scoped watches. Since every rule in the manager role covers namespaced resources, this change also makes it possible to run with per-namespace Roles instead of the ClusterRole (with the metrics proxy disabled, as its TokenReview/SubjectAccessReview permissions are cluster-scoped) — left as a future improvement.

Testing

  • Unit tests for the namespace-list parsing: empty, whitespace-only, and separator-only inputs yield the zero cache.Options, keeping the unset path identical to the previous behavior.
  • make test passes; helm template/helm lint verified with and without the value set.

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Jul 13, 2026
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@kjvalencik, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 51 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 415d2107-4af0-4bf4-b053-729bd85b4a98

📥 Commits

Reviewing files that changed from the base of the PR and between 9eb1ec1 and 5b7b50c.

📒 Files selected for processing (5)
  • charts/etcd-operator/templates/deployment.yaml
  • charts/etcd-operator/values.yaml
  • docs/installation.md
  • main.go
  • main_test.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for scoping the etcd-operator to watch specific namespaces instead of all namespaces. It adds a --watch-namespace flag and a corresponding WATCH_NAMESPACE environment variable to the manager, updates the Helm chart to support this configuration via manager.watchNamespaces, and updates the documentation and tests accordingly. The review feedback suggests making the Helm template more robust by handling cases where manager.watchNamespaces is provided as a string instead of a slice to prevent template rendering errors.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread charts/etcd-operator/templates/deployment.yaml
The manager's default cluster-wide cache holds every Pod, PVC, Service,
Job, and PDB in the cluster; on large clusters this OOM-kills the manager
against the chart's default 128Mi limit.

Add a --watch-namespace flag (defaulting to $WATCH_NAMESPACE, per the
operator-sdk convention) taking a comma-separated namespace list, wired
into the manager's Cache.DefaultNamespaces. Empty/unset preserves the
current watch-everything behavior. The chart exposes it as
manager.watchNamespaces, rendered onto the manager container as the
WATCH_NAMESPACE env var.

RBAC is intentionally untouched: the ClusterRole continues to authorize
the scoped watches.

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

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant