From 005711961cf3b5cc1a11c06558d1b0b9f21d69ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E6=97=A5=E6=98=8E?= Date: Wed, 25 Nov 2020 15:58:28 +0800 Subject: [PATCH] fix: vpc static route manage --- pkg/controller/vpc.go | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/pkg/controller/vpc.go b/pkg/controller/vpc.go index 48229824482..d9b8dbfd652 100644 --- a/pkg/controller/vpc.go +++ b/pkg/controller/vpc.go @@ -6,6 +6,7 @@ import ( "reflect" "strings" + "github.com/alauda/kube-ovn/pkg/util" k8serrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/types" @@ -137,30 +138,32 @@ func (c *Controller) handleAddOrUpdateVpc(key string) error { return err } - // handle route - existRoute, err := c.ovnClient.GetStaticRouteList(vpc.Name) - if err != nil { - klog.Errorf("failed to get vpc %s static route list, %v", vpc.Name, err) - return err - } - - routeNeedDel, routeNeedAdd, err := diffRoute(existRoute, vpc.Spec.StaticRoutes) - if err != nil { - klog.Errorf("failed to diff vpc %s static route, %v", vpc.Name, err) - return err - } - for _, item := range routeNeedDel { - if err = c.ovnClient.DeleteStaticRoute(item.CIDR, vpc.Name); err != nil { - klog.Errorf("del vpc %s static route failed, %v", vpc.Name, err) + if vpc.Name != util.DefaultVpc { + // handle route + existRoute, err := c.ovnClient.GetStaticRouteList(vpc.Name) + if err != nil { + klog.Errorf("failed to get vpc %s static route list, %v", vpc.Name, err) return err } - } - for _, item := range routeNeedAdd { - if err = c.ovnClient.AddStaticRoute(convertPolicy(item.Policy), item.CIDR, item.NextHopIP, vpc.Name); err != nil { - klog.Errorf("add static route to vpc %s failed, %v", vpc.Name, err) + routeNeedDel, routeNeedAdd, err := diffRoute(existRoute, vpc.Spec.StaticRoutes) + if err != nil { + klog.Errorf("failed to diff vpc %s static route, %v", vpc.Name, err) return err } + for _, item := range routeNeedDel { + if err = c.ovnClient.DeleteStaticRoute(item.CIDR, vpc.Name); err != nil { + klog.Errorf("del vpc %s static route failed, %v", vpc.Name, err) + return err + } + } + + for _, item := range routeNeedAdd { + if err = c.ovnClient.AddStaticRoute(convertPolicy(item.Policy), item.CIDR, item.NextHopIP, vpc.Name); err != nil { + klog.Errorf("add static route to vpc %s failed, %v", vpc.Name, err) + return err + } + } } vpc.Status.Router = key