In summary_test, make Docker cpu/memory checks optional if unavailable.

The numbers will only be available when docker.service has its own
memory and cpu cgroups, which doesn't necessarily happen unless the unit
has Delegate=yes configured.

Let's work around that by checking the status of Delegate, in the case
where we are:
* running Docker
* running Systemd
* able to check the status through systemctl
* the status is explicitly Delegate=no (the default)

If all of those are true, let's make CPU and Memory expectations
optional.

Tested: make test-e2e-node REMOTE=true HOSTS=centos-e2e-node FOCUS="Summary API"
pull/8/head
Filipe Brandenburger 2018-03-21 08:46:46 -07:00
parent 351a70b60e
commit b8c39b7055
1 changed files with 26 additions and 1 deletions

View File

@ -19,6 +19,7 @@ package e2e_node
import ( import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os/exec"
"strings" "strings"
"time" "time"
@ -118,9 +119,33 @@ var _ = framework.KubeDescribe("Summary API", func() {
"PageFaults": bounded(0, 1000000), "PageFaults": bounded(0, 1000000),
"MajorPageFaults": bounded(0, 10), "MajorPageFaults": bounded(0, 10),
}) })
runtimeContExpectations := sysContExpectations().(*gstruct.FieldsMatcher)
if systemdutil.IsRunningSystemd() && framework.TestContext.ContainerRuntime == "docker" {
// Some Linux distributions still ship a docker.service that is missing
// a `Delegate=yes` setting (or equivalent CPUAccounting= and MemoryAccounting=)
// that allows us to monitor the container runtime resource usage through
// the "cpu" and "memory" cgroups.
//
// Make an exception here for those distros, only for Docker, so that they
// can pass the full node e2e tests even in that case.
//
// For newer container runtimes (using CRI) and even distros that still
// ship Docker, we should encourage them to always set `Delegate=yes` in
// order to make monitoring of the runtime possible.
stdout, err := exec.Command("systemctl", "show", "-p", "Delegate", "docker.service").CombinedOutput()
if err == nil && strings.TrimSpace(string(stdout)) == "Delegate=no" {
// Only make these optional if we can successfully confirm that
// Delegate is set to "no" (in other words, unset.) If we fail
// to check that, default to requiring it, which might cause
// false positives, but that should be the safer approach.
By("Making runtime container expectations optional, since systemd was not configured to Delegate=yes the cgroups")
runtimeContExpectations.Fields["Memory"] = Or(BeNil(), runtimeContExpectations.Fields["Memory"])
runtimeContExpectations.Fields["CPU"] = Or(BeNil(), runtimeContExpectations.Fields["CPU"])
}
}
systemContainers := gstruct.Elements{ systemContainers := gstruct.Elements{
"kubelet": sysContExpectations(), "kubelet": sysContExpectations(),
"runtime": sysContExpectations(), "runtime": runtimeContExpectations,
"pods": podsContExpectations, "pods": podsContExpectations,
} }
// The Kubelet only manages the 'misc' system container if the host is not running systemd. // The Kubelet only manages the 'misc' system container if the host is not running systemd.