1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-09 17:37:12 +00:00
kyverno/pkg/engine/globalcontext/store/store.go
Khaled Emara 226fa9515a
feat: add globalcontext controller (#9601)
* feat: add globalcontext controller

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

* rework controller

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* rbac

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* cmd

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* fix rbac

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* engine

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* k8s resources

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* k8s resource

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* resync zero

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* api call

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* api call

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* clean

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* fix linter

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

---------

Signed-off-by: Khaled Emara <khaled.emara@nirmata.com>
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
Co-authored-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2024-02-02 10:41:35 +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, skip it before replacing it
if old != nil {
val.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)
}