Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Add default route on delegatedNIC interface #3109

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions cns/middlewares/k8sSwiftV2_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package middlewares

import (
"github.com/Azure/azure-container-networking/cns"
"github.com/Azure/azure-container-networking/cns/logger"
"github.com/Azure/azure-container-networking/cns/middlewares/utils"
"github.com/Azure/azure-container-networking/crd/multitenancy/api/v1alpha1"
"github.com/pkg/errors"
Expand All @@ -12,7 +11,14 @@ import (
// default route is set for secondary interface NIC(i.e,delegatedNIC)
func (k *K8sSWIFTv2Middleware) setRoutes(podIPInfo *cns.PodIpInfo) error {
if podIPInfo.NICType == cns.InfraNIC {
logger.Printf("[SWIFTv2Middleware] skip setting default route on InfraNIC interface")
// as a workaround, set a default route with gw 0.0.0.0 to avoid HNS setting default route to infraNIC interface
// TODO: Remove this once HNS supports custom routes adding to the pod
route := cns.Route{
IPAddress: "0.0.0.0/0",
GatewayIPAddress: "0.0.0.0",
}
podIPInfo.Routes = append(podIPInfo.Routes, route)

podIPInfo.SkipDefaultRoutes = true
}
return nil
Expand Down Expand Up @@ -40,5 +46,12 @@ func (k *K8sSWIFTv2Middleware) assignSubnetPrefixLengthFields(podIPInfo *cns.Pod
},
GatewayIPAddress: interfaceInfo.GatewayIP,
}
// assign the default route with gateway IP
route := cns.Route{
IPAddress: "0.0.0.0/0",
GatewayIPAddress: interfaceInfo.GatewayIP,
}
podIPInfo.Routes = append(podIPInfo.Routes, route)

return nil
}
16 changes: 15 additions & 1 deletion cns/middlewares/k8sSwiftV2_windows_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package middlewares

import (
"reflect"
"testing"

"github.com/Azure/azure-container-networking/cns"
Expand Down Expand Up @@ -53,16 +54,29 @@ func TestAssignSubnetPrefixSuccess(t *testing.T) {
MacAddress: "12:34:56:78:9a:bc",
}

gatewayIP := "20.240.1.1"
intInfo := v1alpha1.InterfaceInfo{
GatewayIP: "20.240.1.1",
GatewayIP: gatewayIP,
SubnetAddressSpace: "20.240.1.0/16",
}

routes := []cns.Route{
{
IPAddress: "0.0.0.0/0",
GatewayIPAddress: gatewayIP,
},
}

ipInfo := podIPInfo
err := middleware.assignSubnetPrefixLengthFields(&ipInfo, intInfo, ipInfo.PodIPConfig.IPAddress)
assert.Equal(t, err, nil)
// assert that the function for windows modifies all the expected fields with prefix-length
assert.Equal(t, ipInfo.PodIPConfig.PrefixLength, uint8(16))
assert.Equal(t, ipInfo.HostPrimaryIPInfo.Gateway, intInfo.GatewayIP)
assert.Equal(t, ipInfo.HostPrimaryIPInfo.Subnet, intInfo.SubnetAddressSpace)

// compare two slices of routes
if !reflect.DeepEqual(ipInfo.Routes, routes) {
t.Errorf("got '%+v', expected '%+v'", ipInfo.Routes, routes)
}
}
Loading