diff --git a/pkg/kube/objects.go b/pkg/kube/objects.go index 4231490a..82723d74 100644 --- a/pkg/kube/objects.go +++ b/pkg/kube/objects.go @@ -45,6 +45,11 @@ func NewObjectMetadataProvider(size int) ObjectMetadataProvider { } func (o *ObjectMetadataCache) GetObjectMetadata(reference *v1.ObjectReference, clientset *kubernetes.Clientset, dynClient dynamic.Interface, metricsStore *metrics.Store) (ObjectMetadata, error) { + // If name is empty, we cannot fetch metadata from API + if reference.Name == "" { + return ObjectMetadata{}, nil + } + // ResourceVersion changes when the object is updated. // We use "UID/ResourceVersion" as cache key so that if the object is updated we get the new metadata. // UID and ResourceVersion are not always present, so we need to check if they exist before using them as cache key. @@ -57,11 +62,6 @@ func (o *ObjectMetadataCache) GetObjectMetadata(reference *v1.ObjectReference, c } } - // If name is empty, we cannot fetch metadata from API - if reference.Name == "" { - return ObjectMetadata{}, nil - } - var group, version string s := strings.Split(reference.APIVersion, "/") if len(s) == 1 {