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

Bug 1862700: Fix ovnkube-node aggressive memory allocation to prevent memory bloating #227

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 21 additions & 8 deletions go-controller/pkg/cni/helper_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,7 @@ func (pr *PodRequest) ConfigureInterface(namespace string, podName string, ifInf
klog.Warningf("failed to settle addresses: %q", err)
}

err = wait.PollImmediate(100*time.Millisecond, 20*time.Second, func() (bool, error) {
stdout, err := ofctlExec("dump-flows", "br-int")
if err != nil {
return false, nil
}
return strings.Contains(stdout, ifInfo.IPs[0].IP.String()), nil
})
if err != nil {
if err = waitForPodFlows(ifInfo.MAC.String()); err != nil {
dcbw marked this conversation as resolved.
Show resolved Hide resolved
return nil, fmt.Errorf("timed out dumping br-int flow entries for sandbox: %v", err)
}

Expand Down Expand Up @@ -373,6 +366,26 @@ func (pr *PodRequest) deletePodConntrack() {
}
}

// OCP HACK: wait for OVN to fully process the new pod
func waitForPodFlows(mac string) error {

return wait.PollImmediate(200*time.Millisecond, 20*time.Second, func() (bool, error) {
// Query the flows by mac address
query := fmt.Sprintf("table=9,dl_src=%s",mac)
// ovs-ofctl dumps error on stderr, so stdout will only dump flow data if matches the query.
stdout, err := ofctlExec("dump-flows", "br-int", query)
if err != nil {
return false, nil
}
if len(stdout) == 0 {
return false, nil
}
return true, nil
})
}

// END OCP HACK

// PlatformSpecificCleanup deletes the OVS port
func (pr *PodRequest) PlatformSpecificCleanup() error {
ifaceName := pr.SandboxID[:15]
Expand Down
29 changes: 22 additions & 7 deletions go-controller/pkg/cni/ovs.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cni

import (
"bytes"
"fmt"
"k8s.io/klog"
"strings"

kexec "k8s.io/utils/exec"
Expand All @@ -18,20 +20,33 @@ func setExec(r kexec.Interface) error {
}

func ofctlExec(args ...string) (string, error) {
args = append([]string{"--timeout=30"}, args...)
output, err := runner.Command("ovs-ofctl", args...).CombinedOutput()

args = append([]string{"--timeout=30","--no-stats", "--strict"}, args...)
var stdout, stderr bytes.Buffer
cmd := runner.Command("ovs-ofctl", args...)
cmd.SetStdout(&stdout)
cmd.SetStderr(&stderr)

cmdStr := strings.Join(args, " ")
klog.V(5).Infof("exec: ovs-ofctl %s", cmdStr)

err := cmd.Run()

if err != nil {
return "", fmt.Errorf("failed to run 'ovs-ofctl %s': %v\n %q", strings.Join(args, " "), err, string(output))
stderrStr := string(stderr.Bytes())
klog.Errorf("exec: ovs-ofctl %s: stderr: %q", cmdStr, stderrStr)
return "", fmt.Errorf("failed to run 'ovs-ofctl %s': %v\n %q", cmdStr, err, stderrStr)
}
stdoutStr := string(stdout.Bytes())
klog.V(5).Infof("exec: ovs-ofctl %s: stdout: %q",cmdStr, stdoutStr)

outStr := string(output)
trimmed := strings.TrimSpace(outStr)
trimmed := strings.TrimSpace(stdoutStr)
// If output is a single line, strip the trailing newline
if strings.Count(trimmed, "\n") == 0 {
outStr = trimmed
stdoutStr = trimmed
}

return outStr, nil
return stdoutStr, nil
}

func ovsExec(args ...string) (string, error) {
Expand Down