Skip to content

Commit

Permalink
Change the position of assigning the sg variable
Browse files Browse the repository at this point in the history
Signed-off-by: zhuanlan <zhuanlan_yewu@cmss.chinamobile.com>
  • Loading branch information
Longchuanzheng authored and bobz965 committed Mar 29, 2024
1 parent 27f6629 commit 31044bf
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions pkg/controller/security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,16 +415,6 @@ func (c *Controller) syncSgLogicalPort(key string) error {
defer func() { _ = c.sgKeyMutex.UnlockKey(key) }()
klog.Infof("sync lsp for security group %s", key)

sg, err := c.sgsLister.Get(key)
if err != nil {
if k8serrors.IsNotFound(err) {
klog.Errorf("sg '%s' not found.", key)
return nil
}
klog.Errorf("failed to get sg '%s'. %v", key, err)
return err
}

sgPorts, err := c.OVNNbClient.ListLogicalSwitchPorts(false, map[string]string{fmt.Sprintf("associated_sg_%s", key): "true"}, nil)
if err != nil {
klog.Errorf("failed to find logical port, %v", err)
Expand Down Expand Up @@ -452,6 +442,16 @@ func (c *Controller) syncSgLogicalPort(key string) error {
}
}

sg, err := c.sgsLister.Get(key)
if err != nil {
if k8serrors.IsNotFound(err) {
klog.Errorf("sg '%s' not found.", key)
return nil
}
klog.Errorf("failed to get sg '%s'. %v", key, err)
return err
}

if err = c.OVNNbClient.PortGroupSetPorts(sg.Status.PortGroup, ports); err != nil {
klog.Errorf("add ports to port group %s: %v", sg.Status.PortGroup, err)
return err
Expand Down

0 comments on commit 31044bf

Please sign in to comment.