You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/content/en/docs/building-operators/golang/crds-scope.md
+44-55Lines changed: 44 additions & 55 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,69 +6,54 @@ weight: 60
6
6
7
7
## Overview
8
8
9
-
The CustomResourceDefinition (CRD) scope can also be changed for cluster-scoped operators so that there is only a single
10
-
instance (for a given name) of the Custom Resource (CR) to manage across the cluster.
9
+
This page details the various methods to control the scope of a CRD. See the [operator scope doc](/docs/building-operators/golang/operator-scope/) for information on configuring operator scope, such as which namespaces to watch.
11
10
12
-
The CRD manifests are generated in `config/crd/bases`. For each CRD that needs to be cluster-scoped, its manifest
13
-
should specify `spec.scope: Cluster`.
11
+
Custom Resource Definitions (CRDs) contain a scope field that determines whether the resulting Custom Resource (CR)
12
+
is cluster or namespace scoped. An operator author might use a namespaced-scoped CRD
13
+
to restrict access to a CR to certain namespaces, or to have different versions of CRs accessible in different namespaces.
14
+
Alternatively, an operator author might want a cluster-scoped CRD so all namespaces have visibility and access to CRs.
14
15
15
-
To ensure that the CRD is always generated with `scope: Cluster`, add the marker
16
-
`//+kubebuilder:resource:path=<resource>,scope=Cluster`, or if already present replace `scope={Namespaced -> Cluster}`,
17
-
above the CRD's Go type definition in `api/<version>/<kind>_types.go` or `apis/<group>/<version>/<kind>_types.go`
18
-
if you are using the [multigroup][multigroup-kubebuilder-doc] layout. Note that the `<resource>`
19
-
element must be the same lower-case plural value of the CRD's Kind, `spec.names.plural`.
16
+
The CRD manifests are generated by the `operator-sdk create api` command in `config/crd/bases`. A CRD's `spec.scope` field controls API scope; valid values are [`Cluster` and `Namespaced`](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#create-a-customresourcedefinition).
17
+
For an Operator-sdk Go project, this value is determined by the `operator-sdk create api --namespaced` boolean flag, which edits the
18
+
`types.go` file for the resource. For other operator types, the command edits `spec.scope` in the CRD's YAML manifest directly.
20
19
21
-
**NOTE**: When a `Manager` instance is created in the `main.go` file, it receives the namespace(s) as Options.
22
-
These namespace(s) should be watched and cached for the Client which is provided by the Controllers. Only clients
23
-
provided by cluster-scoped projects where the `Namespace` attribute is `""` will be able to manage cluster-scoped CRs.
24
-
For more information see the [Manager][manager_user_guide] topic in the user guide and the
25
-
[Manager Options][manager_options].
20
+
## Set `create api` --namespaced flag
26
21
27
-
## Example for changing the CRD scope from Namespaced to Cluster
22
+
When creating a new API, the `--namespaced` flag controls whether the resulting CRD will be cluster or namespace scoped.
23
+
By default, `--namespaced` is set to `true` which sets the scope to `Namespaced`. An example command to create a cluster-scoped API would be:
28
24
29
-
- Check the `spec.names.plural` in the CRD's Kind YAML file
0 commit comments