Skip to content

Commit d04c7d1

Browse files
authored
Merge pull request #1734 from honpey/panic-fix
internal/store: fix metrics slice length for init containers
2 parents 07c8a22 + 9f3e368 commit d04c7d1

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

internal/store/pod.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -587,19 +587,19 @@ func createPodInitContainerInfoFamilyGenerator() generator.FamilyGenerator {
587587
metric.Gauge,
588588
"",
589589
wrapPodFunc(func(p *v1.Pod) *metric.Family {
590-
ms := make([]*metric.Metric, len(p.Status.InitContainerStatuses))
590+
ms := []*metric.Metric{}
591591
labelKeys := []string{"container", "image_spec", "image", "image_id", "container_id"}
592592

593-
for i, c := range p.Spec.InitContainers {
593+
for _, c := range p.Spec.InitContainers {
594594
for _, cs := range p.Status.InitContainerStatuses {
595595
if cs.Name != c.Name {
596596
continue
597597
}
598-
ms[i] = &metric.Metric{
598+
ms = append(ms, &metric.Metric{
599599
LabelKeys: labelKeys,
600600
LabelValues: []string{cs.Name, c.Image, cs.Image, cs.ImageID, cs.ContainerID},
601601
Value: 1,
602-
}
602+
})
603603
}
604604
}
605605

0 commit comments

Comments
 (0)