mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
summary test now tests a pod that has containers that have restarted
This commit is contained in:
parent
9a9a296556
commit
1a6572fc6c
@ -18,6 +18,7 @@ package e2e_node
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -291,18 +292,7 @@ func getPods(specs []*testPodSpec) (pods []*v1.Pod) {
|
|||||||
containers = append(containers, v1.Container{
|
containers = append(containers, v1.Container{
|
||||||
Image: "gcr.io/google_containers/busybox:1.24",
|
Image: "gcr.io/google_containers/busybox:1.24",
|
||||||
Name: spec.getContainerName(i),
|
Name: spec.getContainerName(i),
|
||||||
Command: []string{
|
Command: getRestartingContainerCommand("/test-empty-dir-mnt", i, int(spec.restartCount), ""),
|
||||||
"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),
|
|
||||||
},
|
|
||||||
VolumeMounts: []v1.VolumeMount{
|
VolumeMounts: []v1.VolumeMount{
|
||||||
{MountPath: "/test-empty-dir-mnt", Name: "test-empty-dir"},
|
{MountPath: "/test-empty-dir-mnt", Name: "test-empty-dir"},
|
||||||
},
|
},
|
||||||
@ -321,3 +311,18 @@ func getPods(specs []*testPodSpec) (pods []*v1.Pod) {
|
|||||||
}
|
}
|
||||||
return
|
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"
|
"github.com/onsi/gomega/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const restartCount = 3
|
||||||
|
|
||||||
var _ = framework.KubeDescribe("Summary API", func() {
|
var _ = framework.KubeDescribe("Summary API", func() {
|
||||||
f := framework.NewDefaultFramework("summary-test")
|
f := framework.NewDefaultFramework("summary-test")
|
||||||
Context("when querying /stats/summary", func() {
|
Context("when querying /stats/summary", func() {
|
||||||
@ -53,9 +55,10 @@ var _ = framework.KubeDescribe("Summary API", func() {
|
|||||||
const pod1 = "stats-busybox-1"
|
const pod1 = "stats-busybox-1"
|
||||||
|
|
||||||
By("Creating test pods")
|
By("Creating test pods")
|
||||||
createSummaryTestPods(f, pod0, pod1)
|
pods := getSummaryTestPods(f, pod0, pod1)
|
||||||
// Wait for cAdvisor to collect 2 stats points
|
f.PodClient().CreateBatch(pods)
|
||||||
time.Sleep(15 * time.Second)
|
// Wait for cAdvisor to collect 2 stats points, and for pods to restart
|
||||||
|
time.Sleep(45 * time.Second)
|
||||||
|
|
||||||
// Setup expectations.
|
// Setup expectations.
|
||||||
const (
|
const (
|
||||||
@ -131,16 +134,16 @@ var _ = framework.KubeDescribe("Summary API", func() {
|
|||||||
"StartTime": recent(maxStartAge),
|
"StartTime": recent(maxStartAge),
|
||||||
"CPU": ptrMatchAllFields(gstruct.Fields{
|
"CPU": ptrMatchAllFields(gstruct.Fields{
|
||||||
"Time": recent(maxStatsAge),
|
"Time": recent(maxStatsAge),
|
||||||
"UsageNanoCores": bounded(100000, 100000000),
|
"UsageNanoCores": bounded(100000, 1000000000),
|
||||||
"UsageCoreNanoSeconds": bounded(10000000, 1000000000),
|
"UsageCoreNanoSeconds": bounded(10000000, 100000000000),
|
||||||
}),
|
}),
|
||||||
"Memory": ptrMatchAllFields(gstruct.Fields{
|
"Memory": ptrMatchAllFields(gstruct.Fields{
|
||||||
"Time": recent(maxStatsAge),
|
"Time": recent(maxStatsAge),
|
||||||
"AvailableBytes": bounded(1*mb, 10*mb),
|
"AvailableBytes": bounded(10*kb, 10*mb),
|
||||||
"UsageBytes": bounded(10*kb, 5*mb),
|
"UsageBytes": bounded(10*kb, 20*mb),
|
||||||
"WorkingSetBytes": bounded(10*kb, 2*mb),
|
"WorkingSetBytes": bounded(10*kb, 20*mb),
|
||||||
"RSSBytes": bounded(1*kb, mb),
|
"RSSBytes": bounded(1*kb, mb),
|
||||||
"PageFaults": bounded(100, 100000),
|
"PageFaults": bounded(100, 1000000),
|
||||||
"MajorPageFaults": bounded(0, 10),
|
"MajorPageFaults": bounded(0, 10),
|
||||||
}),
|
}),
|
||||||
"Rootfs": ptrMatchAllFields(gstruct.Fields{
|
"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))
|
pods := make([]*v1.Pod, 0, len(names))
|
||||||
for _, name := range names {
|
for _, name := range names {
|
||||||
pods = append(pods, &v1.Pod{
|
pods = append(pods, &v1.Pod{
|
||||||
@ -272,7 +275,7 @@ func createSummaryTestPods(f *framework.Framework, names ...string) {
|
|||||||
{
|
{
|
||||||
Name: "busybox-container",
|
Name: "busybox-container",
|
||||||
Image: "gcr.io/google_containers/busybox:1.24",
|
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{
|
Resources: v1.ResourceRequirements{
|
||||||
Limits: v1.ResourceList{
|
Limits: v1.ResourceList{
|
||||||
// Must set memory limit to get MemoryStats.AvailableBytes
|
// 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
|
// Mapping function for gstruct.MatchAllElements
|
||||||
|
Loading…
Reference in New Issue
Block a user