Skip to content

Commit

Permalink
fix vpc spec external not true after init external gw (#2140)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobz965 committed Dec 8, 2022
1 parent 51907e0 commit 4072eb7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
30 changes: 20 additions & 10 deletions pkg/controller/external-gw.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,33 @@ 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 !vpc.Spec.EnableExternal {
vpc.Spec.EnableExternal = true
if _, err := c.config.KubeOvnClient.KubeovnV1().Vpcs().Update(context.Background(), vpc, metav1.UpdateOptions{}); err != nil {
errMsg := fmt.Errorf("failed to update vpc enable external %s, %v", vpc.Name, err)
klog.Error(errMsg)
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
if !vpc.Status.EnableExternal {
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
19 changes: 14 additions & 5 deletions pkg/controller/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ func (c *Controller) handleAddOrUpdateSubnet(key string) error {
}
return err
}
klog.V(4).Infof("handle add or update subnet %s", cachedSubnet.Name)

subnet := cachedSubnet.DeepCopy()
if err = formatSubnet(subnet, c); err != nil {
Expand Down Expand Up @@ -640,9 +641,11 @@ func (c *Controller) handleAddOrUpdateSubnet(key string) error {
}
} else {
// 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 !randomAllocateGW {
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 && !randomAllocateGW {
klog.Infof("remove connection from router %s to switch %s", vpc.Status.Router, subnet.Name)
Expand Down Expand Up @@ -818,7 +821,7 @@ func (c *Controller) handleDeleteSubnet(subnet *kubeovnv1.Subnet) error {
}
} else {
if k8serrors.IsNotFound(err) {
klog.Infof("remove connection from router %s to switch %s", vpc.Status.Router, subnet.Name)
klog.Infof("remove connection from router %s to switch %s", util.DefaultVpc, subnet.Name)
if err = c.ovnLegacyClient.RemoveRouterPort(subnet.Name, util.DefaultVpc); err != nil {
klog.Errorf("failed to delete router port %s %v", subnet.Name, err)
return err
Expand Down Expand Up @@ -1382,8 +1385,14 @@ func (c *Controller) reconcileVlan(subnet *kubeovnv1.Subnet) error {
if subnet.Spec.Vlan == "" {
return nil
}

klog.Infof("reconcile vlan %v", subnet.Spec.Vlan)
isExternalGatewaySwitch := !subnet.Spec.LogicalGateway && subnet.Name == c.config.ExternalGatewaySwitch
if isExternalGatewaySwitch {
// external gw deal this vlan subnet, just skip
klog.Infof("skip reconcile vlan subnet %s", c.config.ExternalGatewaySwitch)
return nil
}

vlan, err := c.vlansLister.Get(subnet.Spec.Vlan)
if err != nil {
klog.Errorf("failed to get vlan %s: %v", subnet.Spec.Vlan, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/daemon/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type Configuration struct {
DefaultProviderName string
DefaultInterfaceName string
ExternalGatewayConfigNS string
ExternalGatewaySwitch string
ExternalGatewaySwitch string // provider network underlay vlan subnet
}

// ParseFlags will parse cmd args then init kubeClient and configuration
Expand Down

0 comments on commit 4072eb7

Please sign in to comment.