mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-15 17:51:20 +00:00
f18f155816
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
26 lines
792 B
Go
26 lines
792 B
Go
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
engineapi "github.com/kyverno/kyverno/pkg/engine/api"
|
|
)
|
|
|
|
func GetErrorMsg(engineReponses []engineapi.EngineResponse) string {
|
|
var str []string
|
|
var resourceInfo string
|
|
for _, er := range engineReponses {
|
|
if !er.IsSuccessful() {
|
|
// resource in engineReponses is identical as this was called per admission request
|
|
resourceInfo = fmt.Sprintf("%s/%s/%s", er.Resource.GetKind(), er.Resource.GetNamespace(), er.Resource.GetName())
|
|
str = append(str, fmt.Sprintf("failed policy %s:", er.Policy().GetName()))
|
|
for _, rule := range er.PolicyResponse.Rules {
|
|
if rule.Status() != engineapi.RuleStatusPass {
|
|
str = append(str, rule.String())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return fmt.Sprintf("Resource %s %s", resourceInfo, strings.Join(str, ";"))
|
|
}
|