Merge pull request #109227 from Monokaix/refactor-pleg/getContainersFromPods

refactor: pleg/getContainersFromPods
This commit is contained in:
Kubernetes Prow Robot 2022-06-28 10:17:58 -07:00 committed by GitHub
commit 50b982edab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -325,29 +325,25 @@ func (g *GenericPLEG) relist() {
func getContainersFromPods(pods ...*kubecontainer.Pod) []*kubecontainer.Container {
cidSet := sets.NewString()
var containers []*kubecontainer.Container
fillCidSet := func(cs []*kubecontainer.Container) {
for _, c := range cs {
cid := c.ID.ID
if cidSet.Has(cid) {
continue
}
cidSet.Insert(cid)
containers = append(containers, c)
}
}
for _, p := range pods {
if p == nil {
continue
}
for _, c := range p.Containers {
cid := string(c.ID.ID)
if cidSet.Has(cid) {
continue
}
cidSet.Insert(cid)
containers = append(containers, c)
}
fillCidSet(p.Containers)
// Update sandboxes as containers
// TODO: keep track of sandboxes explicitly.
for _, c := range p.Sandboxes {
cid := string(c.ID.ID)
if cidSet.Has(cid) {
continue
}
cidSet.Insert(cid)
containers = append(containers, c)
}
fillCidSet(p.Sandboxes)
}
return containers
}