Skip to content

Commit

Permalink
fix: vlan gw clean in 2 scene (#2117)
Browse files Browse the repository at this point in the history
Co-authored-by: zhangbingbing <zhangbingbing@yealink.com>
  • Loading branch information
bobz965 and zhangbingbing committed Dec 5, 2022
1 parent b8e15e1 commit 78584b7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
18 changes: 18 additions & 0 deletions pkg/controller/external-gw.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,24 @@ func (c *Controller) resyncExternalGateway() {
lastExGwCM = cm.Data
c.ovnLegacyClient.ExternalGatewayType = cm.Data["type"]
klog.Info("finish establishing ovn external gw")
cachedVpc, err := c.vpcsLister.Get(c.config.ClusterRouter)
if err != nil {
klog.Errorf("failed to get vpc %s, %v", c.config.ClusterRouter, err)
return
}
vpc := cachedVpc.DeepCopy()
vpc.Spec.EnableExternal = true
vpc.Status.EnableExternal = true
bytes, err := vpc.Status.Bytes()
if err != nil {
klog.Errorf("failed to get vpc bytes, %v", err)
return
}
if _, err = c.config.KubeOvnClient.KubeovnV1().Vpcs().Patch(context.Background(),
vpc.Name, types.MergePatchType, bytes, metav1.PatchOptions{}, "status"); err != nil {
klog.Errorf("failed to patch vpc %s, %v", c.config.ClusterRouter, err)
return
}
}
}

Expand Down
23 changes: 7 additions & 16 deletions pkg/controller/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,15 +619,12 @@ func (c *Controller) handleAddOrUpdateSubnet(key string) error {
c.patchSubnetStatus(subnet, "ListLogicalSwitchFailed", err.Error())
return err
}
var isUnderlayGateway, needRouter bool
if subnet.Spec.Vlan == "" {
// subnet is overlay, should add lrp between vpc and subnet, lrp ip is subnet gw
needRouter = true
} else {
// subnet is underlay, lrp is controlled by vpc spec enableExternal
needRouter = subnet.Spec.LogicalGateway
isUnderlayGateway = !subnet.Spec.LogicalGateway
}
needRouter := subnet.Spec.Vlan == "" || subnet.Spec.LogicalGateway
// 1. overlay subnet, should add lrp, lrp ip is subnet gw
// 2. underlay subnet use logical gw, should add lrp, lrp ip is subnet gw
randomAllocateGW := !subnet.Spec.LogicalGateway && vpc.Spec.EnableExternal && subnet.Name == c.config.ExternalGatewaySwitch
// 3. underlay subnet use physical gw, vpc has eip, lrp managed in vpc process, lrp ip is random allocation, not subnet gw

if !exist {
subnet.Status.EnsureStandardConditions()
// If multiple namespace use same ls name, only first one will success
Expand All @@ -642,18 +639,12 @@ func (c *Controller) handleAddOrUpdateSubnet(key string) error {
}
}
} else {
if !needRouter && isUnderlayGateway {
// do nothing if subnet is underlay vlan and use underlay gw
// TODO:// support update if spec changed
klog.Infof("skip reset external connection from vpc %s to switch %s", vpc.Status.Router, subnet.Name)
return nil
}
// logical switch exists, only update other_config
if err := c.ovnLegacyClient.SetLogicalSwitchConfig(subnet.Name, vpc.Status.Router, subnet.Spec.Protocol, subnet.Spec.CIDRBlock, subnet.Spec.Gateway, subnet.Spec.ExcludeIps, needRouter); err != nil {
c.patchSubnetStatus(subnet, "SetLogicalSwitchConfigFailed", err.Error())
return err
}
if !needRouter {
if !needRouter && !randomAllocateGW {
klog.Infof("remove connection from router %s to switch %s", vpc.Status.Router, subnet.Name)
if err := c.ovnLegacyClient.RemoveRouterPort(subnet.Name, vpc.Status.Router); err != nil {
klog.Errorf("failed to remove router port from %s, %v", subnet.Name, err)
Expand Down

0 comments on commit 78584b7

Please sign in to comment.