Skip to content

Commit

Permalink
Don't requeue if the template is invalid
Browse files Browse the repository at this point in the history
Signed-off-by: Dale Haiducek <19750917+dhaiducek@users.noreply.github.com>
(cherry picked from commit d684146)
  • Loading branch information
dhaiducek authored and magic-mirror-bot[bot] committed Sep 29, 2023
1 parent dba5abd commit 84df5e2
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions controllers/templatesync/template_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,17 +450,16 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
continue
}

// reject if not configuration policy and has template strings
// reject if not configuration policy and has template strings, and don't requeue
if gvk.Kind != "ConfigurationPolicy" {
// if not configuration policies, do a simple check for templates {{hub and reject
// only checking for hub and not {{ as they could be valid cases where they are valid chars.
if strings.Contains(string(policyT.ObjectDefinition.Raw), "{{hub ") {
errMsg := fmt.Sprintf("Templates are not supported for kind : %s", gvk.Kind)
resultError = k8serrors.NewBadRequest(errMsg)

_ = r.emitTemplateError(ctx, instance, tIndex, tName, isClusterScoped, errMsg)

tLogger.Error(resultError, "Failed to process the policy template")
tLogger.Error(k8serrors.NewBadRequest(errMsg), "Failed to process the policy template")

policyUserErrorsCounter.WithLabelValues(instance.Name, tName, "format-error").Inc()

Expand Down Expand Up @@ -559,7 +558,6 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
)
}

resultError = err
errMsg := fmt.Sprintf("Failed to create policy template: %s", err)

_ = r.emitTemplateError(ctx, instance, tIndex, tName, isClusterScoped, errMsg)
Expand All @@ -571,6 +569,9 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
policyUserErrorsCounter.WithLabelValues(instance.Name, tName, "format-error").Inc()
} else {
policySystemErrorsCounter.WithLabelValues(instance.Name, tName, "create-error").Inc()

// Only requeue if the policy template is valid
resultError = err
}

continue
Expand Down Expand Up @@ -757,7 +758,6 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
return reconcile.Result{}, err
}

resultError = err
errMsg := fmt.Sprintf("Failed to update policy template %s: %s", tName, err)

_ = r.emitTemplateError(ctx, instance, tIndex, tName, isClusterScoped, errMsg)
Expand All @@ -769,6 +769,9 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
policyUserErrorsCounter.WithLabelValues(instance.Name, tName, "format-error").Inc()
} else {
policySystemErrorsCounter.WithLabelValues(instance.Name, tName, "patch-error").Inc()

// Only requeue if the policy template is valid
resultError = err
}

continue
Expand Down

0 comments on commit 84df5e2

Please sign in to comment.