From 0c01fc0fcec2443209c5d993e09a2a9ad0a0991e Mon Sep 17 00:00:00 2001 From: chongchuanbing Date: Thu, 14 Apr 2022 20:20:16 +0800 Subject: [PATCH] uid not exist for TaintManagerEviction event --- pkg/kube/annotations.go | 11 +++++++---- pkg/kube/labels.go | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/pkg/kube/annotations.go b/pkg/kube/annotations.go index 4f0470ad..a22973ef 100644 --- a/pkg/kube/annotations.go +++ b/pkg/kube/annotations.go @@ -32,9 +32,12 @@ func NewAnnotationCache(kubeconfig *rest.Config) *AnnotationCache { } func (a *AnnotationCache) GetAnnotationsWithCache(reference *v1.ObjectReference) (map[string]string, error) { - uid := reference.UID + cacheKey := string(reference.UID) + if len(cacheKey) == 0 { + cacheKey = reference.Name + } - if val, ok := a.cache.Get(uid); ok { + if val, ok := a.cache.Get(cacheKey); ok { return val.(map[string]string), nil } @@ -46,13 +49,13 @@ func (a *AnnotationCache) GetAnnotationsWithCache(reference *v1.ObjectReference) delete(annotations, key) } } - a.cache.Add(uid, annotations) + a.cache.Add(cacheKey, annotations) return annotations, nil } if errors.IsNotFound(err) { var empty map[string]string - a.cache.Add(uid, empty) + a.cache.Add(cacheKey, empty) return nil, nil } diff --git a/pkg/kube/labels.go b/pkg/kube/labels.go index 76e182e0..5ac39fde 100644 --- a/pkg/kube/labels.go +++ b/pkg/kube/labels.go @@ -31,16 +31,19 @@ func NewLabelCache(kubeconfig *rest.Config) (*LabelCache) { } func (l *LabelCache) GetLabelsWithCache(reference *v1.ObjectReference) (map[string]string, error) { - uid := reference.UID + cacheKey := string(reference.UID) + if len(cacheKey) == 0 { + cacheKey = reference.Name + } - if val, ok := l.cache.Get(uid); ok { + if val, ok := l.cache.Get(cacheKey); ok { return val.(map[string]string), nil } obj, err := GetObject(reference, l.clientset, l.dynClient) if err == nil { labels := obj.GetLabels() - l.cache.Add(uid, labels) + l.cache.Add(cacheKey, labels) return labels, nil } @@ -48,7 +51,7 @@ func (l *LabelCache) GetLabelsWithCache(reference *v1.ObjectReference) (map[stri // There can be events without the involved objects existing, they seem to be not garbage collected? // Marking it nil so that we can return faster var empty map[string]string - l.cache.Add(uid, empty) + l.cache.Add(cacheKey, empty) return nil, nil }