diff --git a/discovery/kubernetes/ingress.go b/discovery/kubernetes/ingress.go index 1feffa68f..10c729ede 100644 --- a/discovery/kubernetes/ingress.go +++ b/discovery/kubernetes/ingress.go @@ -144,7 +144,8 @@ const ( ) func ingressLabels(ingress *v1beta1.Ingress) model.LabelSet { - ls := make(model.LabelSet, len(ingress.Labels)+len(ingress.Annotations)+2) + // Each label and annotation will create two key-value pairs in the map. + ls := make(model.LabelSet, 2*(len(ingress.Labels)+len(ingress.Annotations))+2) ls[ingressNameLabel] = lv(ingress.Name) ls[namespaceLabel] = lv(ingress.Namespace) diff --git a/discovery/kubernetes/node.go b/discovery/kubernetes/node.go index 677cb74b0..08c933b38 100644 --- a/discovery/kubernetes/node.go +++ b/discovery/kubernetes/node.go @@ -151,7 +151,8 @@ const ( ) func nodeLabels(n *apiv1.Node) model.LabelSet { - ls := make(model.LabelSet, len(n.Labels)+len(n.Annotations)+1) + // Each label and annotation will create two key-value pairs in the map. + ls := make(model.LabelSet, 2*(len(n.Labels)+len(n.Annotations))+1) ls[nodeNameLabel] = lv(n.Name) diff --git a/discovery/kubernetes/service.go b/discovery/kubernetes/service.go index 858ef36bd..ca01a5b38 100644 --- a/discovery/kubernetes/service.go +++ b/discovery/kubernetes/service.go @@ -149,7 +149,8 @@ const ( ) func serviceLabels(svc *apiv1.Service) model.LabelSet { - ls := make(model.LabelSet, len(svc.Labels)+len(svc.Annotations)+2) + // Each label and annotation will create two key-value pairs in the map. + ls := make(model.LabelSet, 2*(len(svc.Labels)+len(svc.Annotations))+2) ls[serviceNameLabel] = lv(svc.Name) ls[namespaceLabel] = lv(svc.Namespace)