From ce094a58528f1a28b6e826ca731f33d165643d5b Mon Sep 17 00:00:00 2001 From: Nikhil-Ladha Date: Wed, 25 Sep 2024 15:45:28 +0530 Subject: [PATCH] util: use protobuf encoding for core k8s apis For core K8s API objects like Pods, Nodes, etc., we can use protobuf encoding which reduces CPU consumption related to (de)serialization, reduces overall latency of the API call, reduces memory footprint, reduces the amount of work performed by the GC and results in quicker propagation of objects to event handlers of shared informers. Signed-off-by: Nikhil-Ladha --- internal/util/k8s/client.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/util/k8s/client.go b/internal/util/k8s/client.go index d5629fee54da..c7731db04e99 100644 --- a/internal/util/k8s/client.go +++ b/internal/util/k8s/client.go @@ -20,6 +20,7 @@ import ( "fmt" "os" + "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" @@ -47,6 +48,7 @@ func NewK8sClient() (*kubernetes.Clientset, error) { return nil, fmt.Errorf("failed to get cluster config: %w", err) } } + cfg.ContentType = runtime.ContentTypeProtobuf client, err := kubernetes.NewForConfig(cfg) if err != nil { return nil, fmt.Errorf("failed to create client: %w", err)