Skip to content
This repository has been archived by the owner on Aug 31, 2022. It is now read-only.

cache bugfix #193

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
11 changes: 7 additions & 4 deletions pkg/kube/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down
11 changes: 7 additions & 4 deletions pkg/kube/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,27 @@ 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
}

if errors.IsNotFound(err) {
// 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
}

Expand Down