1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-15 17:51:20 +00:00

add debug env BACKGROUND_SCAN_INTERVAL (#7504)

Signed-off-by: ShutingZhao <shuting@nirmata.com>
This commit is contained in:
shuting 2023-06-13 20:21:40 +08:00 committed by GitHub
parent 8e5e2634fa
commit 9ce83958c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -44,6 +44,7 @@ func createrLeaderControllers(
metricsConfig metrics.MetricsConfigManager, metricsConfig metrics.MetricsConfigManager,
eventGenerator event.Interface, eventGenerator event.Interface,
jp jmespath.Interface, jp jmespath.Interface,
backgroundScanInterval time.Duration,
) ([]internal.Controller, error) { ) ([]internal.Controller, error) {
policyCtrl, err := policy.NewPolicyController( policyCtrl, err := policy.NewPolicyController(
kyvernoClient, kyvernoClient,
@ -56,7 +57,7 @@ func createrLeaderControllers(
eventGenerator, eventGenerator,
kubeInformer.Core().V1().Namespaces(), kubeInformer.Core().V1().Namespaces(),
logging.WithName("PolicyController"), logging.WithName("PolicyController"),
time.Hour, backgroundScanInterval,
metricsConfig, metricsConfig,
jp, jp,
) )
@ -91,6 +92,7 @@ func main() {
flagset.IntVar(&genWorkers, "genWorkers", 10, "Workers for the background controller.") flagset.IntVar(&genWorkers, "genWorkers", 10, "Workers for the background controller.")
flagset.IntVar(&maxQueuedEvents, "maxQueuedEvents", 1000, "Maximum events to be queued.") flagset.IntVar(&maxQueuedEvents, "maxQueuedEvents", 1000, "Maximum events to be queued.")
flagset.StringVar(&omitEvents, "omit-events", "", "Set this flag to a comma sperated list of PolicyViolation, PolicyApplied, PolicyError, PolicySkipped to disable events, e.g. --omit-events=PolicyApplied,PolicyViolation") flagset.StringVar(&omitEvents, "omit-events", "", "Set this flag to a comma sperated list of PolicyViolation, PolicyApplied, PolicyError, PolicySkipped to disable events, e.g. --omit-events=PolicyApplied,PolicyViolation")
// config // config
appConfig := internal.NewConfiguration( appConfig := internal.NewConfiguration(
internal.WithProfiling(), internal.WithProfiling(),
@ -111,6 +113,18 @@ func main() {
// setup // setup
signalCtx, setup, sdown := internal.Setup(appConfig, "kyverno-background-controller", false) signalCtx, setup, sdown := internal.Setup(appConfig, "kyverno-background-controller", false)
defer sdown() defer sdown()
var err error
bgscanInterval := time.Hour
val := os.Getenv("BACKGROUND_SCAN_INTERVAL")
if val != "" {
if bgscanInterval, err = time.ParseDuration(val); err != nil {
setup.Logger.Error(err, "failed to set the background scan interval")
os.Exit(1)
}
}
setup.Logger.V(2).Info("setting the background scan interval", "value", bgscanInterval.String())
// THIS IS AN UGLY FIX // THIS IS AN UGLY FIX
// ELSE KYAML IS NOT THREAD SAFE // ELSE KYAML IS NOT THREAD SAFE
kyamlopenapi.Schema() kyamlopenapi.Schema()
@ -180,6 +194,7 @@ func main() {
setup.MetricsManager, setup.MetricsManager,
eventGenerator, eventGenerator,
setup.Jp, setup.Jp,
bgscanInterval,
) )
if err != nil { if err != nil {
logger.Error(err, "failed to create leader controllers") logger.Error(err, "failed to create leader controllers")