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:
parent
dd4f1fb995
commit
938df21d4d
1 changed files with 6 additions and 2 deletions
|
@ -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),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue