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

fix: remove filtering for policy admission handlers (#5462)

* fix: remove filtering for policy admission handlers

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

* move kyverno filtering

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

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
Co-authored-by: Prateek Pandey <prateek.pandey@nirmata.com>
This commit is contained in:
Charles-Edouard Brétéché 2022-11-25 09:21:39 +01:00 committed by GitHub
parent 42221a93e4
commit 67bd7b1edc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 5 additions and 9 deletions

View file

@ -6,6 +6,7 @@ import (
"github.com/go-logr/logr"
"github.com/kyverno/kyverno/pkg/config"
webhookutils "github.com/kyverno/kyverno/pkg/webhooks/utils"
admissionv1 "k8s.io/api/admission/v1"
)
@ -18,6 +19,9 @@ func (inner AdmissionHandler) withFilter(c config.Configuration) AdmissionHandle
if c.ToFilter(request.Kind.Kind, request.Namespace, request.Name) {
return nil
}
if webhookutils.ExcludeKyvernoResources(request.Kind.Kind) {
return nil
}
return inner(ctx, logger, request, startTime)
}
}

View file

@ -43,6 +43,6 @@ func (h *handlers) Validate(ctx context.Context, logger logr.Logger, request *ad
return admissionutils.Response(err, warnings...)
}
func (h *handlers) Mutate(ctx context.Context, logger logr.Logger, request *admissionv1.AdmissionRequest, _ time.Time) *admissionv1.AdmissionResponse {
func (h *handlers) Mutate(_ context.Context, _ logr.Logger, _ *admissionv1.AdmissionRequest, _ time.Time) *admissionv1.AdmissionResponse {
return admissionutils.ResponseSuccess()
}

View file

@ -95,9 +95,6 @@ func NewHandlers(
}
func (h *handlers) Validate(ctx context.Context, logger logr.Logger, request *admissionv1.AdmissionRequest, failurePolicy string, startTime time.Time) *admissionv1.AdmissionResponse {
if webhookutils.ExcludeKyvernoResources(request.Kind.Kind) {
return admissionutils.ResponseSuccess()
}
kind := request.Kind.Kind
logger = logger.WithValues("kind", kind)
logger.V(4).Info("received an admission request in validating webhook")
@ -145,9 +142,6 @@ func (h *handlers) Validate(ctx context.Context, logger logr.Logger, request *ad
}
func (h *handlers) Mutate(ctx context.Context, logger logr.Logger, request *admissionv1.AdmissionRequest, failurePolicy string, startTime time.Time) *admissionv1.AdmissionResponse {
if webhookutils.ExcludeKyvernoResources(request.Kind.Kind) {
return admissionutils.ResponseSuccess()
}
if request.Operation == admissionv1.Delete {
return admissionutils.ResponseSuccess()
}

View file

@ -103,7 +103,6 @@ func NewServer(
"POST",
config.PolicyMutatingWebhookServicePath,
handlers.FromAdmissionFunc("MUTATE", policyHandlers.Mutate).
WithFilter(configuration).
WithDump(debugModeOpts.DumpPayload).
WithMetrics(metricsConfig).
WithAdmission(policyLogger.WithName("mutate")).
@ -113,7 +112,6 @@ func NewServer(
"POST",
config.PolicyValidatingWebhookServicePath,
handlers.FromAdmissionFunc("VALIDATE", policyHandlers.Validate).
WithFilter(configuration).
WithDump(debugModeOpts.DumpPayload).
WithMetrics(metricsConfig).
WithAdmission(policyLogger.WithName("validate")).