Skip to content

Commit

Permalink
controller: requeue without error on render failure
Browse files Browse the repository at this point in the history
  • Loading branch information
abursavich committed Nov 7, 2019
1 parent 21b391d commit 3ed4514
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions pkg/controllers/configmapsecret_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,20 @@ func (r *ConfigMapSecret) Reconcile(req reconcile.Request) (reconcile.Result, er
secretNames, configMapNames := varRefs(cms.Spec.Vars)
r.setRefs(cms.Namespace, cms.Name, secretNames, configMapNames)

return reconcile.Result{}, r.sync(ctx, log, cms)
requeue, err := r.sync(ctx, log, cms)
return reconcile.Result{Requeue: requeue}, err
}

func (r *ConfigMapSecret) sync(ctx context.Context, log logr.Logger, cms *v1alpha1.ConfigMapSecret) error {
func (r *ConfigMapSecret) sync(ctx context.Context, log logr.Logger, cms *v1alpha1.ConfigMapSecret) (bool, error) {
secret, reason, err := r.renderSecret(ctx, cms)
if err != nil {
defer r.syncRenderFailureStatus(ctx, log, cms, reason, err.Error())
if isConfigError(err) {
// TODO: controller-runtime will still log this as an error... is there any way to avoid it?
log.Info("Unable to render ConfigMapSecret", "warning", err)
} else {
log.Error(err, "Unable to render ConfigMapSecret")
return true, nil
}
r.syncRenderFailureStatus(ctx, log, cms, reason, err.Error())
return err
log.Error(err, "Unable to render ConfigMapSecret")
return false, err
}

key := types.NamespacedName{Namespace: secret.Namespace, Name: secret.Name}
Expand All @@ -169,18 +169,18 @@ func (r *ConfigMapSecret) sync(ctx context.Context, log logr.Logger, cms *v1alph
secretLog.Info("Creating Secret")
if err := r.client.Create(ctx, secret); err != nil {
secretLog.Error(err, "Unable to create Secret")
return err
return false, err
}
return r.syncSuccessStatus(ctx, log, cms)
return false, r.syncSuccessStatus(ctx, log, cms)
}
secretLog.Error(err, "Unable to get Secret")
return err
return false, err
}

// Confirm or take ownership.
ownerChanged, err := r.setOwner(secretLog, cms, found)
if err != nil {
return err
return false, err
}

// Update the object and write the result back if there are any changes
Expand All @@ -192,10 +192,10 @@ func (r *ConfigMapSecret) sync(ctx context.Context, log logr.Logger, cms *v1alph
secretLog.Info("Updating Secret")
if err := r.client.Update(ctx, found); err != nil {
secretLog.Error(err, "Unable to update Secret")
return err
return false, err
}
}
return r.syncSuccessStatus(ctx, log, cms)
return false, r.syncSuccessStatus(ctx, log, cms)
}

func (r *ConfigMapSecret) setOwner(log logr.Logger, cms *v1alpha1.ConfigMapSecret, secret *corev1.Secret) (bool, error) {
Expand Down

0 comments on commit 3ed4514

Please sign in to comment.