Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update Designing Lean Operators docs to use new Kubebuilder cache con… #6743

Merged
merged 1 commit into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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