Skip to content

Commit d8afce4

Browse files
authored
Change docs to reflect updated controller runtime options for caching select namespaces (operator-framework#6719)
Signed-off-by: jberkhahn <[email protected]>
1 parent 667de3d commit d8afce4

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

website/content/en/docs/building-operators/golang/operator-scope.md

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ as cluster-scoped. For example, the [cert-manager][cert-manager] operator is oft
1919
permissions and watches so that it can manage and issue certificates for an entire cluster.
2020

2121
**IMPORTANT**: When a [Manager][ctrl-manager] instance is created in the `main.go` file, the
22-
Namespaces are set via [Manager Options][ctrl-options] as described below. These Namespaces should be watched and
22+
Namespaces are set via [Cache Config][cache-config] as described below. These Namespaces should be watched and
2323
cached for the Client which is provided by the Manager. Only clients provided by cluster-scoped Managers are able
2424
to manage cluster-scoped CRD's. For further information see: [CRD scope doc][crd-scope-doc].
2525

2626
## Manager watching options
2727

2828
### Watching resources in all Namespaces (default)
2929

30-
A [Manager][ctrl-manager] is initialized with no Namespace option specified, or `Namespace: ""` will
30+
A [Manager][ctrl-manager] is initialized with no Cache option specified, or with a Cache.DefaultNamespaces of `Namespace: ""` will
3131
watch all Namespaces:
3232

3333
```go
@@ -42,10 +42,10 @@ mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
4242
...
4343
```
4444

45-
### Watching resources in a single Namespace
45+
### Watching resources in specific Namespaces
4646

47-
To restrict the scope of the [Manager's][ctrl-manager] cache to a specific Namespace set the `Namespace` field
48-
in [Options][ctrl-options]:
47+
To restrict the scope of the [Manager's][ctrl-manager] cache to a specific Namespace set the `Cache.DefaultNamespaces'
48+
field in [Options][ctrl-options]:
4949

5050
```go
5151
...
@@ -55,32 +55,39 @@ mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
5555
Port: 9443,
5656
LeaderElection: enableLeaderElection,
5757
LeaderElectionID: "f1c5ece8.example.com",
58-
Namespace: "operator-namespace",
58+
Cache: cache.Options{
59+
DefaultNamespaces: map[string]cache.Config{"operator-namespace": cache.Config{}},
60+
},
5961
})
6062
...
6163
```
6264

6365
### Watching resources in a set of Namespaces
6466

65-
It is possible to use [`MultiNamespacedCacheBuilder`][multi-namespaced-cache-builder] from
66-
[Options][ctrl-options] to watch and manage resources in a set of Namespaces:
67+
It is also possible to use 'DefaultNamepsaces' to watch and manage resources in a set of Namespaces:
6768

6869
```go
6970
...
70-
namespaces := []string{"foo", "bar"} // List of Namespaces
71-
...
7271
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
7372
Scheme: scheme,
7473
MetricsBindAddress: metricsAddr,
7574
Port: 9443,
7675
LeaderElection: enableLeaderElection,
7776
LeaderElectionID: "f1c5ece8.example.com",
78-
NewCache: cache.MultiNamespacedCacheBuilder(namespaces),
77+
Cache: cache.Options{
78+
DefaultNamespaces: map[string]cache.Config{
79+
"operator-namespace1": cache.Config{},
80+
"operator-namespace2": cache.Config{},
81+
},
82+
},
7983
})
8084
...
8185
```
82-
In the above example, a CR created in a Namespace not in the set passed to `Options` will not be reconciled by
83-
its controller because the [Manager][ctrl-manager] does not manage that Namespace.
86+
87+
In the above example, a CR created in a Namespace not in the set passed to `Cache.DefaultNamespaces` will not be reconciled by
88+
its controller because the [Manager][ctrl-manager] does not manage that Namespace. Further restrictions and qualifications
89+
can created on a per-namespace basis by setting fields in the cache.Config object, for further information see the
90+
[controller runtime docs][cache-config]
8491

8592
**IMPORTANT:** Note that this is not intended to be used for excluding Namespaces, this is better done via a Predicate.
8693

@@ -299,10 +306,10 @@ If the operator can watch multiple namespaces, set the following in your `spec.i
299306
supported: true
300307
```
301308

309+
[cache-config]: https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/cache#Config
302310
[cert-manager]: https://github.com/jetstack/cert-manager
303311
[ctrl-manager]: https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/manager#Manager
304312
[ctrl-options]: https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/manager#Options
305-
[multi-namespaced-cache-builder]: https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/cache#MultiNamespacedCacheBuilder
306313
[k8s-rbac]: https://kubernetes.io/docs/reference/access-authn-authz/rbac/
307314
[kube-rbac-proxy]: https://github.com/brancz/kube-rbac-proxy
308315
[rbac-clusterrole]: https://kubernetes.io/docs/reference/access-authn-authz/rbac/#role-and-clusterrole

website/content/en/docs/building-operators/golang/tutorial.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,6 @@ Next, check out the following:
545545
[markers]: https://book.kubebuilder.io/reference/markers.html
546546
[memcached_controller]: https://github.com/operator-framework/operator-sdk/blob/latest/testdata/go/v4/memcached-operator/internal/controller/memcached_controller.go
547547
[migration-guide]:/docs/building-operators/golang/migration
548-
[multi-namespaced-cache-builder]: https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/cache#MultiNamespacedCacheBuilder
549548
[multigroup-kubebuilder-doc]: https://book.kubebuilder.io/migration/multi-group.html
550549
[olm-integration]: /docs/olm-integration
551550
[openapi-validation]: /docs/building-operators/golang/references/openapi-validation

0 commit comments

Comments
 (0)