Skip to content

Commit

Permalink
sync the default subnet of ns by vpc's status
Browse files Browse the repository at this point in the history
  • Loading branch information
fanriming committed Nov 4, 2020
1 parent dd2234f commit 5dbaf2d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
5 changes: 2 additions & 3 deletions pkg/controller/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,6 @@ func (c *Controller) handleAddOrUpdateSubnet(key string) error {
}
}

c.updateVpcStatusQueue.Add(subnet.Spec.Vpc)

if err := c.reconcileSubnet(subnet); err != nil {
klog.Errorf("reconcile subnet for %s failed, %v", subnet.Name, err)
return err
Expand All @@ -538,6 +536,7 @@ func (c *Controller) handleAddOrUpdateSubnet(key string) error {
}
}

c.updateVpcStatusQueue.Add(subnet.Spec.Vpc)
return nil
}

Expand Down Expand Up @@ -628,6 +627,7 @@ func (c *Controller) handleDeleteLogicalSwitch(key string) error {
}

func (c *Controller) handleDeleteSubnet(subnet *kubeovnv1.Subnet) error {
c.updateVpcStatusQueue.Add(subnet.Spec.Vpc)
err := c.handleDeleteLogicalSwitch(subnet.Name)
if err != nil {
klog.Errorf("failed to delete logical switch %s %v", subnet.Name, err)
Expand All @@ -640,7 +640,6 @@ func (c *Controller) handleDeleteSubnet(subnet *kubeovnv1.Subnet) error {
klog.Errorf("failed to delete router port %s %v", subnet.Name, err)
return err
}
c.updateVpcStatusQueue.Add(subnet.Spec.Vpc)
}

return nil
Expand Down
16 changes: 15 additions & 1 deletion pkg/controller/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ func (c *Controller) handleUpdateVpcStatus(key string) error {
if err != nil {
return err
}

change := false
if vpc.Status.DefaultLogicalSwitch != defaultSubnet {
change = true
}

vpc.Status.DefaultLogicalSwitch = defaultSubnet
vpc.Status.Subnets = subnets
bytes, err := vpc.Status.Bytes()
Expand All @@ -98,7 +104,15 @@ func (c *Controller) handleUpdateVpcStatus(key string) error {
}

vpc, err = c.config.KubeOvnClient.KubeovnV1().Vpcs().Patch(vpc.Name, types.MergePatchType, bytes, "status")
return err
if err != nil {
return err
}
if change {
for _, ns := range vpc.Spec.Namespaces {
c.addNamespaceQueue.Add(ns)
}
}
return nil
}

func (c *Controller) handleAddOrUpdateVpc(key string) error {
Expand Down

0 comments on commit 5dbaf2d

Please sign in to comment.