Skip to content

Conversation

@camilamacedo86
Copy link
Member

@camilamacedo86 camilamacedo86 commented Jan 29, 2026

Add --namespaced flag to scaffold managers that watch only specific namespace(s),
enabling least-privilege deployments and multi-tenant architectures.

Moreover, fix and supplement the documentation accordingly.

Closes: #2123

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 29, 2026
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jan 29, 2026
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: camilamacedo86

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jan 29, 2026
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jan 29, 2026
@camilamacedo86 camilamacedo86 force-pushed the add-namesapced-support branch 9 times, most recently from c3b2723 to 0f4e79d Compare January 29, 2026 22:56
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds namespace-scoped deployment support to Kubebuilder, allowing operators to be configured to watch and manage resources in specific namespace(s) rather than cluster-wide. This addresses issue #2123 by providing a --namespaced flag (similar to the existing --multigroup flag) for both init and edit commands.

Changes:

  • Added --namespaced flag to kubebuilder init and kubebuilder edit commands for scaffolding namespace-scoped operators
  • Implemented namespace-scoped RBAC generation (Role/RoleBinding instead of ClusterRole/ClusterRoleBinding)
  • Added namespace watching configuration in main.go template with support for single and multi-namespace modes via WATCH_NAMESPACE environment variable
  • Added comprehensive documentation including migration guide, manager scope reference, and CRD scope reference

Reviewed changes

Copilot reviewed 58 out of 71 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pkg/config/interface.go Added IsNamespaced(), SetNamespaced(), and ClearNamespaced() interface methods
pkg/config/v3/config.go Implemented namespaced flag in config struct and methods
pkg/machinery/interfaces.go Added HasNamespaced interface for templates
pkg/machinery/injector.go Added injection of namespaced flag to templates
pkg/machinery/mixins.go Added NamespacedMixin for template scaffolding
pkg/plugins/golang/v4/init.go Added --namespaced flag to init command
pkg/plugins/golang/v4/edit.go Added --namespaced flag to edit command
pkg/plugins/golang/v4/scaffolds/edit.go Added RBAC scaffolding logic for namespace-scoped mode
pkg/plugins/golang/v4/scaffolds/internal/templates/cmd/main.go Added conditional scaffolding for namespace watching code
pkg/plugins/golang/v4/scaffolds/internal/templates/controllers/controller.go Added conditional RBAC markers with namespace parameter
pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller.go Added namespace-scoped RBAC marker support
pkg/plugins/common/kustomize/v2/scaffolds/init.go Added conditional scaffolding of Role vs ClusterRole based on namespaced flag
pkg/plugins/common/kustomize/v2/scaffolds/edit.go Added edit scaffolder for toggling RBAC between namespaced and cluster-scoped
pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/rbac/namespaced_role.go New template for namespace-scoped Role
pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/rbac/namespaced_role_binding.go New template for namespace-scoped RoleBinding
pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/rbac/cluster_role.go Renamed from Role to ClusterRole for clarity
pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/rbac/cluster_role_binding.go Renamed from RoleBinding to ClusterRoleBinding for clarity
pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/rbac/crd_*_role.go Added conditional Kind (Role vs ClusterRole) based on namespaced flag
pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/manager/config.go Added conditional WATCH_NAMESPACE environment variable
pkg/plugins/optional/helm/v2alpha/scaffolds/internal/kustomize/helm_templater.go Added roleRef name substitution for Helm charts
test/e2e/v4/plugin_cluster_test.go Added namespace-scoped e2e tests with namespace isolation verification
test/e2e/v4/generate_test.go Added GenerateV4Namespaced and GenerateV4NamespacedWithoutWebhooks test functions
test/testdata/generate.sh Updated to scaffold project-v4-with-plugins with --namespaced flag
testdata/project-v4-with-plugins/* Regenerated test data with namespace-scoped configuration
docs/book/src/reference/scopes.md Restructured to explain manager vs CRD scope concepts
docs/book/src/reference/manager-scope.md New comprehensive manager scope reference documentation
docs/book/src/reference/crd-scope.md New comprehensive CRD scope reference documentation
docs/book/src/migration/namespace-scoped.md New migration guide for converting existing projects to namespace-scoped
docs/book/src/SUMMARY.md Added new documentation pages to book navigation
**/AGENTS.md Added namespace-scoped conversion instructions for AI agents

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@camilamacedo86 camilamacedo86 changed the title WIP ✨ (CLI): Add option for namespaced layout such as we have for multigroup ✨ (CLI): Add option for namespaced layout such as we have for multigroup Jan 29, 2026
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 29, 2026
@camilamacedo86 camilamacedo86 changed the title ✨ (CLI): Add option for namespaced layout such as we have for multigroup WIP ✨ (CLI): Add option for namespaced layout such as we have for multigroup Jan 29, 2026
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 29, 2026
@camilamacedo86 camilamacedo86 changed the title WIP ✨ (CLI): Add option for namespaced layout such as we have for multigroup ✨ Add option for namespaced layout such as we have for multigroup Jan 29, 2026
@camilamacedo86 camilamacedo86 changed the title ✨ feat(go/v4): add namespace-scoped manager support WIP ✨ feat(go/v4): add namespace-scoped manager support Jan 31, 2026
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 31, 2026
@camilamacedo86 camilamacedo86 force-pushed the add-namesapced-support branch 7 times, most recently from eaf2129 to d9bde20 Compare February 2, 2026 11:26
@camilamacedo86 camilamacedo86 changed the title WIP ✨ feat(go/v4): add namespace-scoped manager support ✨ feat(go/v4): add namespace-scoped manager support Feb 2, 2026
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 2, 2026
@camilamacedo86
Copy link
Member Author

