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

fix: vlan gw operate lrp #2117

Merged
merged 1 commit into from
Dec 5, 2022
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
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