Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pkg/kube/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Cache: Empty Name Prevents Unique Object Retrieval

Moving the empty name check before the cache lookup prevents returning valid cached metadata when reference.Name is empty but reference.UID and reference.ResourceVersion are present. The cache key is based on UID and ResourceVersion, so cached data for that object should still be returned even if the name is missing from the current reference, as the UID/ResourceVersion pair uniquely identifies the object.

Fix in Cursor Fix in Web


// 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.
Expand All @@ -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 {
Expand Down