Skip to content

Commit

Permalink
fix(dsr): add family specific link inside pod
Browse files Browse the repository at this point in the history
For IPv6 we need to have family specific links inside the pod to receive
the ip6ip6 and ipip traffic that we are sending.
  • Loading branch information
aauren committed Oct 7, 2023
1 parent 514a8af commit 1a891c3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
37 changes: 23 additions & 14 deletions pkg/controllers/proxy/linux_networking.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,22 @@ func (ln *linuxNetworking) prepareEndpointForDsrWithCRI(runtimeEndpoint, contain

func (ln *linuxNetworking) configureContainerForDSR(
vip, endpointIP, containerID string, pid int, hostNetworkNamespaceHandle netns.NsHandle) error {
var ipTunLink netlink.Link
parsedEIP := net.ParseIP(endpointIP)
if parsedEIP == nil {
return fmt.Errorf("failed to parse endpoint IP %s", endpointIP)
}
if parsedEIP.To4() != nil {
ipTunLink = &netlink.Iptun{
LinkAttrs: netlink.LinkAttrs{Name: KubeTunnelIfv4},
Local: parsedEIP,
}
} else {
ipTunLink = &netlink.Ip6tnl{
LinkAttrs: netlink.LinkAttrs{Name: KubeTunnelIfv6},
Local: parsedEIP,
}
}
endpointNamespaceHandle, err := netns.GetFromPid(pid)
if err != nil {
return fmt.Errorf("failed to get endpoint namespace (containerID=%s, pid=%d, error=%v)",
Expand All @@ -665,11 +681,8 @@ func (ln *linuxNetworking) configureContainerForDSR(
activeNetworkNamespaceHandle.String())
_ = activeNetworkNamespaceHandle.Close()

// TODO: fix boilerplate `netns.Set(hostNetworkNamespaceHandle)` code. Need a robust
// way to switch back to old namespace, pretty much all things will go wrong if we dont switch back

// create an ipip tunnel interface inside the endpoint container
tunIf, err := netlink.LinkByName(KubeTunnelIf)
tunIf, err := netlink.LinkByName(ipTunLink.Attrs().Name)
if err != nil {
if err.Error() != IfaceNotFound {
attemptNamespaceResetAfterError(hostNetworkNamespaceHandle)
Expand All @@ -678,12 +691,8 @@ func (ln *linuxNetworking) configureContainerForDSR(
}

klog.V(2).Infof("Could not find tunnel interface %s in endpoint %s so creating one.",
KubeTunnelIf, endpointIP)
ipTunLink := netlink.Iptun{
LinkAttrs: netlink.LinkAttrs{Name: KubeTunnelIf},
Local: net.ParseIP(endpointIP),
}
err = netlink.LinkAdd(&ipTunLink)
ipTunLink.Attrs().Name, endpointIP)
err = netlink.LinkAdd(ipTunLink)
if err != nil {
attemptNamespaceResetAfterError(hostNetworkNamespaceHandle)
return fmt.Errorf("failed to add ipip tunnel interface in endpoint namespace due to %v", err)
Expand All @@ -692,13 +701,13 @@ func (ln *linuxNetworking) configureContainerForDSR(
// this is ugly, but ran into issue multiple times where interface did not come up quickly.
for retry := 0; retry < 60; retry++ {
time.Sleep(interfaceWaitSleepTime)
tunIf, err = netlink.LinkByName(KubeTunnelIf)
tunIf, err = netlink.LinkByName(ipTunLink.Attrs().Name)
if err == nil {
break
}
if err.Error() == IfaceNotFound {
klog.V(3).Infof("Waiting for tunnel interface %s to come up in the pod, retrying",
KubeTunnelIf)
ipTunLink.Attrs().Name)
continue
} else {
break
Expand All @@ -707,11 +716,11 @@ func (ln *linuxNetworking) configureContainerForDSR(

if err != nil {
attemptNamespaceResetAfterError(hostNetworkNamespaceHandle)
return fmt.Errorf("failed to get %s tunnel interface handle due to %v", KubeTunnelIf, err)
return fmt.Errorf("failed to get %s tunnel interface handle due to %v", ipTunLink.Attrs().Name, err)
}

klog.V(2).Infof("Successfully created tunnel interface %s in endpoint %s.",
KubeTunnelIf, endpointIP)
ipTunLink.Attrs().Name, endpointIP)
}

// bring the tunnel interface up
Expand Down
3 changes: 2 additions & 1 deletion pkg/controllers/proxy/network_services_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import (

const (
KubeDummyIf = "kube-dummy-if"
KubeTunnelIf = "kube-tunnel-if"
KubeTunnelIfv4 = "kube-tunnel-if"
KubeTunnelIfv6 = "kube-tunnel-v6"
IfaceNotFound = "Link not found"
IfaceHasAddr = "file exists"
IfaceHasNoAddr = "cannot assign requested address"
Expand Down

0 comments on commit 1a891c3

Please sign in to comment.