mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 10:20:51 +00:00
Merge pull request #109227 from Monokaix/refactor-pleg/getContainersFromPods
refactor: pleg/getContainersFromPods
This commit is contained in:
commit
50b982edab
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user