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:
parent
7d573b30d2
commit
e92405041e
1 changed files with 11 additions and 4 deletions
|
@ -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()}, "/")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue