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 eb2c362..c3015c2 100644 --- a/pkg/goldpinger/k8s.go +++ b/pkg/goldpinger/k8s.go @@ -30,10 +30,10 @@ func getNamespace() string { return namespace } +// 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() - namespace := getNamespace() - pods, err := GoldpingerConfig.KubernetesClient.CoreV1().Pods(namespace).List(metav1.ListOptions{LabelSelector: "app=goldpinger"}) + 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")