From 3727994dea01e6bcc19c73cbce2b830ed3e1bf91 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 d7088f0f..83962c7d 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" @@ -135,7 +136,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) @@ -186,3 +188,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 640b69b32363acb17a805831b6c8de9c0bcb2202 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 83962c7d..511076a8 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -203,6 +203,8 @@ func pruneIrrelevantPodData(obj interface{}) (interface{}, error) { Annotations: oldPod.Annotations, Labels: oldPod.Labels, } + newPod.Spec = corev1.PodSpec{} + newPod.Status = corev1.PodStatus{} return newPod, nil }