From 4cddd3b5f8a5690892abc83847e1003a0711c70b Mon Sep 17 00:00:00 2001 From: Ted Wexler Date: Thu, 20 Dec 2018 14:52:09 +0000 Subject: [PATCH 1/2] Use a configuration value for the label selector when discovering goldpinger pods Signed-off-by: Ted Wexler --- pkg/goldpinger/config.go | 1 + pkg/goldpinger/k8s.go | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/goldpinger/config.go b/pkg/goldpinger/config.go index 04e18d2..b15bff9 100644 --- a/pkg/goldpinger/config.go +++ b/pkg/goldpinger/config.go @@ -26,5 +26,6 @@ var GoldpingerConfig = struct { Hostname string `long:"hostname" description:"Hostname to use" env:"HOSTNAME"` Port int `long:"client-port-override" description:"(for testing) use this port when calling other instances" env:"CLIENT_PORT_OVERRIDE"` UseHostIP bool `long:"use-host-ip" description:"When making the calls, use host ip (defaults to pod ip)" env:"USE_HOST_IP"` + LabelSelector string `long:"label-selector" description:"label selector to use to discover goldpinger pods in the cluster" env:"LABEL_SELECTOR" default:"app=goldpinger"` KubernetesClient *kubernetes.Clientset }{} diff --git a/pkg/goldpinger/k8s.go b/pkg/goldpinger/k8s.go index db38c4b..a899a87 100644 --- a/pkg/goldpinger/k8s.go +++ b/pkg/goldpinger/k8s.go @@ -20,10 +20,11 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) +// GetAllPods returns a map of Pod IP to Host IP based on a label selector defined in config func GetAllPods() map[string]string { timer := GetLabeledKubernetesCallsTimer() - pods, err := GoldpingerConfig.KubernetesClient.CoreV1().Pods("").List(metav1.ListOptions{LabelSelector: "app=goldpinger"}) + pods, err := GoldpingerConfig.KubernetesClient.CoreV1().Pods("").List(metav1.ListOptions{LabelSelector: GoldpingerConfig.LabelSelector}) if err != nil { log.Println("Error getting pods for selector: ", err.Error()) CountError("kubernetes_api") From 38f409b7bd1136a7404a35ec64dfa3055d859989 Mon Sep 17 00:00:00 2001 From: Ted Wexler Date: Thu, 20 Dec 2018 12:23:45 -0500 Subject: [PATCH 2/2] Fix merge issue Signed-off-by: Ted Wexler --- pkg/goldpinger/k8s.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/goldpinger/k8s.go b/pkg/goldpinger/k8s.go index d66249b..c3015c2 100644 --- a/pkg/goldpinger/k8s.go +++ b/pkg/goldpinger/k8s.go @@ -33,7 +33,7 @@ func getNamespace() string { // GetAllPods returns a map of Pod IP to Host IP based on a label selector defined in config func GetAllPods() map[string]string { timer := GetLabeledKubernetesCallsTimer() - pods, err := GoldpingerConfig.KubernetesClient.CoreV1().Pods(namespace).List(metav1.ListOptions{LabelSelector: GoldpingerConfig.LabelSelector}) + pods, err := GoldpingerConfig.KubernetesClient.CoreV1().Pods(getNamespace()).List(metav1.ListOptions{LabelSelector: GoldpingerConfig.LabelSelector}) if err != nil { log.Println("Error getting pods for selector: ", err.Error()) CountError("kubernetes_api")