1
0
Fork 0
mirror of https://github.com/kyverno/policy-reporter.git synced 2024-12-14 11:57:32 +00:00
policy-reporter/pkg/config/readinessprobe.go
Frank Jogeleit 78f24497fa
Policy Reporter v3 (#482)
Policy Reporter v3

Signed-off-by: Frank Jogeleit <frank.jogeleit@web.de>
2024-10-07 11:10:46 +02:00

53 lines
837 B
Go

package config
import (
"go.uber.org/zap"
)
type ReadinessProbe struct {
config *Config
ready chan bool
running bool
}
func (r *ReadinessProbe) required() bool {
if !r.config.REST.Enabled {
return false
}
return r.config.LeaderElection.Enabled
}
func (r *ReadinessProbe) Ready() {
if r.required() && !r.running {
go func() {
zap.L().Debug("readiness probe ready")
r.ready <- true
}()
}
}
func (r *ReadinessProbe) Wait() {
if r.required() && !r.running {
r.running = <-r.ready
zap.L().Debug("readiness probe finished")
return
}
}
func (r *ReadinessProbe) Close() {
close(r.ready)
}
func (r *ReadinessProbe) Running() bool {
return r.running
}
func NewReadinessProbe(config *Config) *ReadinessProbe {
return &ReadinessProbe{
config: config,
ready: make(chan bool),
running: false,
}
}