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

remove static route for custom vpc #3647

Merged
merged 1 commit into from
Jan 22, 2024
Merged
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
93 changes: 0 additions & 93 deletions pkg/controller/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -1350,90 +1350,6 @@ func (c *Controller) reconcileCustomVpcBfdStaticRoute(vpcName, subnetName string
return nil
}

func (c *Controller) reconcileCustomVpcAddNormalStaticRoute(vpcName string) error {
// vpc disable bfd and subnet disable ecmp
// use normal type static route, not ecmp
// dst 0.0.0.0 nexthop is external underlay switch gw
// let all subnet access external network based snat

defualtExternalSubnet, err := c.subnetsLister.Get(c.config.ExternalGatewaySwitch)
if err != nil {
klog.Errorf("failed to get default external switch subnet %s: %v", c.config.ExternalGatewaySwitch, err)
return err
}
gatewayV4, gatewayV6 := util.SplitStringIP(defualtExternalSubnet.Spec.Gateway)
cachedVpc, err := c.vpcsLister.Get(vpcName)
if err != nil {
if k8serrors.IsNotFound(err) {
return nil
}
klog.Errorf("failed to get vpc %s, %v", vpcName, err)
return err
}

rtbs := c.getRouteTablesByVpc(cachedVpc)
routeTotal := len(cachedVpc.Spec.StaticRoutes) + len(rtbs)*2
routes := make([]*kubeovnv1.StaticRoute, 0, routeTotal)
v4Exist, v6Exist := false, false
for _, staticRoutes := range rtbs {
for _, route := range staticRoutes {
if route.Policy == kubeovnv1.PolicyDst &&
route.NextHopIP == gatewayV4 &&
route.CIDR == "0.0.0.0/0" {
v4Exist = true
continue
}
if route.Policy == kubeovnv1.PolicyDst &&
route.NextHopIP == gatewayV6 &&
route.CIDR == "::/0" {
v6Exist = true
continue
}
if route.ECMPMode == "" {
// filter ecmp bfd route
klog.Infof("keep exist normal static route %v", route)
routes = append(routes, route)
}
}
}
needUpdate := false
if !v4Exist && gatewayV4 != "" {
klog.Infof("add normal static route v4 nexthop %s", gatewayV4)
routes = append(routes, &kubeovnv1.StaticRoute{
Policy: kubeovnv1.PolicyDst,
CIDR: "0.0.0.0/0",
NextHopIP: gatewayV4,
RouteTable: util.MainRouteTable,
})
needUpdate = true
}

if !v6Exist && gatewayV6 != "" {
klog.Infof("add normal static route v6 nexthop %s", gatewayV6)
routes = append(routes, &kubeovnv1.StaticRoute{
Policy: kubeovnv1.PolicyDst,
CIDR: "::/0",
NextHopIP: gatewayV6,
RouteTable: util.MainRouteTable,
})
needUpdate = true
}

if needUpdate {
vpc := cachedVpc.DeepCopy()
vpc.Spec.StaticRoutes = routes
if _, err = c.config.KubeOvnClient.KubeovnV1().Vpcs().Update(context.Background(), vpc, metav1.UpdateOptions{}); err != nil {
klog.Errorf("failed to update vpc spec static route %s, %v", vpc.Name, err)
return err
}
if err = c.patchVpcBfdStatus(vpc.Name); err != nil {
klog.Errorf("failed to patch vpc %s, %v", vpc.Name, err)
return err
}
}
return nil
}

func (c *Controller) reconcileCustomVpcDelNormalStaticRoute(vpcName string) error {
// normal static route is prior than ecmp bfd static route
// if use ecmp bfd static route, normal static route should not exist
Expand Down Expand Up @@ -1874,15 +1790,6 @@ func (c *Controller) reconcileCustomVpcStaticRoute(subnet *kubeovnv1.Subnet) err
}
}

if vpc.Spec.EnableExternal && (!vpc.Spec.EnableBfd || !subnet.Spec.EnableEcmp) {
// add normal static route
klog.Infof("add normal external static route for enable external vpc %s, subnet %s", vpc.Name, subnet.Name)
if err := c.reconcileCustomVpcAddNormalStaticRoute(vpc.Name); err != nil {
klog.Errorf("failed to reconcile vpc %q bfd static route", vpc.Name)
return err
}
}

if subnet.Spec.Vlan != "" && !subnet.Spec.LogicalGateway && subnet.Spec.U2OInterconnection && subnet.Status.U2OInterconnectionIP != "" {
if err := c.addPolicyRouteForU2OInterconn(subnet); err != nil {
klog.Errorf("failed to add policy route for underlay to overlay subnet interconnection %s %v", subnet.Name, err)
Expand Down
8 changes: 0 additions & 8 deletions pkg/controller/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,14 +590,6 @@ func (c *Controller) handleAddOrUpdateVpc(key string) error {
}
}
}
if !vpc.Spec.EnableBfd {
// auto add normal type static route, if not use ecmp based bfd
klog.Infof("add normal external static route for enable external vpc %s", vpc.Name)
if err := c.reconcileCustomVpcAddNormalStaticRoute(vpc.Name); err != nil {
klog.Errorf("failed to reconcile vpc %q bfd static route", vpc.Name)
return err
}
}
if cachedVpc.Spec.ExtraExternalSubnets != nil {
sort.Strings(vpc.Spec.ExtraExternalSubnets)
}
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/framework/docker/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func ContainerList(filters map[string][]string) ([]types.Container, error) {
f.Add(k, v1)
}
}
return cli.ContainerList(context.Background(), types.ContainerListOptions{All: true, Filters: f})
return cli.ContainerList(context.Background(), container.ListOptions{All: true, Filters: f})
}

func ContainerCreate(name, image, networkName string, cmd []string) (*types.ContainerJSON, error) {
Expand All @@ -49,7 +49,7 @@ func ContainerCreate(name, image, networkName string, cmd []string) (*types.Cont
return nil, err
}

if err = cli.ContainerStart(context.Background(), resp.ID, types.ContainerStartOptions{}); err != nil {
if err = cli.ContainerStart(context.Background(), resp.ID, container.StartOptions{}); err != nil {
return nil, err
}

Expand Down Expand Up @@ -83,5 +83,5 @@ func ContainerRemove(id string) error {
}
defer cli.Close()

return cli.ContainerRemove(context.Background(), id, types.ContainerRemoveOptions{Force: true})
return cli.ContainerRemove(context.Background(), id, container.RemoveOptions{Force: true})
}
Loading