From 7612a46029e5dfb199c37e53212c4fbabb095951 Mon Sep 17 00:00:00 2001 From: Blake Date: Tue, 18 Dec 2018 14:41:53 -0800 Subject: [PATCH 1/4] Limit the list of Pod.List calls by namespace On larger clusters with thousands of pods listing all pods is too expensive. Signed-off-by: Blake --- pkg/goldpinger/k8s.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pkg/goldpinger/k8s.go b/pkg/goldpinger/k8s.go index db38c4b..9d01403 100644 --- a/pkg/goldpinger/k8s.go +++ b/pkg/goldpinger/k8s.go @@ -16,14 +16,24 @@ package goldpinger import ( "log" - + "io/ioutil" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -func GetAllPods() map[string]string { +func getNamespace() string { + b, err := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace") + if err != nil { + log.Println("Unable to determine namespace: ", err.Error()) + } + namespace := string(b) + return namespace +} + +func GetAllPods() map[string]string { timer := GetLabeledKubernetesCallsTimer() - pods, err := GoldpingerConfig.KubernetesClient.CoreV1().Pods("").List(metav1.ListOptions{LabelSelector: "app=goldpinger"}) + namespace := getNamespace() + pods, err := GoldpingerConfig.KubernetesClient.CoreV1().Pods(namespace).List(metav1.ListOptions{LabelSelector: "app=goldpinger"}) if err != nil { log.Println("Error getting pods for selector: ", err.Error()) CountError("kubernetes_api") From 63e7820b1d55cf83659fda8102895a57b1aa4662 Mon Sep 17 00:00:00 2001 From: Mikolaj Pawlikowski Date: Wed, 19 Dec 2018 10:27:11 +0000 Subject: [PATCH 2/4] Bump minor version to 1.1.0 Signed-off-by: Mikolaj Pawlikowski --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index cf2aa75..d0eb6f1 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ name ?= goldpinger -version ?= 1.0.2 +version ?= 1.1.0 bin ?= goldpinger pkg ?= "github.com/bloomberg/goldpinger" tag = $(name):$(version) From 8a2d9e6f37bd6c477026760299a3c291b96b7672 Mon Sep 17 00:00:00 2001 From: Mikolaj Pawlikowski Date: Thu, 20 Dec 2018 15:42:47 +0100 Subject: [PATCH 3/4] Fix indentation Signed-off-by: Mikolaj Pawlikowski --- pkg/goldpinger/k8s.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pkg/goldpinger/k8s.go b/pkg/goldpinger/k8s.go index 9d01403..7052c15 100644 --- a/pkg/goldpinger/k8s.go +++ b/pkg/goldpinger/k8s.go @@ -16,18 +16,17 @@ package goldpinger import ( "log" - "io/ioutil" + "io/ioutil" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func getNamespace() string { - b, err := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace") - if err != nil { - log.Println("Unable to determine namespace: ", err.Error()) - } - - namespace := string(b) - return namespace + b, err := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace") + if err != nil { + log.Println("Unable to determine namespace: ", err.Error()) + } + namespace := string(b) + return namespace } func GetAllPods() map[string]string { From 5bad42922e4f491829096a8e7d58386b647f5f36 Mon Sep 17 00:00:00 2001 From: Mikolaj Pawlikowski Date: Thu, 20 Dec 2018 18:03:17 +0100 Subject: [PATCH 4/4] Explicitly return empty string on error reading namespace Signed-off-by: Mikolaj Pawlikowski --- pkg/goldpinger/k8s.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/goldpinger/k8s.go b/pkg/goldpinger/k8s.go index 7052c15..eb2c362 100644 --- a/pkg/goldpinger/k8s.go +++ b/pkg/goldpinger/k8s.go @@ -24,6 +24,7 @@ func getNamespace() string { b, err := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace") if err != nil { log.Println("Unable to determine namespace: ", err.Error()) + return "" } namespace := string(b) return namespace