Skip to content

Commit acf7872

Browse files
authored
fix getting service cluster ips (kubeovn#4206)
Signed-off-by: zhangzujian <[email protected]>
1 parent a11abec commit acf7872

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Diff for: pkg/util/k8s.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"net"
66
"net/url"
7-
"slices"
87
"strings"
98
"time"
109

@@ -64,7 +63,18 @@ func ServiceClusterIPs(svc v1.Service) []string {
6463
if len(svc.Spec.ClusterIPs) == 0 && svc.Spec.ClusterIP != v1.ClusterIPNone && svc.Spec.ClusterIP != "" {
6564
return []string{svc.Spec.ClusterIP}
6665
}
67-
return slices.Clone(svc.Spec.ClusterIPs)
66+
67+
ips := make([]string, 0, len(svc.Spec.ClusterIPs))
68+
for _, ip := range svc.Spec.ClusterIPs {
69+
if net.ParseIP(ip) == nil {
70+
if ip != "" && ip != v1.ClusterIPNone {
71+
klog.Warningf("invalid cluster IP %q for service %s/%s", ip, svc.Namespace, svc.Name)
72+
}
73+
continue
74+
}
75+
ips = append(ips, ip)
76+
}
77+
return ips
6878
}
6979

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

0 commit comments

Comments
 (0)