mirror of
https://github.com/bloomberg/goldpinger.git
synced 2026-02-14 18:09:50 +00:00
changing to IP_VERSIONS
Signed-off-by: Tyler Lloyd <Tyler.Lloyd@microsoft.com>
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"k8s.io/utils/net"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
@@ -132,6 +133,16 @@ func main() {
|
||||
if goldpinger.GoldpingerConfig.PingNumber == 0 {
|
||||
logger.Info("--ping-number set to 0: pinging all pods")
|
||||
}
|
||||
if goldpinger.GoldpingerConfig.IPVersions == nil || len(goldpinger.GoldpingerConfig.IPVersions) == 0 {
|
||||
logger.Info("IPVersions not set: settings to 4 (IPv4)")
|
||||
goldpinger.GoldpingerConfig.IPVersions = []string{"4"}
|
||||
}
|
||||
if len(goldpinger.GoldpingerConfig.IPVersions) > 1 {
|
||||
logger.Warn("Multiple IP versions not supported. Will use first version specified as default", zap.Strings("IPVersions", goldpinger.GoldpingerConfig.IPVersions))
|
||||
}
|
||||
if goldpinger.GoldpingerConfig.IPVersions[0] != string(net.IPv4) && goldpinger.GoldpingerConfig.IPVersions[0] != net.IPv6 {
|
||||
logger.Error("Unknown IP version specified: expected values are 4 or 6", zap.Strings("IPVersions", goldpinger.GoldpingerConfig.IPVersions))
|
||||
}
|
||||
|
||||
server.ConfigureAPI()
|
||||
goldpinger.StartUpdater()
|
||||
|
||||
@@ -30,13 +30,14 @@ var GoldpingerConfig = struct {
|
||||
PingNumber uint `long:"ping-number" description:"Number of peers to ping. A value of 0 indicates all peers should be pinged." default:"0" env:"PING_NUMBER"`
|
||||
Port int `long:"client-port-override" description:"(for testing) use this port when calling other instances" env:"CLIENT_PORT_OVERRIDE"`
|
||||
UseHostIP bool `long:"use-host-ip" description:"When making the calls, use host ip (defaults to pod ip)" env:"USE_HOST_IP"`
|
||||
UseIPv6 bool `long:"use-ipv6" description:"Will find the IPv6 address on a pod to use for pinging." env:"USE_IPV6"`
|
||||
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"`
|
||||
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:" "`
|
||||
|
||||
IPVersions []string `long:"ip-versions" description:"The IP versions to use (space delimited). Possible values are 4 and 6 (defaults to 4)." env:"IP_VERSIONS" env-delim:" "`
|
||||
|
||||
// Timeouts
|
||||
PingTimeoutMs int64 `long:"ping-timeout-ms" description:"The timeout in milliseconds for a ping call to other goldpinger pods" env:"PING_TIMEOUT_MS" default:"300"`
|
||||
CheckTimeoutMs int64 `long:"check-timeout-ms" description:"The timeout in milliseconds for a check call to other goldpinger pods" env:"CHECK_TIMEOUT_MS" default:"1000"`
|
||||
|
||||
@@ -48,7 +48,7 @@ func getPodNamespace() string {
|
||||
// getHostIP gets the IP of the host where the pod is scheduled. If UseIPv6 is enabled then we need to check
|
||||
// the node IPs since HostIP will only list the default IP version one.
|
||||
func getHostIP(p v1.Pod) string {
|
||||
if !GoldpingerConfig.UseIPv6 || k8snet.IsIPv6String(p.Status.HostIP) {
|
||||
if ipMatchesConfig(p.Status.HostIP) {
|
||||
return p.Status.HostIP
|
||||
}
|
||||
|
||||
@@ -66,31 +66,31 @@ func getHostIP(p v1.Pod) string {
|
||||
timer.ObserveDuration()
|
||||
}
|
||||
|
||||
result := p.Status.HostIP
|
||||
var hostIP string
|
||||
for _, addr := range node.Status.Addresses {
|
||||
if k8snet.IsIPv6String(addr.Address) {
|
||||
result = addr.Address
|
||||
if ipMatchesConfig(addr.Address) {
|
||||
hostIP = addr.Address
|
||||
}
|
||||
}
|
||||
nodeIPMap[p.Spec.NodeName] = result
|
||||
return result
|
||||
nodeIPMap[p.Spec.NodeName] = hostIP
|
||||
return hostIP
|
||||
}
|
||||
|
||||
// getPodIP will get an IPv6 IP from PodIPs if the UseIPv6 config is set, otherwise just return the object PodIP
|
||||
func getPodIP(p v1.Pod) string {
|
||||
if !GoldpingerConfig.UseIPv6 {
|
||||
if ipMatchesConfig(p.Status.PodIP) {
|
||||
return p.Status.PodIP
|
||||
}
|
||||
|
||||
var v6IP string
|
||||
var podIP string
|
||||
if p.Status.PodIPs != nil {
|
||||
for _, ip := range p.Status.PodIPs {
|
||||
if k8snet.IsIPv6String(ip.IP) {
|
||||
v6IP = ip.IP
|
||||
if ipMatchesConfig(ip.IP) {
|
||||
podIP = ip.IP
|
||||
}
|
||||
}
|
||||
}
|
||||
return v6IP
|
||||
return podIP
|
||||
}
|
||||
|
||||
// GetAllPods returns a mapping from a pod name to a pointer to a GoldpingerPod(s)
|
||||
@@ -114,3 +114,23 @@ func GetAllPods() map[string]*GoldpingerPod {
|
||||
}
|
||||
return podMap
|
||||
}
|
||||
|
||||
// ipMatchesConfig checks if the input IP family matches the first entry in the IPVersions config.
|
||||
// TODO update to check all config versions to support dual-stack pinging.
|
||||
func ipMatchesConfig(ip string) bool {
|
||||
ipFamily := getIPFamily(ip)
|
||||
return GoldpingerConfig.IPVersions[0] == ipFamily
|
||||
}
|
||||
|
||||
// getIPFamily returns the IP family of the input IP.
|
||||
// Possible values are 4 and 6.
|
||||
func getIPFamily(ip string) string {
|
||||
if k8snet.IsIPv4String(ip) {
|
||||
return string(k8snet.IPv4)
|
||||
}
|
||||
if k8snet.IsIPv6String(ip) {
|
||||
return k8snet.IPv6
|
||||
}
|
||||
zap.L().Error("Error determining IP family", zap.String("IP", ip))
|
||||
return ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user