Skip to content

Commit

Permalink
Fix: Resolve issue with skipped execution of sg annotations (#3700)
Browse files Browse the repository at this point in the history
The problem causing ineffective application of sg annotations is
that, during virtual machine restart, the logical switch port is
intentionally not deleted.(I guess).

When sg annotations are added and the VM is restarted, the create
logical switch port logic is skipped as it detects the existing
lsp. Consequently, the annotation fails to attach to the lsp. Even
when we sync lsp for sg, it has no effect.

A simple fix is to update the existing lsp during lsp creation if
it already exists. This approach ensures correct annotation
attachment and addresses the skipped execution issue.

Signed-off-by: wfnuser <wfnuser@hotmail.com>
  • Loading branch information
wfnuser authored and bobz965 committed Feb 18, 2024
1 parent ae895e2 commit 8e0e4b1
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions pkg/ovs/ovn-nb-logical_switch_port.go
Expand Up @@ -16,18 +16,7 @@ import (
"github.com/kubeovn/kube-ovn/pkg/util"
)

func (c *OVNNbClient) CreateLogicalSwitchPort(lsName, lspName, ip, mac, podName, namespace string, portSecurity bool, securityGroups, vips string, enableDHCP bool, dhcpOptions *DHCPOptionsUUIDs, vpc string) error {
exist, err := c.LogicalSwitchPortExists(lspName)
if err != nil {
klog.Error(err)
return err
}

// ignore
if exist {
return nil
}

func buildLogicalSwitchPort(lspName, ip, mac, podName, namespace string, portSecurity bool, securityGroups, vips string, enableDHCP bool, dhcpOptions *DHCPOptionsUUIDs, vpc string) *ovnnb.LogicalSwitchPort {
/* normal lsp creation */
lsp := &ovnnb.LogicalSwitchPort{
UUID: ovsclient.NamedUUID(),
Expand Down Expand Up @@ -88,6 +77,27 @@ func (c *OVNNbClient) CreateLogicalSwitchPort(lsName, lspName, ip, mac, podName,
}
}

return lsp
}

func (c *OVNNbClient) CreateLogicalSwitchPort(lsName, lspName, ip, mac, podName, namespace string, portSecurity bool, securityGroups, vips string, enableDHCP bool, dhcpOptions *DHCPOptionsUUIDs, vpc string) error {
exist, err := c.LogicalSwitchPortExists(lspName)
if err != nil {
klog.Error(err)
return err
}

// update if exists
if exist {
lsp := buildLogicalSwitchPort(lspName, ip, mac, podName, namespace, portSecurity, securityGroups, vips, enableDHCP, dhcpOptions, vpc)
if err := c.UpdateLogicalSwitchPort(lsp, &lsp.PortSecurity, &lsp.ExternalIDs); err != nil {
klog.Error(err)
return fmt.Errorf("failed to update logical switch port %s: %v", lspName, err)
}
return nil
}

lsp := buildLogicalSwitchPort(lspName, ip, mac, podName, namespace, portSecurity, securityGroups, vips, enableDHCP, dhcpOptions, vpc)
ops, err := c.CreateLogicalSwitchPortOp(lsp, lsName)
if err != nil {
klog.Error(err)
Expand Down

0 comments on commit 8e0e4b1

Please sign in to comment.