From 0fdd349849eeee491fdf6aa651eea6d0422f2a97 Mon Sep 17 00:00:00 2001 From: Max Goncharenko Date: Thu, 15 Jul 2021 00:50:28 +0300 Subject: [PATCH] Changed error to info for NotFoundError in jsonContext (#2140) * changed error to info for NotFoundError in jsonContext Signed-off-by: Maxim Goncharenko * raise log level for NotFoundError in jsonContext Signed-off-by: Maxim Goncharenko --- pkg/engine/jsonContext.go | 2 +- pkg/engine/mutation.go | 7 ++++++- pkg/engine/validation.go | 6 +++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/pkg/engine/jsonContext.go b/pkg/engine/jsonContext.go index 2aefaf401d..20f500abe5 100644 --- a/pkg/engine/jsonContext.go +++ b/pkg/engine/jsonContext.go @@ -86,7 +86,7 @@ func loadAPIData(logger logr.Logger, entry kyverno.ContextEntry, ctx *PolicyCont results, err := applyJMESPath(path.(string), jsonData) if err != nil { - return fmt.Errorf("failed to apply JMESPath for context entry %v: %v", entry, err) + return err } contextNamedData := make(map[string]interface{}) diff --git a/pkg/engine/mutation.go b/pkg/engine/mutation.go index 65ae60c4bd..0e688e75e4 100644 --- a/pkg/engine/mutation.go +++ b/pkg/engine/mutation.go @@ -5,6 +5,7 @@ import ( "time" "github.com/go-logr/logr" + gojmespath "github.com/jmespath/go-jmespath" kyverno "github.com/kyverno/kyverno/pkg/api/kyverno/v1" "github.com/kyverno/kyverno/pkg/engine/mutate" "github.com/kyverno/kyverno/pkg/engine/response" @@ -71,7 +72,11 @@ func Mutate(policyContext *PolicyContext) (resp *response.EngineResponse) { policyContext.JSONContext.Restore() if err := LoadContext(logger, rule.Context, resCache, policyContext, rule.Name); err != nil { - logger.Error(err, "failed to load context") + if _, ok := err.(gojmespath.NotFoundError); ok { + logger.V(3).Info("failed to load context", "reason", err.Error()) + } else { + logger.Error(err, "failed to load context") + } continue } diff --git a/pkg/engine/validation.go b/pkg/engine/validation.go index a3bb9b8397..ff4f8b5b3d 100644 --- a/pkg/engine/validation.go +++ b/pkg/engine/validation.go @@ -101,7 +101,11 @@ func validateResource(log logr.Logger, ctx *PolicyContext) *response.EngineRespo ctx.JSONContext.Restore() if err := LoadContext(log, rule.Context, ctx.ResourceCache, ctx, rule.Name); err != nil { - log.Error(err, "failed to load context") + if _, ok := err.(gojmespath.NotFoundError); ok { + log.V(3).Info("failed to load context", "reason", err.Error()) + } else { + log.Error(err, "failed to load context") + } continue }