Skip to content

Commit 34edd0a

Browse files
authored
doc/operator-scope: add scope tag for CRD generation (#1652)
1 parent e43d6e5 commit 34edd0a

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

doc/operator-scope.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ For each CRD that needs to be cluster-scoped, update its manifest to be cluster-
2424
* `deploy/crds/<group>_<version>_<kind>_crd.yaml`
2525
* Set `spec.scope: Cluster`
2626

27+
To ensure that the CRD is always generated with `scope: Cluster`, add the tag `// +genclient:nonNamespaced` above the CRD's Go type defintion in `pkg/apis/<group>/<version>/<kind>_types.go`.
28+
2729

2830
### Example for cluster scoped operator
2931

@@ -82,3 +84,18 @@ With the above changes the specified manifests should look as follows:
8284
...
8385
scope: Cluster
8486
```
87+
* `pkg/apis/cache/v1alpha1/memcached_types.go`
88+
```Go
89+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
90+
91+
// Memcached is the Schema for the memcacheds API
92+
// +k8s:openapi-gen=true
93+
// +genclient:nonNamespaced
94+
type Memcached struct {
95+
metav1.TypeMeta `json:",inline"`
96+
metav1.ObjectMeta `json:"metadata,omitempty"`
97+
98+
Spec MemcachedSpec `json:"spec,omitempty"`
99+
Status MemcachedStatus `json:"status,omitempty"`
100+
}
101+
```

doc/user-guide.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ By default this will be the namespace that the operator is running in. To watch
7575
mgr, err := manager.New(cfg, manager.Options{Namespace: ""})
7676
```
7777

78+
By default the main program will set the manager's namespace using the value of `WATCH_NAMESPACE` env defined in `deploy/operator.yaml`.
79+
7880
## Add a new Custom Resource Definition
7981

8082
Add a new Custom Resource Definition(CRD) API called Memcached, with APIVersion `cache.example.com/v1alpha1` and Kind `Memcached`.

0 commit comments

Comments
 (0)