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

fix: panic when response is nil (#5502)

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

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
Charles-Edouard Brétéché 2022-11-29 12:39:44 +01:00 committed by GitHub
parent dd4f1fb995
commit 938df21d4d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -38,6 +38,10 @@ func (inner AdmissionHandler) withMetrics(logger logr.Logger, metricsConfig conf
namespace := request.Namespace
if metricsConfig.CheckNamespace(namespace) {
operation := strings.ToLower(string(request.Operation))
allowed := true
if response != nil {
allowed = response.Allowed
}
if admissionReviewDurationMetric != nil {
defer func() {
latency := int64(time.Since(startTime))
@ -48,7 +52,7 @@ func (inner AdmissionHandler) withMetrics(logger logr.Logger, metricsConfig conf
attribute.String("resource_kind", request.Kind.Kind),
attribute.String("resource_namespace", namespace),
attribute.String("resource_request_operation", operation),
attribute.Bool("request_allowed", response.Allowed),
attribute.Bool("request_allowed", allowed),
)
}()
}
@ -59,7 +63,7 @@ func (inner AdmissionHandler) withMetrics(logger logr.Logger, metricsConfig conf
attribute.String("resource_kind", request.Kind.Kind),
attribute.String("resource_namespace", namespace),
attribute.String("resource_request_operation", operation),
attribute.Bool("request_allowed", response.Allowed),
attribute.Bool("request_allowed", allowed),
)
}
}