1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-07 00:17:13 +00:00
kyverno/pkg/controllers/webhook/recorder.go
shuting 9aebe10d15
refactor: status manager (#12173)
* chore: move webhook status reconciler

Signed-off-by: ShutingZhao <shuting@nirmata.com>

* fix: status removal

Signed-off-by: ShutingZhao <shuting@nirmata.com>

---------

Signed-off-by: ShutingZhao <shuting@nirmata.com>
2025-02-14 15:22:25 +00:00

48 lines
781 B
Go

package webhook
import (
"sync"
)
type Recorder struct {
lock sync.Mutex
data map[string]bool
NotifyChan chan string
}
type StateRecorder interface {
Ready(string) (bool, bool)
Record(string)
Reset()
}
func NewStateRecorder(notifyChan chan string) StateRecorder {
return &Recorder{
data: make(map[string]bool),
NotifyChan: notifyChan,
}
}
func (s *Recorder) Ready(key string) (bool, bool) {
s.lock.Lock()
defer s.lock.Unlock()
ready, ok := s.data[key]
return ready, ok
}
func (s *Recorder) Record(key string) {
s.lock.Lock()
defer s.lock.Unlock()
s.data[key] = true
if s.NotifyChan != nil {
s.NotifyChan <- key
}
}
func (s *Recorder) Reset() {
s.lock.Lock()
defer s.lock.Unlock()
for d := range s.data {
s.data[d] = false
}
}