Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #2695: Wait for ovs-vswitchd PID before calling ovs-appctl #2711

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/images/scripts/start_ovs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ function quit {
stop_ovs
# kill background sleep process
if [ "$SLEEP_PID" != "" ]; then kill $SLEEP_PID > /dev/null 2>&1 || true; fi
cleanup_ovs_run_files
exit 0
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/ovs/ovsctl/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package ovsctl

import (
"fmt"
"net"
"os/exec"
)
Expand Down Expand Up @@ -85,3 +86,7 @@ func (e *ExecError) GetErrorOutput() string {
}
return e.errorOutput
}

func (e *ExecError) Error() string {
return fmt.Sprintf("ExecError: %v, output: %s", e.error, e.errorOutput)
}
22 changes: 19 additions & 3 deletions pkg/ovs/ovsctl/ovsctl_others.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import (
"fmt"
"os"
"os/exec"
"time"

"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog/v2"
)

Expand All @@ -47,12 +49,26 @@ func ovsVSwitchdUDS() string {
// are possible. Besides, this value is only used when invoking ovs-appctl (as a new
// process) at the moment, so the overhead of reading the PID from file should not be a
// concern.
pid, err := readOVSVSwitchdPID()
if err != nil {
klog.ErrorS(err, "Failed to read ovs-vswitchd PID")
var pid int
var readErr error
startTime := time.Now()
hasFailure := false
pollErr := wait.PollImmediate(50*time.Millisecond, 5*time.Second, func() (bool, error) {
pid, readErr = readOVSVSwitchdPID()
if readErr != nil {
hasFailure = true
return false, nil
}
return true, nil
})
if pollErr != nil {
klog.ErrorS(readErr, "Failed to read ovs-vswitchd PID")
// that seems like a reasonable value to return if we cannot read the PID
return "/var/run/openvswitch/ovs-vswitchd.*.ctl"
}
if hasFailure {
klog.V(2).InfoS("Waited for ovs-vswitchd PID to be ready", "duration", time.Since(startTime))
}
return fmt.Sprintf("/var/run/openvswitch/ovs-vswitchd.%d.ctl", pid)
}

Expand Down