Skip to content

Commit

Permalink
Merge pull request #52 from maiqueb/cache-minimal-data
Browse files Browse the repository at this point in the history
Cache minimal data
  • Loading branch information
kubevirt-bot authored Aug 12, 2024
2 parents 31dd1cd + 640b69b commit ae2d7b3
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -186,3 +188,23 @@ 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,
}
newPod.Spec = corev1.PodSpec{}
newPod.Status = corev1.PodStatus{}

return newPod, nil
}

0 comments on commit ae2d7b3

Please sign in to comment.