mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-10 13:42:02 +00:00
Merge pull request #86009 from rphillips/fixes/at_most_one_ref
kubelet: guarantee at most only one cinfo per containerID
This commit is contained in:
@@ -329,17 +329,12 @@ func removeTerminatedContainerInfo(containerInfo map[string]cadvisorapiv2.Contai
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
sort.Sort(ByCreationTime(refs))
|
sort.Sort(ByCreationTime(refs))
|
||||||
i := 0
|
for i := len(refs) - 1; i >= 0; i-- {
|
||||||
for ; i < len(refs); i++ {
|
|
||||||
if hasMemoryAndCPUInstUsage(&refs[i].cinfo) {
|
if hasMemoryAndCPUInstUsage(&refs[i].cinfo) {
|
||||||
// Stops removing when we first see an info with non-zero
|
result[refs[i].cgroup] = refs[i].cinfo
|
||||||
// CPU/Memory usage.
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for ; i < len(refs); i++ {
|
|
||||||
result[refs[i].cgroup] = refs[i].cinfo
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
@@ -62,16 +62,10 @@ func TestRemoveTerminatedContainerInfo(t *testing.T) {
|
|||||||
// The latest containers, which should be in the results.
|
// The latest containers, which should be in the results.
|
||||||
"/pod0-i": getTestContainerInfo(seedPod0Infra, pName0, namespace, leaky.PodInfraContainerName),
|
"/pod0-i": getTestContainerInfo(seedPod0Infra, pName0, namespace, leaky.PodInfraContainerName),
|
||||||
"/pod0-c0": getTestContainerInfo(seedPod0Container0, pName0, namespace, cName00),
|
"/pod0-c0": getTestContainerInfo(seedPod0Container0, pName0, namespace, cName00),
|
||||||
|
|
||||||
// Duplicated containers with non-zero CPU and memory usage. This case
|
|
||||||
// shouldn't happen unless something goes wrong, but we want to test
|
|
||||||
// that the metrics reporting logic works in this scenario.
|
|
||||||
"/pod0-i-duplicated": getTestContainerInfo(seedPod0Infra, pName0, namespace, leaky.PodInfraContainerName),
|
|
||||||
"/pod0-c0-duplicated": getTestContainerInfo(seedPod0Container0, pName0, namespace, cName00),
|
|
||||||
}
|
}
|
||||||
output := removeTerminatedContainerInfo(infos)
|
output := removeTerminatedContainerInfo(infos)
|
||||||
assert.Len(t, output, 4)
|
assert.Len(t, output, 2)
|
||||||
for _, c := range []string{"/pod0-i", "/pod0-c0", "/pod0-i-duplicated", "/pod0-c0-duplicated"} {
|
for _, c := range []string{"/pod0-i", "/pod0-c0"} {
|
||||||
if _, found := output[c]; !found {
|
if _, found := output[c]; !found {
|
||||||
t.Errorf("%q is expected to be in the output\n", c)
|
t.Errorf("%q is expected to be in the output\n", c)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user