@@ -1260,7 +1260,7 @@ func overrideRemediationAction(instance *policiesv1.Policy, tObjectUnstructured
12601260func (r * PolicyReconciler ) emitTemplateSuccess (
12611261 ctx context.Context , pol * policiesv1.Policy , tIndex int , tName string , clusterScoped bool , msg string ,
12621262) error {
1263- err := r .emitTemplateEvent (ctx , pol , tIndex , tName , clusterScoped , "Normal" , " Compliant; " , msg )
1263+ err := r .emitTemplateEvent (ctx , pol , tIndex , tName , clusterScoped , "Normal" , policiesv1 . Compliant , msg )
12641264 if err != nil {
12651265 tlog := log .WithValues ("Policy.Namespace" , pol .Namespace , "Policy.Name" , pol .Name , "template" , tName )
12661266 tlog .Error (err , "Failed to emit template success event" )
@@ -1276,7 +1276,7 @@ func (r *PolicyReconciler) emitTemplateError(
12761276 ctx context.Context , pol * policiesv1.Policy , tIndex int , tName string , clusterScoped bool , errMsg string ,
12771277) error {
12781278 err := r .emitTemplateEvent (ctx , pol , tIndex , tName , clusterScoped ,
1279- "Warning" , " NonCompliant; template-error; ", errMsg )
1279+ "Warning" , policiesv1 . NonCompliant , " template-error; "+ errMsg )
12801280 if err != nil {
12811281 tlog := log .WithValues ("Policy.Namespace" , pol .Namespace , "Policy.Name" , pol .Name , "template" , tName )
12821282 tlog .Error (err , "Failed to emit template error event" )
@@ -1291,16 +1291,16 @@ func (r *PolicyReconciler) emitTemplateError(
12911291func (r * PolicyReconciler ) emitTemplatePending (
12921292 ctx context.Context , pol * policiesv1.Policy , tIndex int , tName string , clusterScoped bool , msg string ,
12931293) error {
1294- msgMeta := " Pending; "
1294+ compliance := policiesv1 . Pending
12951295 eventType := "Warning"
12961296
12971297 if pol .Spec .PolicyTemplates [tIndex ].IgnorePending {
1298- msgMeta = " Compliant; "
1298+ compliance = policiesv1 . Compliant
12991299 msg += " but ignorePending is true"
13001300 eventType = "Normal"
13011301 }
13021302
1303- err := r .emitTemplateEvent (ctx , pol , tIndex , tName , clusterScoped , eventType , msgMeta , msg )
1303+ err := r .emitTemplateEvent (ctx , pol , tIndex , tName , clusterScoped , eventType , compliance , msg )
13041304 if err != nil {
13051305 tlog := log .WithValues ("Policy.Namespace" , pol .Namespace , "Policy.Name" , pol .Name , "template" , tName )
13061306 tlog .Error (err , "Failed to emit template pending event" )
@@ -1310,14 +1310,13 @@ func (r *PolicyReconciler) emitTemplatePending(
13101310}
13111311
13121312// emitTemplateEvent performs actions that ensure correct reporting of template sync events. If the
1313- // policy's status already reflects the current status, then no actions are taken. The msgMeta and
1314- // msg are concatenated without spaces, so any spacing should be included inside the msgMeta string.
1313+ // policy's status already reflects the current status, then no actions are taken.
13151314func (r * PolicyReconciler ) emitTemplateEvent (
13161315 ctx context.Context , pol * policiesv1.Policy , tIndex int , tName string , clusterScoped bool ,
1317- eventType string , msgMeta string , msg string ,
1316+ eventType string , compliance policiesv1. ComplianceState , msg string ,
13181317) error {
13191318 // check if the error is already present in the policy status - if so, return early
1320- if strings .Contains (getLatestStatusMessage (pol , tIndex ), msgMeta + msg ) {
1319+ if strings .Contains (getLatestStatusMessage (pol , tIndex ), string ( compliance ) + "; " + msg ) {
13211320 return nil
13221321 }
13231322
@@ -1346,16 +1345,7 @@ func (r *PolicyReconciler) emitTemplateEvent(
13461345 UID : pol .UID ,
13471346 }
13481347
1349- var compState policiesv1.ComplianceState
1350- if strings .HasPrefix (msgMeta , "Compliant" ) {
1351- compState = policiesv1 .Compliant
1352- } else if strings .HasPrefix (msgMeta , "NonCompliant" ) {
1353- compState = policiesv1 .NonCompliant
1354- } else if strings .HasPrefix (msgMeta , "Pending" ) {
1355- compState = policiesv1 .Pending
1356- }
1357-
1358- return sender .SendEvent (ctx , nil , ownerref , policyComplianceReason , msgMeta + msg , compState )
1348+ return sender .SendEvent (ctx , nil , ownerref , policyComplianceReason , msg , compliance )
13591349}
13601350
13611351// handleSyncSuccess performs common actions that should be run whenever a template is in sync,
0 commit comments