From af8f58d2e034382a936a1f44997e75ffc91ae6b6 Mon Sep 17 00:00:00 2001 From: Jonathan Berkhahn Date: Mon, 13 May 2024 07:55:26 -0700 Subject: [PATCH] update Designing Lean Operators docs to use new Kubebuilder cache config options (#6743) Signed-off-by: jberkhahn --- .../designing-lean-operators.md | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/website/content/en/docs/best-practices/designing-lean-operators.md b/website/content/en/docs/best-practices/designing-lean-operators.md index e72bf8e6c13..49478920490 100644 --- a/website/content/en/docs/best-practices/designing-lean-operators.md +++ b/website/content/en/docs/best-practices/designing-lean-operators.md @@ -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 \ No newline at end of file +[Filter cache ListWatch using selectors]: https://github.com/kubernetes-sigs/controller-runtime/blob/master/designs/use-selectors-at-cache.md