diff --git a/cni/network/invoker_cns.go b/cni/network/invoker_cns.go index 78a0907a44..02e0ce7351 100644 --- a/cni/network/invoker_cns.go +++ b/cni/network/invoker_cns.go @@ -362,7 +362,7 @@ func getRoutes(cnsRoutes []cns.Route, skipDefaultRoutes bool) ([]network.RouteIn } gw := net.ParseIP(route.GatewayIPAddress) - if skipDefaultRoutes { + if gw == nil && skipDefaultRoutes { return nil, errors.Wrap(errInvalidGatewayIP, route.GatewayIPAddress) } diff --git a/cns/middlewares/k8sSwiftV2_windows.go b/cns/middlewares/k8sSwiftV2_windows.go index 005ba02755..28f7d6d1b8 100644 --- a/cns/middlewares/k8sSwiftV2_windows.go +++ b/cns/middlewares/k8sSwiftV2_windows.go @@ -71,9 +71,13 @@ func (k *K8sSWIFTv2Middleware) addDefaultRoute(podIPInfo *cns.PodIpInfo, gateway 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 "", errors.Wrap(err, "failed to parse cidr") + } routes[i] = cns.Route{ IPAddress: cidr, - GatewayIPAddress: "", // gateway IP is not required for infraNIC routes + GatewayIPAddress: ip.String(), } } return routes