Skip to content

Commit

Permalink
Error when template for workflow doesn't exist
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
chrisdoherty4 committed Jun 21, 2022
1 parent 88798fa commit 19b68be
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion pkg/controllers/workflow/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/workflow/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ tasks:
ResourceVersion: "999",
},
},
wantErr: nil,
wantErr: errors.New("no template found: name=debian; namespace=default"),
},
// *****
{
Expand Down

0 comments on commit 19b68be

Please sign in to comment.