Commit cf82b403 authored by Brad Davidson's avatar Brad Davidson Committed by Brad Davidson

Add ServiceLB support for PodHostIPs FeatureGate

If the feature-gate is enabled, use status.hostIPs for dual-stack externalTrafficPolicy=Local support Signed-off-by: 's avatarBrad Davidson <brad.davidson@rancher.com> (cherry picked from commit a27d660a) Signed-off-by: 's avatarBrad Davidson <brad.davidson@rancher.com>
parent a70399b0
...@@ -47,7 +47,7 @@ const ( ...@@ -47,7 +47,7 @@ const (
) )
var ( var (
DefaultLBImage = "rancher/klipper-lb:v0.4.4" DefaultLBImage = "rancher/klipper-lb:v0.4.5"
) )
func (k *k3s) Register(ctx context.Context, func (k *k3s) Register(ctx context.Context,
...@@ -435,10 +435,11 @@ func (k *k3s) newDaemonSet(svc *core.Service) (*apps.DaemonSet, error) { ...@@ -435,10 +435,11 @@ func (k *k3s) newDaemonSet(svc *core.Service) (*apps.DaemonSet, error) {
name := generateName(svc) name := generateName(svc)
oneInt := intstr.FromInt(1) oneInt := intstr.FromInt(1)
localTraffic := servicehelper.RequestsOnlyLocalTraffic(svc) localTraffic := servicehelper.RequestsOnlyLocalTraffic(svc)
sourceRanges, err := servicehelper.GetLoadBalancerSourceRanges(svc) sourceRangesSet, err := servicehelper.GetLoadBalancerSourceRanges(svc)
if err != nil { if err != nil {
return nil, err return nil, err
} }
sourceRanges := strings.Join(sourceRangesSet.StringSlice(), ",")
var sysctls []core.Sysctl var sysctls []core.Sysctl
for _, ipFamily := range svc.Spec.IPFamilies { for _, ipFamily := range svc.Spec.IPFamilies {
...@@ -447,6 +448,11 @@ func (k *k3s) newDaemonSet(svc *core.Service) (*apps.DaemonSet, error) { ...@@ -447,6 +448,11 @@ func (k *k3s) newDaemonSet(svc *core.Service) (*apps.DaemonSet, error) {
sysctls = append(sysctls, core.Sysctl{Name: "net.ipv4.ip_forward", Value: "1"}) sysctls = append(sysctls, core.Sysctl{Name: "net.ipv4.ip_forward", Value: "1"})
case core.IPv6Protocol: case core.IPv6Protocol:
sysctls = append(sysctls, core.Sysctl{Name: "net.ipv6.conf.all.forwarding", Value: "1"}) sysctls = append(sysctls, core.Sysctl{Name: "net.ipv6.conf.all.forwarding", Value: "1"})
// 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.
if sourceRanges == "0.0.0.0/0" {
sourceRanges += ",::/0"
}
} }
} }
...@@ -532,7 +538,7 @@ func (k *k3s) newDaemonSet(svc *core.Service) (*apps.DaemonSet, error) { ...@@ -532,7 +538,7 @@ func (k *k3s) newDaemonSet(svc *core.Service) (*apps.DaemonSet, error) {
}, },
{ {
Name: "SRC_RANGES", Name: "SRC_RANGES",
Value: strings.Join(sourceRanges.StringSlice(), " "), Value: sourceRanges,
}, },
{ {
Name: "DEST_PROTO", Name: "DEST_PROTO",
...@@ -558,7 +564,7 @@ func (k *k3s) newDaemonSet(svc *core.Service) (*apps.DaemonSet, error) { ...@@ -558,7 +564,7 @@ func (k *k3s) newDaemonSet(svc *core.Service) (*apps.DaemonSet, error) {
Name: "DEST_IPS", Name: "DEST_IPS",
ValueFrom: &core.EnvVarSource{ ValueFrom: &core.EnvVarSource{
FieldRef: &core.ObjectFieldSelector{ FieldRef: &core.ObjectFieldSelector{
FieldPath: "status.hostIP", FieldPath: getHostIPsFieldPath(),
}, },
}, },
}, },
...@@ -571,7 +577,7 @@ func (k *k3s) newDaemonSet(svc *core.Service) (*apps.DaemonSet, error) { ...@@ -571,7 +577,7 @@ func (k *k3s) newDaemonSet(svc *core.Service) (*apps.DaemonSet, error) {
}, },
core.EnvVar{ core.EnvVar{
Name: "DEST_IPS", Name: "DEST_IPS",
Value: strings.Join(svc.Spec.ClusterIPs, " "), Value: strings.Join(svc.Spec.ClusterIPs, ","),
}, },
) )
} }
...@@ -703,3 +709,7 @@ func ingressToString(ingresses []core.LoadBalancerIngress) []string { ...@@ -703,3 +709,7 @@ func ingressToString(ingresses []core.LoadBalancerIngress) []string {
} }
return parts return parts
} }
func getHostIPsFieldPath() string {
return "status.hostIP"
}
docker.io/rancher/klipper-helm:v0.8.2-build20230815 docker.io/rancher/klipper-helm:v0.8.2-build20230815
docker.io/rancher/klipper-lb:v0.4.4 docker.io/rancher/klipper-lb:v0.4.5
docker.io/rancher/local-path-provisioner:v0.0.24 docker.io/rancher/local-path-provisioner:v0.0.24
docker.io/rancher/mirrored-coredns-coredns:1.10.1 docker.io/rancher/mirrored-coredns-coredns:1.10.1
docker.io/rancher/mirrored-library-busybox:1.36.1 docker.io/rancher/mirrored-library-busybox:1.36.1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment