Skip to content

Commit af8f58d

Browse files
authored
update Designing Lean Operators docs to use new Kubebuilder cache config options (#6743)
Signed-off-by: jberkhahn <jaberkha@us.ibm.com>
1 parent c762768 commit af8f58d

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

website/content/en/docs/best-practices/designing-lean-operators.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,37 @@ Requests to a client backed by a filtered cache for objects that do not match th
1414

1515
## How is this done ?
1616

17-
- When creating the manager, you can override the default NewCache function
17+
- When creating the manager, you can add an Options struct to configure the Cache
1818
- Each client.Object can be filtered with labels and fields
1919

2020
## Examples
2121

22-
In this scenario, the user will override the NewCache function to filter the secret object by it's label. This will return a filtered cache for objects that match the filter.
22+
In this scenario, the user will configure the Cache to filter the secret object by it's label. This will return a filtered cache for objects that match the filter.
2323

2424
```yaml
2525
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
26-
NewCache: cache.BuilderWithOptions(cache.Options{
27-
SelectorsByObject: cache.SelectorsByObject{
28-
&corev1.Secret{}: {
29-
Label: labels.SelectorFromSet(labels.Set{"app": "app-name"}),
30-
},
26+
Cache: cache.Options{
27+
ByObject: map[client.Object]cache.ByObject{
28+
&corev1.Secret{}: cache.ByObject{
29+
Label: labels.SelectorFromSet(labels.Set{"app": "app-name"}),
3130
},
32-
}),
31+
},
32+
},
3333
})
3434
```
3535

36-
In this scenario, the user will override the NewCache function to filter the node object by it's field name. This will return a filtered cache for objects that match the filter.
36+
In this scenario, the user will configure the Cache to filter the node object by it's field name. This will return a filtered cache for objects that match the filter.
3737

3838
```yaml
3939
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
40-
NewCache: cache.BuilderWithOptions(cache.Options{
41-
SelectorsByObject: cache.SelectorsByObject{
42-
&corev1.Node{}: {
43-
Field: fields.SelectorFromSet(fields.Set{"metadata.name": "node01"}),
44-
},
40+
Cache: cache.Options{
41+
ByObject: map[client.Object]cache.ByObject{
42+
&corev1.Node{}: cache.ByObject{
43+
Fields: labels.SelectorFromSet(fields.Set{"metadata.name": "node01"}),
4544
},
46-
}),
45+
},
46+
},
4747
})
4848
```
4949

50-
[Filter cache ListWatch using selectors]: https://github.com/kubernetes-sigs/controller-runtime/blob/master/designs/use-selectors-at-cache.md
50+
[Filter cache ListWatch using selectors]: https://github.com/kubernetes-sigs/controller-runtime/blob/master/designs/use-selectors-at-cache.md

0 commit comments

Comments
 (0)