diff --git a/pkg/event/msgbuilder.go b/pkg/event/msgbuilder.go index 3dfdebaa64..364f4483e7 100644 --- a/pkg/event/msgbuilder.go +++ b/pkg/event/msgbuilder.go @@ -13,7 +13,7 @@ const ( FResourcePolcy MsgKey = iota FProcessRule SPolicyApply - SRuleApply + SRulesApply FPolicyApplyBlockCreate FPolicyApplyBlockUpdate FPolicyApplyBlockUpdateRule @@ -21,11 +21,11 @@ const ( func (k MsgKey) String() string { return [...]string{ - "Failed to satisfy policy on resource '%s'.The following rules '%s' failed to apply. Created Policy Violation", + "Failed to satisfy policy on resource '%s'.The following rule(s) '%s' failed to apply. Created Policy Violation", "Failed to process rule '%s' of policy '%s'. Created Policy Violation", "Policy applied successfully on the resource '%s'", - "Rules '%s' of Policy '%s' applied successful", - "Failed to apply policy, blocked creation of resource '%s'. The following rules '%s' failed to apply", + "Rule(s) '%s' of Policy '%s' applied successful", + "Resource %s blocked by rule(s) %s", "Failed to apply rule '%s' of policy '%s' Blocked update of the resource", "Failed to apply policy on resource '%s'.Blocked update of the resource. The following rules '%s' failed to apply", }[k] diff --git a/pkg/webhooks/server.go b/pkg/webhooks/server.go index 20dba701bb..d78021b9c2 100644 --- a/pkg/webhooks/server.go +++ b/pkg/webhooks/server.go @@ -382,33 +382,33 @@ func (ws *WebhookServer) bodyToAdmissionReview(request *http.Request, writer htt const policyKind = "Policy" -// func NewEventInfoFromPolicyInfo(policyInfoList []*info.PolicyInfo) []*event.Info { -// var eventsInfo []*event.Info +func NewEventInfoFromPolicyInfo(policyInfoList []*info.PolicyInfo) []*event.Info { + var eventsInfo []*event.Info -// ok, msg := isAdmSuccesful(policyInfoList) -// if ok { -// for _, pi := range policyInfoList { -// ruleNames := getRuleNames(*pi, true) -// eventsInfo = append(eventsInfo, -// event.NewEvent(pi.Kind, pi.Namespace+"/"+pi.Resource, event.PolicyApplied, event.SRulesApply, ruleNames, pi.Name)) + ok, msg := isAdmSuccesful(policyInfoList) + if ok { + for _, pi := range policyInfoList { + ruleNames := getRuleNames(*pi, true) + eventsInfo = append(eventsInfo, + event.NewEvent(pi.RKind, pi.RNamespace, pi.RName, event.PolicyApplied, event.SRulesApply, ruleNames, pi.Name)) -// eventsInfo = append(eventsInfo, -// event.NewEvent(policyKind, pi.Name, event.PolicyApplied, event.SPolicyApply, pi.Name, pi.Resource)) + eventsInfo = append(eventsInfo, + event.NewEvent(policyKind, "", pi.Name, event.PolicyApplied, event.SPolicyApply, pi.RName)) -// glog.V(3).Infof("Success events info prepared for %s/%s and %s/%s\n", policyKind, pi.Name, pi.Kind, pi.Resource) -// } -// return eventsInfo -// } + glog.V(3).Infof("Success events info prepared for %s/%s and %s/%s\n", policyKind, pi.Name, pi.RKind, pi.RName) + } + return eventsInfo + } -// for _, pi := range policyInfoList { -// ruleNames := getRuleNames(*pi, false) -// eventsInfo = append(eventsInfo, -// event.NewEvent(policyKind, pi.Name, event.RequestBlocked, event.FPolicyApplyBlockCreate, pi.Resource, ruleNames)) + for _, pi := range policyInfoList { + ruleNames := getRuleNames(*pi, false) + eventsInfo = append(eventsInfo, + event.NewEvent(policyKind, "", pi.Name, event.RequestBlocked, event.FPolicyApplyBlockCreate, pi.RName, ruleNames)) -// glog.V(3).Infof("Rule(s) %s of policy %s blocked resource creation, error: %s\n", ruleNames, pi.Name, msg) -// } -// return eventsInfo -// } + glog.V(3).Infof("Rule(s) %s of policy %s blocked resource creation, error: %s\n", ruleNames, pi.Name, msg) + } + return eventsInfo +} func getRuleNames(policyInfo info.PolicyInfo, onSuccess bool) string { var ruleNames []string