Skip to content

Commit

Permalink
cherry-pick kyverno#7810 (kyverno#7822)
Browse files Browse the repository at this point in the history
Signed-off-by: Mariam Fahmy <[email protected]>
  • Loading branch information
MariamFahmy98 authored Jul 13, 2023
1 parent 532c1a0 commit 515c1b4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions pkg/event/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,21 @@ func NewPolicyAppliedEvent(source Source, engineResponse engineapi.EngineRespons
var bldr strings.Builder
defer bldr.Reset()

var res string
if resource.GetNamespace() != "" {
fmt.Fprintf(&bldr, "%s %s/%s: pass", resource.GetKind(), resource.GetNamespace(), resource.GetName())
res = fmt.Sprintf("%s %s/%s", resource.GetKind(), resource.GetNamespace(), resource.GetName())
} else {
fmt.Fprintf(&bldr, "%s %s: pass", resource.GetKind(), resource.GetName())
res = fmt.Sprintf("%s %s", resource.GetKind(), resource.GetName())
}

hasValidate := engineResponse.Policy().GetSpec().HasValidate()
hasVerifyImages := engineResponse.Policy().GetSpec().HasVerifyImages()
hasMutate := engineResponse.Policy().GetSpec().HasMutate()

if hasValidate || hasVerifyImages {
fmt.Fprintf(&bldr, "%s: pass", res)
} else if hasMutate {
fmt.Fprintf(&bldr, "%s is successfully mutated", res)
}

return Info{
Expand Down
2 changes: 1 addition & 1 deletion pkg/webhooks/utils/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func GenerateEvents(engineResponses []engineapi.EngineResponse, blocked bool) []
// - Some/All policies skipped
// - report skipped event on resource
for _, er := range engineResponses {
if er.IsEmpty() {
if er.IsEmpty() || er.Resource.GetName() == "" {
continue
}
if !er.IsSuccessful() {
Expand Down

0 comments on commit 515c1b4

Please sign in to comment.