Ensure finalizer is always removed after one sync

Signed-off-by: James Munnelly <james@munnelly.eu>
This commit is contained in:
James Munnelly 2018-11-28 23:19:52 +00:00
parent 0656d6cf77
commit 93a7a89d4e

View File

@ -58,12 +58,6 @@ func (c *Controller) Sync(ctx context.Context, ch *cmapi.Challenge) (err error)
oldChal := ch oldChal := ch
ch = ch.DeepCopy() 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() { defer func() {
// TODO: replace with more efficient comparison // TODO: replace with more efficient comparison
if reflect.DeepEqual(oldChal.Status, ch.Status) && len(oldChal.Finalizers) == len(ch.Finalizers) { 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) 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) genericIssuer, err := c.helper.GetGenericIssuer(ch.Spec.IssuerRef, ch.Namespace)
if err != nil { if err != nil {
return fmt.Errorf("error reading (cluster)issuer %q: %v", ch.Spec.IssuerRef.Name, err) 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 { 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 { if len(ch.Finalizers) == 0 {
return nil return nil
} }
@ -190,6 +185,15 @@ func (c *Controller) handleFinalizer(ctx context.Context, ch *cmapi.Challenge) e
} }
ch.Finalizers = ch.Finalizers[1:] 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) solver, err := c.solverFor(ch.Spec.Type)
if err != nil { if err != nil {
glog.Errorf("Error getting solver for challenge %q (type %q): %v", ch.Name, ch.Spec.Type, err) glog.Errorf("Error getting solver for challenge %q (type %q): %v", ch.Name, ch.Spec.Type, err)