diff --git a/pkg/controller/ovn-ic.go b/pkg/controller/ovn-ic.go index 7b14d1a01af..968de38abe3 100644 --- a/pkg/controller/ovn-ic.go +++ b/pkg/controller/ovn-ic.go @@ -52,10 +52,6 @@ func (c *Controller) resyncInterConnection() { return } - if err := c.removeInterConnection(cm.Data["az-name"]); err != nil { - klog.Errorf("failed to remove ovn-ic, %v", err) - return - } c.ovnClient.OVNIcNBAddress = fmt.Sprintf("%s:%s", cm.Data["ic-db-host"], cm.Data["ic-nb-port"]) klog.Info("start to establish ovn-ic") if err := c.establishInterConnection(cm.Data); err != nil { @@ -113,6 +109,17 @@ func (c *Controller) removeInterConnection(azName string) error { } func (c *Controller) establishInterConnection(config map[string]string) error { + tsPort := fmt.Sprintf("ts-%s", config["az-name"]) + exist, err := c.ovnClient.LogicalSwitchPortExists(tsPort) + if err != nil { + klog.Errorf("failed to list logical switch ports, %v", err) + return err + } + if exist { + klog.Infof("ts port %s already exists", tsPort) + return nil + } + if err := c.startOVNIC(config["ic-db-host"], config["ic-nb-port"], config["ic-sb-port"]); err != nil { klog.Errorf("failed to start ovn-ic, %v", err) return err diff --git a/pkg/ovs/ovn-nbctl.go b/pkg/ovs/ovn-nbctl.go index dcc3a5b3596..bf8b65b5e86 100644 --- a/pkg/ovs/ovn-nbctl.go +++ b/pkg/ovs/ovn-nbctl.go @@ -21,7 +21,7 @@ func (c Client) ovnNbCommand(cmdArgs ...string) (string, error) { cmdArgs = append([]string{fmt.Sprintf("--timeout=%d", c.OvnTimeout)}, cmdArgs...) raw, err := exec.Command(OvnNbCtl, cmdArgs...).CombinedOutput() elapsed := float64((time.Since(start)) / time.Millisecond) - klog.V(4).Infof("command %s %s in %vms", OvnNbCtl, strings.Join(cmdArgs, " "), elapsed) + klog.V(4).Infof("command %s %s in %vms, output %q", OvnNbCtl, strings.Join(cmdArgs, " "), elapsed, raw) if err != nil || elapsed > 500 { klog.Warning("ovn-nbctl command error or took too long") klog.Warningf("%s %s in %vms", OvnNbCtl, strings.Join(cmdArgs, " "), elapsed) @@ -340,6 +340,20 @@ func (c Client) ListLogicalSwitchPort() ([]string, error) { return result, nil } +func (c Client) LogicalSwitchPortExists(port string) (bool, error) { + output, err := c.ovnNbCommand("--format=csv", "--data=bare", "--no-heading", "--columns=name", "find", "logical_switch_port", fmt.Sprintf("name=%s", port)) + if err != nil { + klog.Errorf("failed to find port %s", port) + return false, err + } + + if output != "" { + return true, nil + } + + return false, nil +} + func (c Client) ListRemoteLogicalSwitchPortAddress() ([]string, error) { output, err := c.ovnNbCommand("--format=csv", "--data=bare", "--no-heading", "--columns=addresses", "find", "logical_switch_port", "type=remote") if err != nil {