From d4c3422a85ccfe2f00218e88050d072df2e50577 Mon Sep 17 00:00:00 2001 From: Brad Davidson Date: Mon, 22 Jul 2024 23:20:49 +0000 Subject: [PATCH] Fix ipv6 sysctl required by non-ipv6 LoadBalancer service This is a partial revert of 095ecdb0346c038b0c16c39f6f66ad4f67ad10b9, with the workaround moved into klipper-lb. Signed-off-by: Brad Davidson --- pkg/cloudprovider/servicelb.go | 24 +++++++++++++----------- scripts/airgap/image-list.txt | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/pkg/cloudprovider/servicelb.go b/pkg/cloudprovider/servicelb.go index 51adb8bc9a8f..9a0a1ea5e56c 100644 --- a/pkg/cloudprovider/servicelb.go +++ b/pkg/cloudprovider/servicelb.go @@ -52,7 +52,7 @@ const ( ) var ( - DefaultLBImage = "rancher/klipper-lb:v0.4.7" + DefaultLBImage = "rancher/klipper-lb:v0.4.9" ) func (k *k3s) Register(ctx context.Context, @@ -437,12 +437,19 @@ func (k *k3s) newDaemonSet(svc *core.Service) (*apps.DaemonSet, error) { return nil, err } sourceRanges := strings.Join(sourceRangesSet.StringSlice(), ",") + securityContext := &core.PodSecurityContext{} for _, ipFamily := range svc.Spec.IPFamilies { - if ipFamily == core.IPv6Protocol && sourceRanges == "0.0.0.0/0" { - // The upstream default load-balancer source range only includes IPv4, even if the service is IPv6-only or dual-stack. - // If using the default range, and IPv6 is enabled, also allow IPv6. - sourceRanges += ",::/0" + switch ipFamily { + case core.IPv4Protocol: + securityContext.Sysctls = append(securityContext.Sysctls, core.Sysctl{Name: "net.ipv4.ip_forward", Value: "1"}) + case core.IPv6Protocol: + securityContext.Sysctls = append(securityContext.Sysctls, core.Sysctl{Name: "net.ipv6.conf.all.forwarding", Value: "1"}) + if sourceRanges == "0.0.0.0/0" { + // The upstream default load-balancer source range only includes IPv4, even if the service is IPv6-only or dual-stack. + // If using the default range, and IPv6 is enabled, also allow IPv6. + sourceRanges += ",::/0" + } } } @@ -478,12 +485,7 @@ func (k *k3s) newDaemonSet(svc *core.Service) (*apps.DaemonSet, error) { PriorityClassName: priorityClassName, ServiceAccountName: "svclb", AutomountServiceAccountToken: utilsptr.To(false), - SecurityContext: &core.PodSecurityContext{ - Sysctls: []core.Sysctl{ - {Name: "net.ipv4.ip_forward", Value: "1"}, - {Name: "net.ipv6.conf.all.forwarding", Value: "1"}, - }, - }, + SecurityContext: securityContext, Tolerations: []core.Toleration{ { Key: util.MasterRoleLabelKey, diff --git a/scripts/airgap/image-list.txt b/scripts/airgap/image-list.txt index 407d1b55a5e3..02240eee0cbf 100644 --- a/scripts/airgap/image-list.txt +++ b/scripts/airgap/image-list.txt @@ -1,5 +1,5 @@ docker.io/rancher/klipper-helm:v0.8.4-build20240523 -docker.io/rancher/klipper-lb:v0.4.7 +docker.io/rancher/klipper-lb:v0.4.9 docker.io/rancher/local-path-provisioner:v0.0.28 docker.io/rancher/mirrored-coredns-coredns:1.10.1 docker.io/rancher/mirrored-library-busybox:1.36.1