Skip to content

Commit

Permalink
Merge branch 'add-external-probes' of https://github.com/kitfoman/gol…
Browse files Browse the repository at this point in the history
…dpinger into add-external-probes
  • Loading branch information
kitfoman committed Apr 20, 2022
2 parents 69708ba + 92b2efd commit 75e0951
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions pkg/goldpinger/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,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:" "`
Expand Down
13 changes: 11 additions & 2 deletions pkg/goldpinger/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,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
}
}
Expand All @@ -94,6 +95,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()
Expand All @@ -112,7 +121,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),
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/goldpinger/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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
Expand Down

0 comments on commit 75e0951

Please sign in to comment.