From 54b832ed37209bf8bffeb4085f933cc1ba6a9ac8 Mon Sep 17 00:00:00 2001 From: Miguel Duarte Barroso Date: Thu, 23 May 2024 16:06:54 +0200 Subject: [PATCH 1/2] perf: prune cached pod data We only need the pod name / namespace / annotations / labels. Thus we prune everything else. Signed-off-by: Miguel Duarte Barroso --- cmd/main.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/cmd/main.go b/cmd/main.go index 3c81ad32..9006a4f0 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -26,6 +26,7 @@ import ( _ "k8s.io/client-go/plugin/pkg/client/auth" corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime" @@ -121,7 +122,8 @@ func main() { NewCache: func(config *rest.Config, opts cache.Options) (cache.Cache, error) { opts.ByObject = map[client.Object]cache.ByObject{ &corev1.Pod{}: { - Label: virtLauncherSelector(), + Label: virtLauncherSelector(), + Transform: pruneIrrelevantPodData, }, } return cache.New(config, opts) @@ -167,3 +169,21 @@ func main() { func virtLauncherSelector() labels.Selector { return labels.SelectorFromSet(map[string]string{virtv1.AppLabel: "virt-launcher"}) } + +func pruneIrrelevantPodData(obj interface{}) (interface{}, error) { + oldPod, ok := obj.(*corev1.Pod) + if !ok { + return obj, nil + } + + newPod := oldPod.DeepCopy() + newPod.ObjectMeta = metav1.ObjectMeta{ + Name: oldPod.Name, + Namespace: oldPod.Namespace, + UID: oldPod.UID, + Annotations: oldPod.Annotations, + Labels: oldPod.Labels, + } + + return newPod, nil +} From cc2aea69bf740056b4d03e780b556f41aa931457 Mon Sep 17 00:00:00 2001 From: Miguel Duarte Barroso Date: Thu, 23 May 2024 16:15:08 +0200 Subject: [PATCH 2/2] perf: prune cached pod data spec & status Signed-off-by: Miguel Duarte Barroso --- cmd/main.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/main.go b/cmd/main.go index 9006a4f0..0a95ddd4 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -184,6 +184,8 @@ func pruneIrrelevantPodData(obj interface{}) (interface{}, error) { Annotations: oldPod.Annotations, Labels: oldPod.Labels, } + newPod.Spec = corev1.PodSpec{} + newPod.Status = corev1.PodStatus{} return newPod, nil }