Skip to content

Commit 50b982e

Browse files
authored
Merge pull request kubernetes#109227 from Monokaix/refactor-pleg/getContainersFromPods
refactor: pleg/getContainersFromPods
2 parents 8f755aa + 6266554 commit 50b982e

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

pkg/kubelet/pleg/generic.go

+11-15
Original file line numberDiff line numberDiff line change
@@ -325,29 +325,25 @@ func (g *GenericPLEG) relist() {
325325
func getContainersFromPods(pods ...*kubecontainer.Pod) []*kubecontainer.Container {
326326
cidSet := sets.NewString()
327327
var containers []*kubecontainer.Container
328-
for _, p := range pods {
329-
if p == nil {
330-
continue
331-
}
332-
for _, c := range p.Containers {
333-
cid := string(c.ID.ID)
328+
fillCidSet := func(cs []*kubecontainer.Container) {
329+
for _, c := range cs {
330+
cid := c.ID.ID
334331
if cidSet.Has(cid) {
335332
continue
336333
}
337334
cidSet.Insert(cid)
338335
containers = append(containers, c)
339336
}
337+
}
338+
339+
for _, p := range pods {
340+
if p == nil {
341+
continue
342+
}
343+
fillCidSet(p.Containers)
340344
// Update sandboxes as containers
341345
// TODO: keep track of sandboxes explicitly.
342-
for _, c := range p.Sandboxes {
343-
cid := string(c.ID.ID)
344-
if cidSet.Has(cid) {
345-
continue
346-
}
347-
cidSet.Insert(cid)
348-
containers = append(containers, c)
349-
}
350-
346+
fillCidSet(p.Sandboxes)
351347
}
352348
return containers
353349
}

0 commit comments

Comments
 (0)