@@ -47,10 +47,14 @@ func NewObjectMetadataProvider(size int) ObjectMetadataProvider {
47
47
func (o * ObjectMetadataCache ) GetObjectMetadata (reference * v1.ObjectReference , clientset * kubernetes.Clientset , dynClient dynamic.Interface , metricsStore * metrics.Store ) (ObjectMetadata , error ) {
48
48
// ResourceVersion changes when the object is updated.
49
49
// 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
+ }
54
58
}
55
59
56
60
var group , version string
@@ -97,6 +101,9 @@ func (o *ObjectMetadataCache) GetObjectMetadata(reference *v1.ObjectReference, c
97
101
objectMetadata .Deleted = true
98
102
}
99
103
100
- o .cache .Add (cacheKey , objectMetadata )
104
+ if cacheKey != "" {
105
+ o .cache .Add (cacheKey , objectMetadata )
106
+ }
107
+
101
108
return objectMetadata , nil
102
109
}
0 commit comments