Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display hostName other than podName #118

Merged
merged 2 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/goldpinger/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:" "`
Expand Down
13 changes: 11 additions & 2 deletions pkg/goldpinger/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand All @@ -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),
}
Expand Down