mirror of
https://github.com/bloomberg/goldpinger.git
synced 2026-02-14 18:09:50 +00:00
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 <j4ckstraw@foxmail.com>
This commit is contained in:
@@ -20,10 +20,12 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-openapi/loads"
|
"github.com/go-openapi/loads"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
"k8s.io/client-go/rest"
|
"k8s.io/client-go/rest"
|
||||||
"k8s.io/client-go/tools/clientcmd"
|
"k8s.io/client-go/tools/clientcmd"
|
||||||
@@ -131,6 +133,10 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Fatal("Error getting config ", zap.Error(err))
|
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
|
// create the clientset
|
||||||
clientset, err := kubernetes.NewForConfig(config)
|
clientset, err := kubernetes.NewForConfig(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -107,6 +107,8 @@ func getPodNodeName(p v1.Pod) string {
|
|||||||
func GetAllPods() map[string]*GoldpingerPod {
|
func GetAllPods() map[string]*GoldpingerPod {
|
||||||
timer := GetLabeledKubernetesCallsTimer()
|
timer := GetLabeledKubernetesCallsTimer()
|
||||||
listOpts := metav1.ListOptions{
|
listOpts := metav1.ListOptions{
|
||||||
|
ResourceVersion: "0",
|
||||||
|
|
||||||
LabelSelector: GoldpingerConfig.LabelSelector,
|
LabelSelector: GoldpingerConfig.LabelSelector,
|
||||||
FieldSelector: "status.phase=Running", // only select Running pods, otherwise we will get them before they have IPs
|
FieldSelector: "status.phase=Running", // only select Running pods, otherwise we will get them before they have IPs
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user