/retest-required

@camilamacedo86 camilamacedo86 changed the title ✨ feat(go/v4): add namespace-scoped manager support ✨ feat(go/v4): add namespace-scoped manager support Feb 2, 2026
@camilamacedo86
Copy link
Member Author

/test pull-kubebuilder-e2e-k8s-1-33-0

@camilamacedo86
Copy link
Member Author

/test pull-kubebuilder-e2e-k8s-1-34-0

@camilamacedo86 camilamacedo86 force-pushed the add-namesapced-support branch 2 times, most recently from 8c7d680 to f3ff775 Compare February 2, 2026 16:57
@camilamacedo86 camilamacedo86 changed the title ✨ feat(go/v4): add namespace-scoped manager support ✨ (go/v4): Add --namespaced flag for namespace-scoped managers Feb 2, 2026
@camilamacedo86 camilamacedo86 changed the title ✨ (go/v4): Add --namespaced flag for namespace-scoped managers WIP ✨ (go/v4): Add --namespaced flag for namespace-scoped managers Feb 2, 2026
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 2, 2026
camilamacedo86 and others added 2 commits February 3, 2026 15:51
Added IsNamespaced field to RunOptions and implemented namespace isolation
validation to verify namespace-scoped managers only reconcile resources within
their watch namespace. Added tests for both go/v4 and helm plugins.

Co-authored-by: Cursor <[email protected]>
@camilamacedo86 camilamacedo86 changed the title WIP ✨ (go/v4): Add --namespaced flag for namespace-scoped managers ✨ (go/v4): Add --namespaced flag for namespace-scoped managers Feb 3, 2026
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 3, 2026
@camilamacedo86
Copy link
Member Author

/test pull-kubebuilder-e2e-k8s-1-34-0

@camilamacedo86 camilamacedo86 changed the title ✨ (go/v4): Add --namespaced flag for namespace-scoped managers ✨ (go/v4): Add --namespaced flag for namespace-scoped managers Feb 3, 2026
@camilamacedo86
Copy link
Member Author

/test pull-kubebuilder-e2e-k8s-1-34-0

1 similar comment
@camilamacedo86
Copy link
Member Author

/test pull-kubebuilder-e2e-k8s-1-34-0

@k8s-ci-robot
Copy link
Contributor

@camilamacedo86: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubebuilder-e2e-k8s-1-34-0 f95dc0a link true /test pull-kubebuilder-e2e-k8s-1-34-0

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add target to deploy a namespace-scoped operator.

2 participants