mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-17 20:00:07 +00:00
fix(kube-proxy) avoid add zero-masked loadBalancerSourceRanges to ipset
Signed-off-by: roc <roc@imroc.cc>
This commit is contained in:
@@ -68,7 +68,7 @@ func NewNodePortAddresses(family v1.IPFamily, cidrStrings []string) *NodePortAdd
|
||||
}
|
||||
}
|
||||
|
||||
if IsZeroCIDR(str) {
|
||||
if IsZeroCIDR(cidr) {
|
||||
// Ignore everything else
|
||||
npa.cidrs = []*net.IPNet{cidr}
|
||||
npa.matchAll = true
|
||||
|
||||
@@ -45,11 +45,12 @@ const (
|
||||
|
||||
// IsZeroCIDR checks whether the input CIDR string is either
|
||||
// the IPv4 or IPv6 zero CIDR
|
||||
func IsZeroCIDR(cidr string) bool {
|
||||
if cidr == IPv4ZeroCIDR || cidr == IPv6ZeroCIDR {
|
||||
return true
|
||||
func IsZeroCIDR(cidr *net.IPNet) bool {
|
||||
if cidr == nil {
|
||||
return false
|
||||
}
|
||||
return false
|
||||
prefixLen, _ := cidr.Mask.Size()
|
||||
return prefixLen == 0
|
||||
}
|
||||
|
||||
// ShouldSkipService checks if a given service should skip proxying
|
||||
|
||||
@@ -682,7 +682,8 @@ func TestIsZeroCIDR(t *testing.T) {
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if got := IsZeroCIDR(tc.input); tc.expected != got {
|
||||
_, cidr, _ := netutils.ParseCIDRSloppy(tc.input)
|
||||
if got := IsZeroCIDR(cidr); tc.expected != got {
|
||||
t.Errorf("IsZeroCIDR() = %t, want %t", got, tc.expected)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user