Skip to content

Commit

Permalink
fix: wrong subnet status
Browse files Browse the repository at this point in the history
  • Loading branch information
oilbeater committed May 12, 2020
1 parent 4eac0ea commit 27c7256
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions pkg/controller/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,14 @@ func (c *Controller) handleSubnetFinalizer(subnet *kubeovnv1.Subnet) error {
func (c Controller) patchSubnetStatus(subnet *kubeovnv1.Subnet, reason string, errStr string) {
if errStr != "" {
subnet.Status.SetError(reason, errStr)
subnet.Status.NotValidated(reason, errStr)
subnet.Status.NotReady(reason, errStr)
c.recorder.Eventf(subnet, v1.EventTypeWarning, reason, errStr)
} else {
subnet.Status.Ready(reason, "")
subnet.Status.Validated(reason, "")
if reason == "SetPrivateLogicalSwitchSuccess" || reason == "ResetLogicalSwitchAclSuccess" {
subnet.Status.Ready(reason, "")
}
}

bytes, err := subnet.Status.Bytes()
Expand Down Expand Up @@ -372,6 +376,14 @@ func (c *Controller) handleAddOrUpdateSubnet(key string) error {
return nil
}

if err = util.ValidateSubnet(*subnet); err != nil {
klog.Errorf("failed to validate subnet %s, %v", subnet.Name, err)
c.patchSubnetStatus(subnet, "ValidateLogicalSwitchFailed", err.Error())
return err
} else {
c.patchSubnetStatus(subnet, "ValidateLogicalSwitchSuccess", "")
}

subnetList, err := c.subnetsLister.List(labels.Everything())
if err != nil {
klog.Errorf("failed to list subnets %v", err)
Expand Down Expand Up @@ -411,27 +423,13 @@ func (c *Controller) handleAddOrUpdateSubnet(key string) error {

if !exist {
subnet.Status.EnsureStandardConditions()
if err = util.ValidateSubnet(*subnet); err != nil {
klog.Errorf("failed to validate subnet %s, %v", subnet.Name, err)
c.patchSubnetStatus(subnet, "ValidateLogicalSwitchFailed", err.Error())
return err
} else {
c.patchSubnetStatus(subnet, "ValidateLogicalSwitchSuccess", "")
}
// If multiple namespace use same ls name, only first one will success
if err := c.ovnClient.CreateLogicalSwitch(subnet.Name, subnet.Spec.Protocol, subnet.Spec.CIDRBlock, subnet.Spec.Gateway, subnet.Spec.ExcludeIps); err != nil {
c.patchSubnetStatus(subnet, "CreateLogicalSwitchFailed", err.Error())
return err
}
} else {
// logical switch exists, only update other_config
if err = util.ValidateSubnet(*subnet); err != nil {
klog.Errorf("failed to validate subnet %s, %v", subnet.Name, err)
c.patchSubnetStatus(subnet, "ValidateLogicalSwitchFailed", err.Error())
return err
} else {
c.patchSubnetStatus(subnet, "ValidateLogicalSwitchSuccess", "")
}
if err := c.ovnClient.SetLogicalSwitchConfig(subnet.Name, subnet.Spec.Protocol, subnet.Spec.CIDRBlock, subnet.Spec.Gateway, subnet.Spec.ExcludeIps); err != nil {
c.patchSubnetStatus(subnet, "SetLogicalSwitchConfigFailed", err.Error())
return err
Expand All @@ -455,7 +453,7 @@ func (c *Controller) handleAddOrUpdateSubnet(key string) error {
c.patchSubnetStatus(subnet, "ResetLogicalSwitchAclFailed", err.Error())
return err
} else {
c.patchSubnetStatus(subnet, "ResetLogicalSwitchAclFailed", "")
c.patchSubnetStatus(subnet, "ResetLogicalSwitchAclSuccess", "")
}
}

Expand Down

0 comments on commit 27c7256

Please sign in to comment.