mirror of
https://github.com/bloomberg/goldpinger.git
synced 2026-02-26 07:43:48 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5cc9bd55ad | ||
|
|
72832bcbc4 | ||
|
|
a461b0ffd5 | ||
|
|
7609a3ab3f | ||
|
|
588c1a0173 |
@@ -32,6 +32,7 @@ var GoldpingerConfig = struct {
|
||||
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"`
|
||||
Namespace *string `long:"namespace" description:"namespace to use to discover goldpinger pods in the cluster (empty for all). Defaults to discovering the namespace for the current pod" env:"NAMESPACE"`
|
||||
DisplayNodeName bool `long:"display-nodename" description:"Display nodename other than podname in UI (defaults is podname)." env:"DISPLAY_NODENAME"`
|
||||
KubernetesClient *kubernetes.Clientset
|
||||
|
||||
DnsHosts []string `long:"host-to-resolve" description:"A host to attempt dns resolve on (space delimited)" env:"HOSTS_TO_RESOLVE" env-delim:" "`
|
||||
|
||||
@@ -16,8 +16,9 @@ package goldpinger
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go.uber.org/zap"
|
||||
"io/ioutil"
|
||||
|
||||
"go.uber.org/zap"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
k8snet "k8s.io/utils/net"
|
||||
@@ -93,6 +94,14 @@ func getPodIP(p v1.Pod) string {
|
||||
return podIP
|
||||
}
|
||||
|
||||
func getPodNodeName(p v1.Pod) string {
|
||||
if GoldpingerConfig.DisplayNodeName {
|
||||
return p.Spec.NodeName
|
||||
}
|
||||
|
||||
return p.Name
|
||||
}
|
||||
|
||||
// GetAllPods returns a mapping from a pod name to a pointer to a GoldpingerPod(s)
|
||||
func GetAllPods() map[string]*GoldpingerPod {
|
||||
timer := GetLabeledKubernetesCallsTimer()
|
||||
@@ -111,7 +120,7 @@ func GetAllPods() map[string]*GoldpingerPod {
|
||||
podMap := make(map[string]*GoldpingerPod)
|
||||
for _, pod := range pods.Items {
|
||||
podMap[pod.Name] = &GoldpingerPod{
|
||||
Name: pod.Name,
|
||||
Name: getPodNodeName(pod),
|
||||
PodIP: getPodIP(pod),
|
||||
HostIP: getHostIP(pod),
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ var checkResultsMux = sync.Mutex{}
|
||||
// - there is already a pinger with the same name
|
||||
// - the pinger has the same podIP
|
||||
// - the pinger has the same hostIP
|
||||
func exists(existingPods map[string]*GoldpingerPod, new *GoldpingerPod) bool {
|
||||
old, exists := existingPods[new.Name]
|
||||
func exists(existingPods map[string]*GoldpingerPod, podName string, new *GoldpingerPod) bool {
|
||||
old, exists := existingPods[podName]
|
||||
return exists && (old.PodIP == new.PodIP) && (old.HostIP == new.HostIP)
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ func updatePingers(resultsChan chan<- PingAllPodsResult) {
|
||||
|
||||
latest := SelectPods()
|
||||
for podName, pod := range latest {
|
||||
if exists(existingPods, pod) {
|
||||
if exists(existingPods, podName, pod) {
|
||||
// This pod continues to exist in the latest iteration of the update
|
||||
// without any changes
|
||||
// Delete it from the set of pods that we wish to delete
|
||||
|
||||
Reference in New Issue
Block a user