1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00
kyverno/pkg/globalcontext/store/store.go
Khaled Emara 511df7a466
fix(globalcontext): old WaitGroup not stopping (#9813)
* fix(globalcontext): old waitgroup not stopping

Signed-off-by: Khaled Emara <khaled.emara@nirmata.com>

* chore(globalcontext): add AGE

Signed-off-by: Khaled Emara <khaled.emara@nirmata.com>

* feat(globalcontext): add lastRefreshTime

Signed-off-by: Khaled Emara <khaled.emara@nirmata.com>

* fix(globalcontext): unhandled intormer run exception

Signed-off-by: Khaled Emara <khaled.emara@nirmata.com>

* chore(globalcontext): comment wording

Signed-off-by: Khaled Emara <khaled.emara@nirmata.com>

* chore(globalcontext): codegen

Signed-off-by: Khaled Emara <khaled.emara@nirmata.com>

* fix(globalcontext): linter

Signed-off-by: Khaled Emara <khaled.emara@nirmata.com>

---------

Signed-off-by: Khaled Emara <khaled.emara@nirmata.com>
2024-02-27 18:24:39 +00:00

50 lines
759 B
Go

package store
import (
"sync"
)
type Store interface {
Set(key string, val Entry)
Get(key string) (Entry, bool)
Delete(key string)
}
type store struct {
sync.RWMutex
store map[string]Entry
}
func New() Store {
return &store{
store: make(map[string]Entry),
}
}
func (l *store) Set(key string, val Entry) {
l.Lock()
defer l.Unlock()
old := l.store[key]
// If the key already exists, stop it before replacing it
if old != nil {
old.Stop()
}
l.store[key] = val
}
func (l *store) Get(key string) (Entry, bool) {
l.RLock()
defer l.RUnlock()
entry, ok := l.store[key]
return entry, ok
}
func (l *store) Delete(key string) {
l.Lock()
defer l.Unlock()
entry := l.store[key]
if entry != nil {
entry.Stop()
}
delete(l.store, key)
}