1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-15 17:51:20 +00:00
kyverno/cmd/internal/configmap.go
Charles-Edouard Brétéché 3f51e99109
refactor: configuration config map controller (#6829)
* refactor: configuration config map 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>

* fix

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>

* clean

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

* fix

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

* fix

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

---------

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2023-04-11 12:05:20 +00:00

52 lines
1.6 KiB
Go

package internal
import (
"context"
"time"
"github.com/go-logr/logr"
"github.com/kyverno/kyverno/pkg/config"
genericconfigmapcontroller "github.com/kyverno/kyverno/pkg/controllers/generic/configmap"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes"
)
const (
resyncPeriod = 15 * time.Minute
)
func startConfigController(ctx context.Context, logger logr.Logger, client kubernetes.Interface, skipResourceFilters bool) config.Configuration {
configuration := config.NewDefaultConfiguration(skipResourceFilters)
configurationController := genericconfigmapcontroller.NewController(
"config-controller",
client,
resyncPeriod,
config.KyvernoNamespace(),
config.KyvernoConfigMapName(),
func(ctx context.Context, cm *corev1.ConfigMap) error {
configuration.Load(cm)
return nil
},
)
checkError(logger, configurationController.WarmUp(ctx), "failed to init config controller")
go configurationController.Run(ctx, 1)
return configuration
}
func startMetricsConfigController(ctx context.Context, logger logr.Logger, client kubernetes.Interface) config.MetricsConfiguration {
configuration := config.NewDefaultMetricsConfiguration()
configurationController := genericconfigmapcontroller.NewController(
"metrics-config-controller",
client,
resyncPeriod,
config.KyvernoNamespace(),
config.KyvernoMetricsConfigMapName(),
func(ctx context.Context, cm *corev1.ConfigMap) error {
configuration.Load(cm)
return nil
},
)
checkError(logger, configurationController.WarmUp(ctx), "failed to init metrics config controller")
go configurationController.Run(ctx, 1)
return configuration
}