Skip to content

Commit

Permalink
update Designing Lean Operators docs to use new Kubebuilder cache con…
Browse files Browse the repository at this point in the history
…fig options (#6743)

Signed-off-by: jberkhahn <jaberkha@us.ibm.com>
  • Loading branch information
jberkhahn committed May 13, 2024
1 parent c762768 commit af8f58d
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions website/content/en/docs/best-practices/designing-lean-operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,37 @@ Requests to a client backed by a filtered cache for objects that do not match th

## How is this done ?

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

## Examples

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.
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.

```yaml
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
NewCache: cache.BuilderWithOptions(cache.Options{
SelectorsByObject: cache.SelectorsByObject{
&corev1.Secret{}: {
Label: labels.SelectorFromSet(labels.Set{"app": "app-name"}),
},
Cache: cache.Options{
ByObject: map[client.Object]cache.ByObject{
&corev1.Secret{}: cache.ByObject{
Label: labels.SelectorFromSet(labels.Set{"app": "app-name"}),
},
}),
},
},
})
```

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.
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.

```yaml
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
NewCache: cache.BuilderWithOptions(cache.Options{
SelectorsByObject: cache.SelectorsByObject{
&corev1.Node{}: {
Field: fields.SelectorFromSet(fields.Set{"metadata.name": "node01"}),
},
Cache: cache.Options{
ByObject: map[client.Object]cache.ByObject{
&corev1.Node{}: cache.ByObject{
Fields: labels.SelectorFromSet(fields.Set{"metadata.name": "node01"}),
},
}),
},
},
})
```

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

0 comments on commit af8f58d

Please sign in to comment.