mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +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 {
|
func getContainersFromPods(pods ...*kubecontainer.Pod) []*kubecontainer.Container {
|
||||||
cidSet := sets.NewString()
|
cidSet := sets.NewString()
|
||||||
var containers []*kubecontainer.Container
|
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 {
|
for _, p := range pods {
|
||||||
if p == nil {
|
if p == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for _, c := range p.Containers {
|
fillCidSet(p.Containers)
|
||||||
cid := string(c.ID.ID)
|
|
||||||
if cidSet.Has(cid) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
cidSet.Insert(cid)
|
|
||||||
containers = append(containers, c)
|
|
||||||
}
|
|
||||||
// Update sandboxes as containers
|
// Update sandboxes as containers
|
||||||
// TODO: keep track of sandboxes explicitly.
|
// TODO: keep track of sandboxes explicitly.
|
||||||
for _, c := range p.Sandboxes {
|
fillCidSet(p.Sandboxes)
|
||||||
cid := string(c.ID.ID)
|
|
||||||
if cidSet.Has(cid) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
cidSet.Insert(cid)
|
|
||||||
containers = append(containers, c)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return containers
|
return containers
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user