Skip to content

Commit

Permalink
Fix index out of range in controller security_group (#3845)
Browse files Browse the repository at this point in the history
* controller security_group: Fix index out of range problem

* Change the position of assigning the sg variable


---------

Signed-off-by: zhuanlan <zhuanlan_yewu@cmss.chinamobile.com>
  • Loading branch information
Longchuanzheng authored and bobz965 committed Mar 29, 2024
1 parent 8d69acd commit 4c206a7
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions pkg/controller/security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func (c *Controller) updateDenyAllSgPorts() error {
addPorts := make([]string, 0, len(lsps))
for _, lsp := range lsps {
// skip lsp which only have mac addresses,address is in port.PortSecurity[0]
if len(strings.Split(lsp.PortSecurity[0], " ")) < 2 {
if len(lsp.PortSecurity) == 0 || len(strings.Split(lsp.PortSecurity[0], " ")) < 2 {
continue
}

Expand Down 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 4c206a7

Please sign in to comment.