Skip to content

Commit

Permalink
Merge pull request #118 from XIAOMI-CloudNative/feat/show-nodename
Browse files Browse the repository at this point in the history
Display hostName other than podName
  • Loading branch information
seeker89 committed Apr 14, 2022
2 parents 79bb860 + 7609a3a commit a461b0f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
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

0 comments on commit a461b0f

Please sign in to comment.