Single Namespace restored#498
Open
desmax74 wants to merge 1 commit into
Open
Conversation
Reviewer's GuideConfigure the controller-runtime manager to optionally watch a single namespace via a WATCH_NAMESPACE environment variable, and wire that variable into both the controller deployment and CSV manifests. Sequence diagram for manager startup with optional single-namespace cachesequenceDiagram
participant Kubelet
participant OperatorPod
participant Main as main_go
participant Manager as ControllerRuntimeManager
participant KubeAPI as KubernetesAPI
Kubelet->>OperatorPod: Start pod with env WATCH_NAMESPACE (from metadata.namespace)
OperatorPod->>Main: Execute main()
Main->>Main: Read WATCH_NAMESPACE from environment
alt WATCH_NAMESPACE is set
Main->>Main: Build cache.Options with DefaultNamespaces[WATCH_NAMESPACE]
Main->>Manager: Create NewManager(config, Options{Cache: cache.Options})
Manager->>KubeAPI: List/watch resources in WATCH_NAMESPACE only
else WATCH_NAMESPACE is empty
Main->>Main: Use default cache.Options (all namespaces)
Main->>Manager: Create NewManager(config, Options{Cache: default})
Manager->>KubeAPI: List/watch resources in all namespaces
end
Manager-->>Main: Manager initialized
Main->>Manager: Start()
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey there - I've reviewed your changes - here's some feedback:
- Instead of using a package-level
watchNamespacevariable initialized viaos.Getenv, consider reading the environment variable insidemain()to avoid global state and make the configuration behavior easier to test and reason about. - Since this PR only supports a single namespace, using
ctrl.Options{Namespace: watchNamespace}may be clearer and more idiomatic than configuringcache.Options{DefaultNamespaces: map[string]cache.Config{...}}for a single entry.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Instead of using a package-level `watchNamespace` variable initialized via `os.Getenv`, consider reading the environment variable inside `main()` to avoid global state and make the configuration behavior easier to test and reason about.
- Since this PR only supports a single namespace, using `ctrl.Options{Namespace: watchNamespace}` may be clearer and more idiomatic than configuring `cache.Options{DefaultNamespaces: map[string]cache.Config{...}}` for a single entry.
## Individual Comments
### Comment 1
<location> `main.go:83` </location>
<code_context>
+ cacheOpts = cache.Options{
</code_context>
<issue_to_address>
**issue (bug_risk):** Using DefaultNamespaces for a single namespace may change cluster-scoped resource behavior compared to the default cache.
`DefaultNamespaces` is designed for multi-namespace caches and changes how cluster-scoped resources are handled, which can differ from the default single-namespace/cluster-wide cache. If this operator uses cluster-scoped resources (CRDs, ClusterRoles, etc.), this may introduce subtle behavior differences. For a single-namespace watch, prefer setting `Namespace: watchNamespace` in `cache.Options` to preserve default cache behavior while restricting namespaced objects.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
desmax74
force-pushed
the
singleNamespaceRestore
branch
from
November 28, 2025 14:45
7187cd0 to
06542b9
Compare
Signed-off-by: desmax74 <mdessi@redhat.com>
desmax74
force-pushed
the
singleNamespaceRestore
branch
from
December 2, 2025 15:22
05e0118 to
6a07e16
Compare
|
This PR must be considered on-hold until the analysis work required to define a strategy for the RHTPA Operator has been completed. https://issues.redhat.com/browse/TC-3247 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
Configure the operator to watch either a single namespace or all namespaces based on an environment variable.
New Features:
Enhancements: