@@ -450,17 +450,16 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
450450 continue
451451 }
452452
453- // reject if not configuration policy and has template strings
453+ // reject if not configuration policy and has template strings, and don't requeue
454454 if gvk .Kind != "ConfigurationPolicy" {
455455 // if not configuration policies, do a simple check for templates {{hub and reject
456456 // only checking for hub and not {{ as they could be valid cases where they are valid chars.
457457 if strings .Contains (string (policyT .ObjectDefinition .Raw ), "{{hub " ) {
458458 errMsg := fmt .Sprintf ("Templates are not supported for kind : %s" , gvk .Kind )
459- resultError = k8serrors .NewBadRequest (errMsg )
460459
461460 _ = r .emitTemplateError (ctx , instance , tIndex , tName , isClusterScoped , errMsg )
462461
463- tLogger .Error (resultError , "Failed to process the policy template" )
462+ tLogger .Error (k8serrors . NewBadRequest ( errMsg ) , "Failed to process the policy template" )
464463
465464 policyUserErrorsCounter .WithLabelValues (instance .Name , tName , "format-error" ).Inc ()
466465
@@ -559,7 +558,6 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
559558 )
560559 }
561560
562- resultError = err
563561 errMsg := fmt .Sprintf ("Failed to create policy template: %s" , err )
564562
565563 _ = r .emitTemplateError (ctx , instance , tIndex , tName , isClusterScoped , errMsg )
@@ -571,6 +569,9 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
571569 policyUserErrorsCounter .WithLabelValues (instance .Name , tName , "format-error" ).Inc ()
572570 } else {
573571 policySystemErrorsCounter .WithLabelValues (instance .Name , tName , "create-error" ).Inc ()
572+
573+ // Only requeue if the policy template is valid
574+ resultError = err
574575 }
575576
576577 continue
@@ -757,7 +758,6 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
757758 return reconcile.Result {}, err
758759 }
759760
760- resultError = err
761761 errMsg := fmt .Sprintf ("Failed to update policy template %s: %s" , tName , err )
762762
763763 _ = r .emitTemplateError (ctx , instance , tIndex , tName , isClusterScoped , errMsg )
@@ -769,6 +769,9 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
769769 policyUserErrorsCounter .WithLabelValues (instance .Name , tName , "format-error" ).Inc ()
770770 } else {
771771 policySystemErrorsCounter .WithLabelValues (instance .Name , tName , "patch-error" ).Inc ()
772+
773+ // Only requeue if the policy template is valid
774+ resultError = err
772775 }
773776
774777 continue
0 commit comments