From 93a7a89d4e79f9b8694a178d49a1ccc6f00a053f Mon Sep 17 00:00:00 2001 From: James Munnelly Date: Wed, 28 Nov 2018 23:19:52 +0000 Subject: [PATCH] Ensure finalizer is always removed after one sync Signed-off-by: James Munnelly --- pkg/controller/acmechallenges/sync.go | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/pkg/controller/acmechallenges/sync.go b/pkg/controller/acmechallenges/sync.go index 2c5a3ddbb..15a2f7eca 100644 --- a/pkg/controller/acmechallenges/sync.go +++ b/pkg/controller/acmechallenges/sync.go @@ -58,12 +58,6 @@ func (c *Controller) Sync(ctx context.Context, ch *cmapi.Challenge) (err error) oldChal := ch ch = ch.DeepCopy() - // bail out early on if processing=false, as this challenge has not been - // scheduled yet. - if ch.Status.Processing == false { - return nil - } - defer func() { // TODO: replace with more efficient comparison if reflect.DeepEqual(oldChal.Status, ch.Status) && len(oldChal.Finalizers) == len(ch.Finalizers) { @@ -79,6 +73,12 @@ func (c *Controller) Sync(ctx context.Context, ch *cmapi.Challenge) (err error) return c.handleFinalizer(ctx, ch) } + // bail out early on if processing=false, as this challenge has not been + // scheduled yet. + if ch.Status.Processing == false { + return nil + } + genericIssuer, err := c.helper.GetGenericIssuer(ch.Spec.IssuerRef, ch.Namespace) if err != nil { return fmt.Errorf("error reading (cluster)issuer %q: %v", ch.Spec.IssuerRef.Name, err) @@ -176,11 +176,6 @@ func (c *Controller) Sync(ctx context.Context, ch *cmapi.Challenge) (err error) } func (c *Controller) handleFinalizer(ctx context.Context, ch *cmapi.Challenge) error { - genericIssuer, err := c.helper.GetGenericIssuer(ch.Spec.IssuerRef, ch.Namespace) - if err != nil { - return fmt.Errorf("error reading (cluster)issuer %q: %v", ch.Spec.IssuerRef.Name, err) - } - if len(ch.Finalizers) == 0 { return nil } @@ -190,6 +185,15 @@ func (c *Controller) handleFinalizer(ctx context.Context, ch *cmapi.Challenge) e } ch.Finalizers = ch.Finalizers[1:] + if !ch.Status.Processing { + return nil + } + + genericIssuer, err := c.helper.GetGenericIssuer(ch.Spec.IssuerRef, ch.Namespace) + if err != nil { + return fmt.Errorf("error reading (cluster)issuer %q: %v", ch.Spec.IssuerRef.Name, err) + } + solver, err := c.solverFor(ch.Spec.Type) if err != nil { glog.Errorf("Error getting solver for challenge %q (type %q): %v", ch.Name, ch.Spec.Type, err)