Skip to content

Commit

Permalink
fix: do not re-generate ts port
Browse files Browse the repository at this point in the history
  • Loading branch information
oilbeater committed May 7, 2021
1 parent 92a470e commit b9e9633
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
15 changes: 11 additions & 4 deletions pkg/controller/ovn-ic.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,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 {
Expand Down Expand Up @@ -114,6 +110,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
Expand Down
15 changes: 14 additions & 1 deletion pkg/ovs/ovn-nbctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
method := ""
for _, arg := range cmdArgs {
if !strings.HasPrefix(arg, "--") {
Expand Down Expand Up @@ -362,6 +362,19 @@ 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 {
Expand Down

0 comments on commit b9e9633

Please sign in to comment.