Skip to content

Commit

Permalink
Fix returning non-empty reconcile result and error
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-innis committed Oct 20, 2023
1 parent 5593eb4 commit aab6a75
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
5 changes: 4 additions & 1 deletion pkg/controllers/interruption/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ func (c *Controller) Reconcile(ctx context.Context, _ reconcile.Request) (reconc
}
errs[i] = c.deleteMessage(ctx, sqsMessages[i])
})
return reconcile.Result{}, multierr.Combine(errs...)
if err = multierr.Combine(errs...); err != nil {
return reconcile.Result{}, err
}
return reconcile.Result{}, nil
}

func (c *Controller) Name() string {
Expand Down
5 changes: 4 additions & 1 deletion pkg/controllers/nodeclaim/garbagecollection/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,11 @@ func (c *Controller) Reconcile(ctx context.Context, _ reconcile.Request) (reconc
errs[i] = c.garbageCollect(ctx, managedRetrieved[i], nodeList)
}
})
if err = multierr.Combine(errs...); err != nil {
return reconcile.Result{}, err
}
c.successfulCount++
return reconcile.Result{RequeueAfter: lo.Ternary(c.successfulCount <= 20, time.Second*10, time.Minute*2)}, multierr.Combine(errs...)
return reconcile.Result{RequeueAfter: lo.Ternary(c.successfulCount <= 20, time.Second*10, time.Minute*2)}, nil
}

func (c *Controller) garbageCollect(ctx context.Context, nodeClaim *v1beta1.NodeClaim, nodeList *v1.NodeList) error {
Expand Down
5 changes: 4 additions & 1 deletion pkg/controllers/nodeclaim/link/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,11 @@ func (c *Controller) Reconcile(ctx context.Context, _ reconcile.Request) (reconc
workqueue.ParallelizeUntil(ctx, 100, len(retrieved), func(i int) {
errs[i] = c.link(ctx, retrieved[i], machineList.Items)
})
if err = multierr.Combine(errs...); err != nil {
return reconcile.Result{}, err
}
// Effectively, don't requeue this again once it succeeds
return reconcile.Result{RequeueAfter: math.MaxInt64}, multierr.Combine(errs...)
return reconcile.Result{RequeueAfter: math.MaxInt64}, nil
}

func (c *Controller) link(ctx context.Context, retrieved *v1beta1.NodeClaim, existingMachines []v1alpha5.Machine) error {
Expand Down
7 changes: 1 addition & 6 deletions pkg/controllers/nodeclaim/tagging/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,25 @@ func (c *Controller) Name() string {

func (c *Controller) Reconcile(ctx context.Context, nodeClaim *corev1beta1.NodeClaim) (reconcile.Result, error) {
stored := nodeClaim.DeepCopy()

if !isTaggable(nodeClaim) {
return reconcile.Result{}, nil
}

ctx = logging.WithLogger(ctx, logging.FromContext(ctx).With("provider-id", nodeClaim.Status.ProviderID))
id, err := utils.ParseInstanceID(nodeClaim.Status.ProviderID)
if err != nil {
// We don't throw an error here since we don't want to retry until the ProviderID has been updated.
logging.FromContext(ctx).Errorf("failed to parse instance ID, %w", err)
return reconcile.Result{}, nil
}

if err := c.tagInstance(ctx, nodeClaim, id); err != nil {
if err = c.tagInstance(ctx, nodeClaim, id); err != nil {
return reconcile.Result{}, cloudprovider.IgnoreNodeClaimNotFoundError(err)
}

nodeClaim.Annotations = lo.Assign(nodeClaim.Annotations, map[string]string{v1beta1.AnnotationInstanceTagged: "true"})
if !equality.Semantic.DeepEqual(nodeClaim, stored) {
if err := c.kubeClient.Patch(ctx, nodeClaim, client.MergeFrom(stored)); err != nil {
return reconcile.Result{}, client.IgnoreNotFound(err)
}
}

return reconcile.Result{}, nil
}

Expand Down
5 changes: 4 additions & 1 deletion pkg/controllers/nodeclass/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ func (c *Controller) Reconcile(ctx context.Context, nodeClass *v1beta1.EC2NodeCl
err = multierr.Append(err, client.IgnoreNotFound(patchErr))
}
}
return reconcile.Result{RequeueAfter: 5 * time.Minute}, err
if err != nil {
return reconcile.Result{}, err
}
return reconcile.Result{RequeueAfter: 5 * time.Minute}, nil
}

func (c *Controller) Finalize(ctx context.Context, nodeClass *v1beta1.EC2NodeClass) (reconcile.Result, error) {
Expand Down

0 comments on commit aab6a75

Please sign in to comment.