2022-09-09 12:48:29 +02:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2023-01-30 12:41:09 +01:00
|
|
|
engineapi "github.com/kyverno/kyverno/pkg/engine/api"
|
2022-09-09 12:48:29 +02:00
|
|
|
)
|
|
|
|
|
2023-01-30 12:41:09 +01:00
|
|
|
func GetErrorMsg(engineReponses []*engineapi.EngineResponse) string {
|
2022-09-09 12:48:29 +02:00
|
|
|
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.PolicyResponse.Resource.Kind, er.PolicyResponse.Resource.Namespace, er.PolicyResponse.Resource.Name)
|
|
|
|
str = append(str, fmt.Sprintf("failed policy %s:", er.PolicyResponse.Policy.Name))
|
|
|
|
for _, rule := range er.PolicyResponse.Rules {
|
2023-01-30 12:41:09 +01:00
|
|
|
if rule.Status != engineapi.RuleStatusPass {
|
2023-01-30 15:49:44 +01:00
|
|
|
str = append(str, rule.String())
|
2022-09-09 12:48:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("Resource %s %s", resourceInfo, strings.Join(str, ";"))
|
|
|
|
}
|