From 19b68beab1a902846c10ee3422cafb4fd5c3307e Mon Sep 17 00:00:00 2001 From: Chris Doherty Date: Tue, 21 Jun 2022 14:55:21 -0400 Subject: [PATCH] Error when template for workflow doesn't exist When the template referenced by a workflow doesn't exist we need to throw an error to trigger requeueing continuously until the template becomes available. If it doesn't, logging will indicate as much as it will note the errors. Signed-off-by: Chris Doherty --- pkg/controllers/workflow/controller.go | 10 +++++++++- pkg/controllers/workflow/controller_test.go | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/controllers/workflow/controller.go b/pkg/controllers/workflow/controller.go index 8f7b8d3c6..b60639fa3 100644 --- a/pkg/controllers/workflow/controller.go +++ b/pkg/controllers/workflow/controller.go @@ -36,6 +36,9 @@ func NewController(kubeClient client.Client) *Controller { // +kubebuilder:rbac:groups=tinkerbell.org,resources=workflows;workflows/status,verbs=get;list;watch;update;patch;delete func (c *Controller) Reconcile(ctx context.Context, req reconcile.Request) (reconcile.Result, error) { + logger := controllerruntime.LoggerFrom(ctx) + logger.Info("Reconciling") + stored := &v1alpha1.Workflow{} if err := c.kubeClient.Get(ctx, req.NamespacedName, stored); err != nil { if errors.IsNotFound(err) { @@ -74,7 +77,12 @@ func (c *Controller) processNewWorkflow(ctx context.Context, stored *v1alpha1.Wo tpl := &v1alpha1.Template{} if err := c.kubeClient.Get(ctx, client.ObjectKey{Name: stored.Spec.TemplateRef, Namespace: stored.Namespace}, tpl); err != nil { if errors.IsNotFound(err) { - return reconcile.Result{}, nil + // Throw an error to raise awareness and take advantage of immediate requeue. + return reconcile.Result{}, fmt.Errorf( + "no template found: name=%v; namespace=%v", + stored.Spec.TemplateRef, + stored.Namespace, + ) } return controllers.RetryIfError(ctx, err) } diff --git a/pkg/controllers/workflow/controller_test.go b/pkg/controllers/workflow/controller_test.go index 9b0defd02..cc64f8450 100644 --- a/pkg/controllers/workflow/controller_test.go +++ b/pkg/controllers/workflow/controller_test.go @@ -416,7 +416,7 @@ tasks: ResourceVersion: "999", }, }, - wantErr: nil, + wantErr: errors.New("no template found: name=debian; namespace=default"), }, // ***** {