Updating kube-proxy to trim space from loadBalancerSourceRanges

Before this fix, a Service with a loadBalancerSourceRange value that
included a space would cause kube-proxy to crashloop. This updates
kube-proxy to trim any space from that field.
This commit is contained in:
Rob Scott
2020-08-19 12:30:49 -07:00
parent 544b74c2cb
commit c382c79f60
4 changed files with 60 additions and 23 deletions

View File

@@ -1183,9 +1183,10 @@ func (proxier *Proxier) syncProxyRules() {
allowFromNode := false
for _, src := range svcInfo.LoadBalancerSourceRanges() {
writeLine(proxier.natRules, append(args, "-s", src, "-j", string(chosenChain))...)
// ignore error because it has been validated
_, cidr, _ := net.ParseCIDR(src)
if cidr.Contains(proxier.nodeIP) {
_, cidr, err := net.ParseCIDR(src)
if err != nil {
klog.Errorf("Error parsing %s CIDR in LoadBalancerSourceRanges, dropping: %v", cidr, err)
} else if cidr.Contains(proxier.nodeIP) {
allowFromNode = true
}
}

View File

@@ -687,6 +687,10 @@ func TestLoadBalancer(t *testing.T) {
svc.Status.LoadBalancer.Ingress = []v1.LoadBalancerIngress{{
IP: svcLBIP,
}}
// Also ensure that invalid LoadBalancerSourceRanges will not result
// in a crash.
svc.Spec.ExternalIPs = []string{svcLBIP}
svc.Spec.LoadBalancerSourceRanges = []string{" 1.2.3.4/28"}
}),
)