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 <zhangzujian.7@gmail.com>
  • Loading branch information
zhangzujian authored Jun 21, 2024
1 parent a11abec commit acf7872
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/util/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"net"
"net/url"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -64,7 +63,18 @@ func ServiceClusterIPs(svc v1.Service) []string {
if len(svc.Spec.ClusterIPs) == 0 && svc.Spec.ClusterIP != v1.ClusterIPNone && svc.Spec.ClusterIP != "" {
return []string{svc.Spec.ClusterIP}
}
return slices.Clone(svc.Spec.ClusterIPs)

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
}

func LabelSelectorNotEquals(key, value string) (labels.Selector, error) {
Expand Down

0 comments on commit acf7872

Please sign in to comment.