Skip to content

Commit

Permalink
fix: vpc static route manage
Browse files Browse the repository at this point in the history
  • Loading branch information
fanriming committed Nov 25, 2020
1 parent 8deb5d8 commit 0057119
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions pkg/controller/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0057119

Please sign in to comment.