Skip to content

Commit 170bbd4

Browse files
committed
fix(kube_pod_tolerations): deduplicate tolerations before creating metric
1 parent ea5826a commit 170bbd4

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

internal/store/pod.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1642,6 +1642,21 @@ func createPodStatusUnschedulableFamilyGenerator() generator.FamilyGenerator {
16421642
)
16431643
}
16441644

1645+
// getUniqueTolerations takes an array
1646+
func getUniqueTolerations(tolerations []v1.Toleration) []v1.Toleration {
1647+
uniqueTolerationsMap := make(map[v1.Toleration]struct{})
1648+
var uniqueTolerations []v1.Toleration
1649+
1650+
for _, toleration := range tolerations {
1651+
_, exists := uniqueTolerationsMap[toleration]
1652+
if !exists {
1653+
uniqueTolerationsMap[toleration] = struct{}{}
1654+
uniqueTolerations = append(uniqueTolerations, toleration)
1655+
}
1656+
}
1657+
return uniqueTolerations
1658+
}
1659+
16451660
func createPodTolerationsFamilyGenerator() generator.FamilyGenerator {
16461661
return *generator.NewFamilyGeneratorWithStability(
16471662
"kube_pod_tolerations",
@@ -1651,8 +1666,9 @@ func createPodTolerationsFamilyGenerator() generator.FamilyGenerator {
16511666
"",
16521667
wrapPodFunc(func(p *v1.Pod) *metric.Family {
16531668
var ms []*metric.Metric
1669+
uniqueTolerations := getUniqueTolerations(p.Spec.Tolerations)
16541670

1655-
for _, t := range p.Spec.Tolerations {
1671+
for _, t := range uniqueTolerations {
16561672
var key, operator, value, effect, tolerationSeconds string
16571673

16581674
key = t.Key

0 commit comments

Comments
 (0)