-
Notifications
You must be signed in to change notification settings - Fork 79
⚠ make spec.namespace optional with managed namespace support and PSA support #2825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
nader-ziada
wants to merge
2
commits into
operator-framework:main
Choose a base branch
from
nader-ziada:feat/namespace-psa
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # Managed Namespaces | ||
|
|
||
| ## What is a managed namespace? | ||
|
|
||
| When you create a ClusterExtension without specifying `spec.namespace`, operator-controller automatically creates and manages a namespace for the operator. The namespace name comes from the bundle's metadata or defaults to `<packageName>-system`. | ||
|
|
||
| When you specify `spec.namespace`, the namespace must already exist on the cluster and operator-controller installs into it without managing its lifecycle. | ||
|
|
||
| The mode is locked at creation time: you cannot switch between managed and user-provided after the ClusterExtension is created. | ||
|
|
||
| ## Namespace resolution | ||
|
|
||
| In managed mode, the namespace name is resolved from bundle CSV annotations in this order: | ||
|
|
||
| 1. `operatorframework.io/suggested-namespace-template`: the `metadata.name` field from the JSON template | ||
| 2. `operators.operatorframework.io/suggested-namespace`: a plain string with the preferred name | ||
| 3. `<packageName>-system`: convention fallback | ||
|
|
||
| ## What belongs in a managed namespace | ||
|
|
||
| - The operator's own workloads (deployments, services, configmaps) | ||
| - The operator's RBAC resources (service accounts, roles, role bindings) | ||
| - CRDs and webhooks installed by the operator | ||
|
|
||
| ## What does NOT belong in a managed namespace | ||
|
|
||
| - User application workloads | ||
| - Shared services used by multiple operators | ||
| - Persistent data that should survive operator uninstallation | ||
|
|
||
| ## Deletion behavior | ||
|
|
||
| Deleting a ClusterExtension with a managed namespace **deletes the entire namespace and everything in it.** If you have created resources in the managed namespace that are not part of the operator, they will be lost. | ||
|
|
||
| If you need the namespace to persist beyond the operator's lifecycle, use `spec.namespace` to point at an existing namespace you manage yourself. | ||
|
|
||
| ## PSA labels | ||
|
|
||
| If the bundle declares PSA requirements via `operatorframework.io/suggested-namespace-template`, those labels are applied to the managed namespace automatically. This ensures the namespace has the correct Pod Security Admission level for the operator's workloads without manual configuration. | ||
|
|
||
| ## Drift protection | ||
|
|
||
| Managed namespaces are reconciled by the ClusterObjectSet controller. If someone manually modifies or removes labels that the controller owns (e.g., PSA labels from the template), they are automatically restored. | ||
|
|
||
| Labels or annotations added by other actors that don't conflict with controller-owned fields are preserved. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| # Namespace Configuration for Bundle Authors | ||
|
|
||
| Bundle authors can specify their preferred namespace configuration through CSV annotations. These annotations are used by operator-controller when the cluster admin does not provide an explicit `spec.namespace`. | ||
|
|
||
| ## Annotations | ||
|
|
||
| ### `operatorframework.io/suggested-namespace-template` | ||
|
|
||
| Full namespace template with metadata. Use this when your operator needs specific labels or annotations on its namespace (e.g., PSA labels). | ||
|
|
||
| ```yaml | ||
| apiVersion: operators.coreos.com/v1alpha1 | ||
| kind: ClusterServiceVersion | ||
| metadata: | ||
| name: my-operator.v1.0.0 | ||
| annotations: | ||
| operatorframework.io/suggested-namespace-template: | | ||
| { | ||
| "apiVersion": "v1", | ||
| "kind": "Namespace", | ||
| "metadata": { | ||
| "name": "my-operator-system", | ||
| "labels": { | ||
| "pod-security.kubernetes.io/enforce": "privileged", | ||
| "pod-security.kubernetes.io/audit": "privileged", | ||
| "pod-security.kubernetes.io/warn": "privileged" | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### `operators.operatorframework.io/suggested-namespace` | ||
|
|
||
| Simple namespace name without metadata. Use this when you want a specific name but don't need labels or annotations. | ||
|
|
||
| ```yaml | ||
| annotations: | ||
| operators.operatorframework.io/suggested-namespace: my-operator-system | ||
| ``` | ||
|
|
||
| ### No annotation | ||
|
|
||
| If neither annotation is present, operator-controller uses `<packageName>-system` as the namespace name. | ||
|
|
||
| ## Priority | ||
|
|
||
| If both annotations are present, `suggested-namespace-template` takes priority. | ||
|
|
||
| ## Guidelines | ||
|
|
||
| - Always include PSA labels if your operator runs privileged containers. | ||
| - Use a descriptive, unique namespace name that includes your package name to avoid collisions. | ||
| - Do not assume the namespace name will be exactly what you suggest as cluster admins can override it by setting `spec.namespace`. | ||
| - The namespace name from the template is used only when `spec.namespace` is omitted. When set, the admin's choice takes precedence and no namespace object is created. | ||
|
|
||
| ## Consistency across bundle formats | ||
|
|
||
| The `operatorframework.io/suggested-namespace-template` and `operators.operatorframework.io/suggested-namespace` annotations are the canonical way to declare namespace preferences. Future bundle formats should use the same annotation keys to avoid divergence across the ecosystem. |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.