1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-31 03:45:17 +00:00

Changed error to info for NotFoundError in jsonContext (#2140)

* changed error to info for NotFoundError in jsonContext

Signed-off-by: Maxim Goncharenko <goncharenko.maxim@apriorit.com>

* raise log level for NotFoundError in jsonContext

Signed-off-by: Maxim Goncharenko <goncharenko.maxim@apriorit.com>
This commit is contained in:
Max Goncharenko 2021-07-15 00:50:28 +03:00 committed by GitHub
parent 003c865ab9
commit 0fdd349849
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 3 deletions

View file

@ -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{})

View file

@ -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
}

View file

@ -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
}