@@ -19,15 +19,15 @@ as cluster-scoped. For example, the [cert-manager][cert-manager] operator is oft
19
19
permissions and watches so that it can manage and issue certificates for an entire cluster.
20
20
21
21
** 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
23
23
cached for the Client which is provided by the Manager. Only clients provided by cluster-scoped Managers are able
24
24
to manage cluster-scoped CRD's. For further information see: [ CRD scope doc] [ crd-scope-doc ] .
25
25
26
26
## Manager watching options
27
27
28
28
### Watching resources in all Namespaces (default)
29
29
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
31
31
watch all Namespaces:
32
32
33
33
``` go
@@ -42,10 +42,10 @@ mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
42
42
...
43
43
```
44
44
45
- ### Watching resources in a single Namespace
45
+ ### Watching resources in specific Namespaces
46
46
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 ] :
49
49
50
50
``` go
51
51
...
@@ -55,32 +55,39 @@ mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
55
55
Port : 9443 ,
56
56
LeaderElection : enableLeaderElection,
57
57
LeaderElectionID : " f1c5ece8.example.com" ,
58
- Namespace : " operator-namespace" ,
58
+ Cache : cache.Options {
59
+ DefaultNamespaces: map [string ]cache.Config {" operator-namespace" : cache.Config {}},
60
+ },
59
61
})
60
62
...
61
63
```
62
64
63
65
### Watching resources in a set of Namespaces
64
66
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:
67
68
68
69
``` go
69
70
...
70
- namespaces := []string {" foo" , " bar" } // List of Namespaces
71
- ...
72
71
mgr , err := ctrl.NewManager (ctrl.GetConfigOrDie (), ctrl.Options {
73
72
Scheme : scheme,
74
73
MetricsBindAddress : metricsAddr,
75
74
Port : 9443 ,
76
75
LeaderElection : enableLeaderElection,
77
76
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
+ },
79
83
})
80
84
...
81
85
```
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 ]
84
91
85
92
** IMPORTANT:** Note that this is not intended to be used for excluding Namespaces, this is better done via a Predicate.
86
93
@@ -299,10 +306,10 @@ If the operator can watch multiple namespaces, set the following in your `spec.i
299
306
supported: true
300
307
` ` `
301
308
309
+ [cache-config] : https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/cache#Config
302
310
[cert-manager] : https://github.com/jetstack/cert-manager
303
311
[ctrl-manager] : https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/manager#Manager
304
312
[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
306
313
[k8s-rbac] : https://kubernetes.io/docs/reference/access-authn-authz/rbac/
307
314
[kube-rbac-proxy] : https://github.com/brancz/kube-rbac-proxy
308
315
[rbac-clusterrole] : https://kubernetes.io/docs/reference/access-authn-authz/rbac/#role-and-clusterrole
0 commit comments