Commit 54a47a6f authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #46308 from dashpole/summary_container_restart

Automatic merge from submit-queue (batch tested with PRs 46429, 46308, 46395, 45867, 45492) Summary Test looks at pods that have containers that restart. Occasionally, the node can report extra containers that had been restarted through the summary API. This test change tests a pod that restarts, and hopefully should allow us to reproduce and debug this behavior. /assign @dchen1107 /release-note-none
parents 59ee250c 1a6572fc
......@@ -18,6 +18,7 @@ package e2e_node
import (
"fmt"
"strconv"
"strings"
"time"
......@@ -289,20 +290,9 @@ func getPods(specs []*testPodSpec) (pods []*v1.Pod) {
containers := []v1.Container{}
for i := 0; i < spec.numContainers; i++ {
containers = append(containers, v1.Container{
Image: "gcr.io/google_containers/busybox:1.24",
Name: spec.getContainerName(i),
Command: []string{
"sh",
"-c",
fmt.Sprintf(`
f=/test-empty-dir-mnt/countfile%d
count=$(echo 'hello' >> $f ; wc -l $f | awk {'print $1'})
if [ $count -lt %d ]; then
exit 0
fi
while true; do sleep 1; done
`, i, spec.restartCount+1),
},
Image: "gcr.io/google_containers/busybox:1.24",
Name: spec.getContainerName(i),
Command: getRestartingContainerCommand("/test-empty-dir-mnt", i, int(spec.restartCount), ""),
VolumeMounts: []v1.VolumeMount{
{MountPath: "/test-empty-dir-mnt", Name: "test-empty-dir"},
},
......@@ -321,3 +311,18 @@ func getPods(specs []*testPodSpec) (pods []*v1.Pod) {
}
return
}
func getRestartingContainerCommand(path string, containerNum, restarts int, loopingCommand string) []string {
return []string{
"sh",
"-c",
fmt.Sprintf(`
f=%s/countfile%s
count=$(echo 'hello' >> $f ; wc -l $f | awk {'print $1'})
if [ $count -lt %d ]; then
exit 0
fi
while true; do %s sleep 10; done`,
path, strconv.Itoa(containerNum), restarts+1, loopingCommand),
}
}
......@@ -35,6 +35,8 @@ import (
"github.com/onsi/gomega/types"
)
const restartCount = 3
var _ = framework.KubeDescribe("Summary API", func() {
f := framework.NewDefaultFramework("summary-test")
Context("when querying /stats/summary", func() {
......@@ -53,9 +55,10 @@ var _ = framework.KubeDescribe("Summary API", func() {
const pod1 = "stats-busybox-1"
By("Creating test pods")
createSummaryTestPods(f, pod0, pod1)
// Wait for cAdvisor to collect 2 stats points
time.Sleep(15 * time.Second)
pods := getSummaryTestPods(f, pod0, pod1)
f.PodClient().CreateBatch(pods)
// Wait for cAdvisor to collect 2 stats points, and for pods to restart
time.Sleep(45 * time.Second)
// Setup expectations.
const (
......@@ -131,16 +134,16 @@ var _ = framework.KubeDescribe("Summary API", func() {
"StartTime": recent(maxStartAge),
"CPU": ptrMatchAllFields(gstruct.Fields{
"Time": recent(maxStatsAge),
"UsageNanoCores": bounded(100000, 100000000),
"UsageCoreNanoSeconds": bounded(10000000, 1000000000),
"UsageNanoCores": bounded(100000, 1000000000),
"UsageCoreNanoSeconds": bounded(10000000, 100000000000),
}),
"Memory": ptrMatchAllFields(gstruct.Fields{
"Time": recent(maxStatsAge),
"AvailableBytes": bounded(1*mb, 10*mb),
"UsageBytes": bounded(10*kb, 5*mb),
"WorkingSetBytes": bounded(10*kb, 2*mb),
"AvailableBytes": bounded(10*kb, 10*mb),
"UsageBytes": bounded(10*kb, 20*mb),
"WorkingSetBytes": bounded(10*kb, 20*mb),
"RSSBytes": bounded(1*kb, mb),
"PageFaults": bounded(100, 100000),
"PageFaults": bounded(100, 1000000),
"MajorPageFaults": bounded(0, 10),
}),
"Rootfs": ptrMatchAllFields(gstruct.Fields{
......@@ -259,7 +262,7 @@ var _ = framework.KubeDescribe("Summary API", func() {
})
})
func createSummaryTestPods(f *framework.Framework, names ...string) {
func getSummaryTestPods(f *framework.Framework, names ...string) []*v1.Pod {
pods := make([]*v1.Pod, 0, len(names))
for _, name := range names {
pods = append(pods, &v1.Pod{
......@@ -272,7 +275,7 @@ func createSummaryTestPods(f *framework.Framework, names ...string) {
{
Name: "busybox-container",
Image: "gcr.io/google_containers/busybox:1.24",
Command: []string{"sh", "-c", "ping -c 1 google.com; while true; do echo 'hello world' >> /test-empty-dir-mnt/file ; sleep 1; done"},
Command: getRestartingContainerCommand("/test-empty-dir-mnt", 0, restartCount, "ping -c 1 google.com; echo 'hello world' >> /test-empty-dir-mnt/file"),
Resources: v1.ResourceRequirements{
Limits: v1.ResourceList{
// Must set memory limit to get MemoryStats.AvailableBytes
......@@ -297,7 +300,7 @@ func createSummaryTestPods(f *framework.Framework, names ...string) {
},
})
}
f.PodClient().CreateBatch(pods)
return pods
}
// Mapping function for gstruct.MatchAllElements
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment