From acac9dee8b7ddcdb969a466674736b6d48c2a5ed Mon Sep 17 00:00:00 2001 From: j4ckstraw Date: Sat, 17 Jun 2023 15:56:47 +0800 Subject: [PATCH 1/2] use protobuf and add resourceVersion in listOption 1. communicate to kube-apiserver with protobuf 2. listOption add resourceVersion=0. without resourceversion, list will force kube-apiserver retrieve data from etcd. In a 100+ nodes, 7500+ pods kubernetes cluster, this patch make kube-apiserver cpu utils reduce 5-10%. Signed-off-by: j4ckstraw --- cmd/goldpinger/main.go | 6 ++++++ pkg/goldpinger/k8s.go | 2 ++ 2 files changed, 8 insertions(+) diff --git a/cmd/goldpinger/main.go b/cmd/goldpinger/main.go index 3a2d002..de02b5c 100644 --- a/cmd/goldpinger/main.go +++ b/cmd/goldpinger/main.go @@ -20,10 +20,12 @@ import ( "io/ioutil" "log" "os" + "strings" "time" "github.com/go-openapi/loads" "go.uber.org/zap" + "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" @@ -131,6 +133,10 @@ func main() { if err != nil { logger.Fatal("Error getting config ", zap.Error(err)) } + // communicate to kube-apiserver with protobuf + config.AcceptContentTypes = strings.Join([]string{runtime.ContentTypeProtobuf, runtime.ContentTypeJSON}, ",") + config.ContentType = runtime.ContentTypeProtobuf + // create the clientset clientset, err := kubernetes.NewForConfig(config) if err != nil { diff --git a/pkg/goldpinger/k8s.go b/pkg/goldpinger/k8s.go index 7227933..0a81582 100644 --- a/pkg/goldpinger/k8s.go +++ b/pkg/goldpinger/k8s.go @@ -107,6 +107,8 @@ func getPodNodeName(p v1.Pod) string { func GetAllPods() map[string]*GoldpingerPod { timer := GetLabeledKubernetesCallsTimer() listOpts := metav1.ListOptions{ + ResourceVersion: "0", + LabelSelector: GoldpingerConfig.LabelSelector, FieldSelector: "status.phase=Running", // only select Running pods, otherwise we will get them before they have IPs } From 507a63d8bc9e49bf82cb6506de5a002b07e61cde Mon Sep 17 00:00:00 2001 From: Sachin Kamboj Date: Mon, 8 Apr 2024 15:41:55 -0400 Subject: [PATCH 2/2] Increment the version Signed-off-by: Sachin Kamboj --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d71055e..66cc6f1 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ name ?= goldpinger -version ?= v3.7.0 +version ?= v3.10.0 bin ?= goldpinger pkg ?= "github.com/bloomberg/goldpinger" tag = $(name):$(version)