Skip to content

Commit

Permalink
fix getting service cluster ips (#4206)
Browse files Browse the repository at this point in the history
Signed-off-by: zhangzujian <[email protected]>
  • Loading branch information
zhangzujian committed Jun 21, 2024
1 parent 8761e3c commit b1b7d3b
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions pkg/util/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,19 @@ func GetNodeInternalIP(node v1.Node) (ipv4, ipv6 string) {
}

func ServiceClusterIPs(svc v1.Service) []string {
ips := svc.Spec.ClusterIPs
if len(ips) == 0 && svc.Spec.ClusterIP != v1.ClusterIPNone && svc.Spec.ClusterIP != "" {
ips = []string{svc.Spec.ClusterIP}
if len(svc.Spec.ClusterIPs) == 0 && svc.Spec.ClusterIP != v1.ClusterIPNone && svc.Spec.ClusterIP != "" {
return []string{svc.Spec.ClusterIP}
}

ips := make([]string, 0, len(svc.Spec.ClusterIPs))
for _, ip := range svc.Spec.ClusterIPs {
if net.ParseIP(ip) == nil {
if ip != "" && ip != v1.ClusterIPNone {
klog.Warningf("invalid cluster IP %q for service %s/%s", ip, svc.Namespace, svc.Name)
}
continue
}
ips = append(ips, ip)
}
return ips
}
Expand Down

0 comments on commit b1b7d3b

Please sign in to comment.