Skip to content

Commit

Permalink
use default gw ip
Browse files Browse the repository at this point in the history
  • Loading branch information
paulyufan2 committed Jan 22, 2025
1 parent 91847f5 commit a3053a8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
15 changes: 9 additions & 6 deletions cns/middlewares/k8sSwiftV2_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import (
"github.com/pkg/errors"
)

const (
defaultGateway = "0.0.0.0"
)

// for AKS L1VH, do not set default route on infraNIC to avoid customer pod reaching all infra vnet services
// default route is set for secondary interface NIC(i.e,delegatedNIC)
func (k *K8sSWIFTv2Middleware) setRoutes(podIPInfo *cns.PodIpInfo) error {
Expand All @@ -19,7 +23,7 @@ func (k *K8sSWIFTv2Middleware) setRoutes(podIPInfo *cns.PodIpInfo) error {
// TODO: Remove this once HNS fix is ready
route := cns.Route{
IPAddress: "0.0.0.0/0",
GatewayIPAddress: "0.0.0.0",
GatewayIPAddress: defaultGateway,
}
podIPInfo.Routes = append(podIPInfo.Routes, route)

Expand Down Expand Up @@ -69,16 +73,15 @@ func (k *K8sSWIFTv2Middleware) addDefaultRoute(podIPInfo *cns.PodIpInfo, gateway
podIPInfo.Routes = append(podIPInfo.Routes, route)
}

// add routes to podIPInfo for the given CIDRs and gateway IP
// always use default gateway IP for containerd to configure routes;
// containerd will set route with default gateway ip like 10.0.0.0/16 via 0.0.0.0 dev eth0
func (k *K8sSWIFTv2Middleware) addRoutes(cidrs []string) []cns.Route {
routes := make([]cns.Route, len(cidrs))
for i, cidr := range cidrs {
ip, _, err := net.ParseCIDR(cidr)
if err != nil {
return nil
}
routes[i] = cns.Route{
IPAddress: cidr,
GatewayIPAddress: ip.String(),
GatewayIPAddress: defaultGateway,
}
}
return routes
Expand Down
10 changes: 1 addition & 9 deletions network/endpoint_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,18 +333,10 @@ func (nw *network) configureHcnEndpoint(epInfo *EndpointInfo) (*hcn.HostComputeE
}

for _, route := range epInfo.Routes {
nextHop := route.Gw.String()
// If the route is for the frontend NIC, the next hop should be empty.
// This is because the containerd does not require next hop to configure route and the expected route entry on lcow should be like:
// 10.224.0.0/12 dev eth0
if epInfo.NICType == cns.NodeNetworkInterfaceFrontendNIC {
nextHop = ""
}
hcnRoute := hcn.Route{
NextHop: nextHop,
NextHop: route.Gw.String(),
DestinationPrefix: route.Dst.String(),
}

hcnEndpoint.Routes = append(hcnEndpoint.Routes, hcnRoute)
}

Expand Down

0 comments on commit a3053a8

Please sign in to comment.