diff --git a/lib/promscrape/discovery/kubernetes/api.go b/lib/promscrape/discovery/kubernetes/api.go index ca77b10de..913826a3a 100644 --- a/lib/promscrape/discovery/kubernetes/api.go +++ b/lib/promscrape/discovery/kubernetes/api.go @@ -305,8 +305,13 @@ func (uw *urlWatcher) reloadObjects() string { logger.Errorf("cannot parse response from %q: %s", requestURL, err) return "" } + labelsByKey := make(map[string][]map[string]string, len(objectsByKey)) + for k, o := range objectsByKey { + labelsByKey[k] = o.getTargetLabels(uw) + } uw.mu.Lock() uw.objectsByKey = objectsByKey + uw.labelsByKey = labelsByKey uw.mu.Unlock() return metadata.ResourceVersion }