1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00
Signed-off-by: ShutingZhao <shuting@nirmata.com>
This commit is contained in:
shuting 2023-03-03 18:51:34 +08:00 committed by GitHub
parent 7d573b30d2
commit e92405041e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -127,12 +127,12 @@ func NewBackgroundSuccessEvent(policy, rule string, source Source, r *unstructur
func NewPolicyExceptionEvents(source Source, engineResponse *response.EngineResponse, ruleResp *response.RuleResponse) []Info {
exceptionName, exceptionNamespace := getExceptionEventInfoFromRuleResponseMsg(ruleResp.Message)
policyMessage := fmt.Sprintf("resource %s was skipped from rule %s due to policy exception %s/%s", engineResponse.PatchedResource.GetName(), ruleResp.Name, exceptionNamespace, exceptionName)
policyMessage := fmt.Sprintf("resource %s was skipped from rule %s due to policy exception %s/%s", resourceKey(engineResponse.PatchedResource), ruleResp.Name, exceptionNamespace, exceptionName)
var exceptionMessage string
if engineResponse.PolicyResponse.Policy.Namespace == "" {
exceptionMessage = fmt.Sprintf("resource %s was skipped from policy rule %s/%s", engineResponse.PatchedResource.GetName(), engineResponse.PolicyResponse.Policy.Name, ruleResp.Name)
exceptionMessage = fmt.Sprintf("resource %s was skipped from policy rule %s/%s", resourceKey(engineResponse.PatchedResource), engineResponse.PolicyResponse.Policy.Name, ruleResp.Name)
} else {
exceptionMessage = fmt.Sprintf("resource %s was skipped from policy rule %s/%s/%s", engineResponse.PatchedResource.GetName(), engineResponse.PolicyResponse.Policy.Namespace, engineResponse.PolicyResponse.Policy.Name, ruleResp.Name)
exceptionMessage = fmt.Sprintf("resource %s was skipped from policy rule %s/%s/%s", resourceKey(engineResponse.PatchedResource), engineResponse.PolicyResponse.Policy.Namespace, engineResponse.PolicyResponse.Policy.Name, ruleResp.Name)
}
policyEvent := Info{
Kind: getPolicyKind(engineResponse.Policy),
@ -164,6 +164,13 @@ func getExceptionEventInfoFromRuleResponseMsg(message string) (name string, name
namespace = ""
name = arr[0]
}
return name, namespace
}
func resourceKey(resource unstructured.Unstructured) string {
if resource.GetNamespace() != "" {
return strings.Join([]string{resource.GetKind(), resource.GetNamespace(), resource.GetName()}, "/")
}
return strings.Join([]string{resource.GetKind(), resource.GetName()}, "/")
}