@@ -47,10 +47,14 @@ func NewObjectMetadataProvider(size int) ObjectMetadataProvider {
4747func (o * ObjectMetadataCache ) GetObjectMetadata (reference * v1.ObjectReference , clientset * kubernetes.Clientset , dynClient dynamic.Interface , metricsStore * metrics.Store ) (ObjectMetadata , error ) {
4848 // ResourceVersion changes when the object is updated.
4949 // We use "UID/ResourceVersion" as cache key so that if the object is updated we get the new metadata.
50- cacheKey := strings .Join ([]string {string (reference .UID ), reference .ResourceVersion }, "/" )
51- if val , ok := o .cache .Get (cacheKey ); ok {
52- metricsStore .KubeApiReadCacheHits .Inc ()
53- return val .(ObjectMetadata ), nil
50+ // UID and ResourceVersion are not always present, so we need to check if they exist before using them as cache key.
51+ var cacheKey string
52+ if reference .UID != "" && reference .ResourceVersion != "" {
53+ cacheKey := strings .Join ([]string {string (reference .UID ), reference .ResourceVersion }, "/" )
54+ if val , ok := o .cache .Get (cacheKey ); ok {
55+ metricsStore .KubeApiReadCacheHits .Inc ()
56+ return val .(ObjectMetadata ), nil
57+ }
5458 }
5559
5660 var group , version string
@@ -97,6 +101,9 @@ func (o *ObjectMetadataCache) GetObjectMetadata(reference *v1.ObjectReference, c
97101 objectMetadata .Deleted = true
98102 }
99103
100- o .cache .Add (cacheKey , objectMetadata )
104+ if cacheKey != "" {
105+ o .cache .Add (cacheKey , objectMetadata )
106+ }
107+
101108 return objectMetadata , nil
102109}
0 commit comments