1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00

chore: move more constants (#7944)

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
Charles-Edouard Brétéché 2023-07-31 16:51:23 +02:00 committed by GitHub
parent d28ba3b980
commit 524d93f413
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 12 additions and 19 deletions

View file

@ -3,7 +3,9 @@ package kyverno
const (
// Well known labels
LabelAppManagedBy = "app.kubernetes.io/managed-by"
LabelAppComponent = "app.kubernetes.io/component"
LabelCertManagedBy = "cert.kyverno.io/managed-by"
LabelWebhookManagedBy = "webhook.kyverno.io/managed-by"
// Well known annotations
AnnotationAutogenControllers = "pod-policies.kyverno.io/autogen-controllers"
AnnotationPolicyCategory = "policies.kyverno.io/category"

View file

@ -11,7 +11,6 @@ import (
"github.com/kyverno/kyverno/pkg/controllers"
"github.com/kyverno/kyverno/pkg/logging"
"github.com/kyverno/kyverno/pkg/tls"
"github.com/kyverno/kyverno/pkg/utils"
controllerutils "github.com/kyverno/kyverno/pkg/utils/controller"
admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
corev1 "k8s.io/api/core/v1"
@ -156,7 +155,7 @@ func objectMeta(name string, annotations map[string]string, owner ...metav1.Owne
return metav1.ObjectMeta{
Name: name,
Labels: map[string]string{
utils.ManagedByLabel: kyverno.ValueKyvernoApp,
kyverno.LabelWebhookManagedBy: kyverno.ValueKyvernoApp,
},
Annotations: annotations,
OwnerReferences: owner,

View file

@ -18,7 +18,6 @@ import (
"github.com/kyverno/kyverno/pkg/config"
"github.com/kyverno/kyverno/pkg/controllers"
"github.com/kyverno/kyverno/pkg/tls"
"github.com/kyverno/kyverno/pkg/utils"
controllerutils "github.com/kyverno/kyverno/pkg/utils/controller"
kubeutils "github.com/kyverno/kyverno/pkg/utils/kube"
runtimeutils "github.com/kyverno/kyverno/pkg/utils/runtime"
@ -889,7 +888,7 @@ func (c *controller) mergeWebhook(dst *webhook, policy kyvernov1.PolicyInterface
func (c *controller) buildOwner() []metav1.OwnerReference {
selector := labels.SelectorFromSet(labels.Set(map[string]string{
utils.KyvernoComponentLabel: "kyverno",
kyverno.LabelAppComponent: "kyverno",
}))
clusterroles, err := c.clusterroleLister.List(selector)

View file

@ -5,7 +5,6 @@ import (
"github.com/kyverno/kyverno/api/kyverno"
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
"github.com/kyverno/kyverno/pkg/utils"
"golang.org/x/exp/slices"
admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -89,7 +88,7 @@ func objectMeta(name string, annotations map[string]string, owner ...metav1.Owne
return metav1.ObjectMeta{
Name: name,
Labels: map[string]string{
utils.ManagedByLabel: kyverno.ValueKyvernoApp,
kyverno.LabelWebhookManagedBy: kyverno.ValueKyvernoApp,
},
Annotations: annotations,
OwnerReferences: owner,

View file

@ -1,6 +0,0 @@
package utils
const (
ManagedByLabel = "webhook.kyverno.io/managed-by"
KyvernoComponentLabel = "app.kubernetes.io/component"
)

View file

@ -8,12 +8,12 @@ import (
"github.com/go-logr/logr"
"github.com/julienschmidt/httprouter"
"github.com/kyverno/kyverno/api/kyverno"
"github.com/kyverno/kyverno/pkg/clients/dclient"
"github.com/kyverno/kyverno/pkg/config"
"github.com/kyverno/kyverno/pkg/logging"
"github.com/kyverno/kyverno/pkg/metrics"
"github.com/kyverno/kyverno/pkg/toggle"
"github.com/kyverno/kyverno/pkg/utils"
controllerutils "github.com/kyverno/kyverno/pkg/utils/controller"
runtimeutils "github.com/kyverno/kyverno/pkg/utils/runtime"
"github.com/kyverno/kyverno/pkg/webhooks/handlers"
@ -236,16 +236,16 @@ func (s *server) cleanup(ctx context.Context) {
}
deleteVwc := func() {
if err := s.vwcClient.DeleteCollection(ctx, metav1.DeleteOptions{}, metav1.ListOptions{
LabelSelector: utils.ManagedByLabel,
LabelSelector: kyverno.LabelWebhookManagedBy,
}); err != nil && !apierrors.IsNotFound(err) {
logger.Error(err, "failed to clean up validating webhook configuration", "label", utils.ManagedByLabel)
logger.Error(err, "failed to clean up validating webhook configuration", "label", kyverno.LabelWebhookManagedBy)
}
}
deleteMwc := func() {
if err := s.mwcClient.DeleteCollection(ctx, metav1.DeleteOptions{}, metav1.ListOptions{
LabelSelector: utils.ManagedByLabel,
LabelSelector: kyverno.LabelWebhookManagedBy,
}); err != nil && !apierrors.IsNotFound(err) {
logger.Error(err, "failed to clean up mutating webhook configuration", "label", utils.ManagedByLabel)
logger.Error(err, "failed to clean up mutating webhook configuration", "label", kyverno.LabelWebhookManagedBy)
}
}
deleteLease("kyvernopre-lock")