From ef300d5ca2ef2ec169b01f90a920e05762b73ca6 Mon Sep 17 00:00:00 2001 From: Tyler Lloyd Date: Wed, 23 Mar 2022 16:01:35 +0000 Subject: [PATCH 1/4] cleanup IPv6 references only check node IPs when determining hostIP IP_VERSIONS not IP_FAMILIES Signed-off-by: Tyler Lloyd --- README.md | 2 +- pkg/goldpinger/k8s.go | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 181aad2..1ad76a7 100644 --- a/README.md +++ b/README.md @@ -231,7 +231,7 @@ You can also see [an example of using `kubeconfig` in the `./extras`](./extras/e ### Using with IPv4/IPv6 dual-stack -If your pods having IPv4 and IPv6 addresses assigned and you want to test communication over IPv6, you can specify the `USE_IPV6` environment variable which will use the IPv6 address on the pod and host. +If your cluster IPv4/IPv6 dual-stack and you want to force IPv6, you can set the `IP_VERSIONS` environment variable to "6" (default is "4") which will use the IPv6 address on the pod and host. ![ipv6](./extras/screenshot-ipv6.png) diff --git a/pkg/goldpinger/k8s.go b/pkg/goldpinger/k8s.go index 3643a75..96dd67d 100644 --- a/pkg/goldpinger/k8s.go +++ b/pkg/goldpinger/k8s.go @@ -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" @@ -68,7 +69,8 @@ func getHostIP(p v1.Pod) string { var hostIP string for _, addr := range node.Status.Addresses { - if ipMatchesConfig(addr.Address) { + if (addr.Type == v1.NodeInternalIP || addr.Type == v1.NodeExternalIP) && + ipMatchesConfig(addr.Address) { hostIP = addr.Address } } From 588c1a017303b765fa3f513bc83e1397c1ba3a99 Mon Sep 17 00:00:00 2001 From: wanglijie6 Date: Fri, 8 Apr 2022 18:59:40 +0800 Subject: [PATCH 2/4] Show hostName other than podName Signed-off-by: wanglijie6 --- pkg/goldpinger/k8s.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/goldpinger/k8s.go b/pkg/goldpinger/k8s.go index 3643a75..33f340f 100644 --- a/pkg/goldpinger/k8s.go +++ b/pkg/goldpinger/k8s.go @@ -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 p.Spec.NodeName != "" { + 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), } From 7609a3ab3f36e52ff54045ac21e4991f58dbddec Mon Sep 17 00:00:00 2001 From: wanglijie6 Date: Wed, 13 Apr 2022 10:51:51 +0800 Subject: [PATCH 3/4] Add --display-nodename option to control UI display Add GoldpingerConfig.DisplayNodeName to control UI display, default is `false`, which means to display podName Signed-off-by: wanglijie6 --- pkg/goldpinger/config.go | 1 + pkg/goldpinger/k8s.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/goldpinger/config.go b/pkg/goldpinger/config.go index dba0dfb..b71da60 100644 --- a/pkg/goldpinger/config.go +++ b/pkg/goldpinger/config.go @@ -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:" "` diff --git a/pkg/goldpinger/k8s.go b/pkg/goldpinger/k8s.go index 33f340f..7b323be 100644 --- a/pkg/goldpinger/k8s.go +++ b/pkg/goldpinger/k8s.go @@ -95,7 +95,7 @@ func getPodIP(p v1.Pod) string { } func getPodNodeName(p v1.Pod) string { - if p.Spec.NodeName != "" { + if GoldpingerConfig.DisplayNodeName { return p.Spec.NodeName } From 72832bcbc4e20b55ee2679cd9f51cf7ad2d7435b Mon Sep 17 00:00:00 2001 From: wanglijie6 Date: Fri, 15 Apr 2022 19:06:11 +0800 Subject: [PATCH 4/4] Fix pinger be removed by not found. heatmap will be broken in every refeshPeriod, I found pinger is be deleted because of exists check faild. updatePingers will check if a pod still exist or a new one, and update pingers in every refreshPeriod. the function exists failed to check pod exist, so fix it. Signed-off-by: wanglijie6 --- pkg/goldpinger/updater.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/goldpinger/updater.go b/pkg/goldpinger/updater.go index ea8834c..c538d43 100644 --- a/pkg/goldpinger/updater.go +++ b/pkg/goldpinger/updater.go @@ -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