From 74a6a5a3193c83c5193e7e6cfecf1bf96c5ce858 Mon Sep 17 00:00:00 2001 From: Ole Markus With Date: Sat, 4 Mar 2023 07:02:25 +0100 Subject: [PATCH] Always try to prune an addon even if applying updates fail --- channels/pkg/channels/addon.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/channels/pkg/channels/addon.go b/channels/pkg/channels/addon.go index 16493be58f..b173194220 100644 --- a/channels/pkg/channels/addon.go +++ b/channels/pkg/channels/addon.go @@ -197,12 +197,26 @@ func (a *Addon) updateAddon(ctx context.Context, k8sClient kubernetes.Interface, return fmt.Errorf("error reading manifest: %w", err) } - if err := applier.Apply(ctx, data); err != nil { - return fmt.Errorf("error applying update from %q: %w", manifestURL, err) + var merr error + var applyError, pruneError error + + if applyError = applier.Apply(ctx, data); applyError != nil { + merr = multierr.Append(merr, fmt.Errorf("error applying update: %w", applyError)) } - if err := pruner.Prune(ctx, data, a.Spec.Prune); err != nil { - return fmt.Errorf("error pruning manifest from %q: %w", manifestURL, err) + if pruneError = pruner.Prune(ctx, data, a.Spec.Prune); pruneError != nil { + merr = multierr.Append(merr, fmt.Errorf("error pruning manifest: %w", pruneError)) + } + + if applyError != nil && pruneError == nil { + // If we failed to apply, but not prune, we should try to apply again + if err := applier.Apply(ctx, data); err != nil { + merr = multierr.Append(merr, fmt.Errorf("error applying update after prune: %w", err)) + } + } + + if merr != nil { + return fmt.Errorf("error updating addon from %q: %w", manifestURL, merr) } if err := a.AddNeedsUpdateLabel(ctx, k8sClient, required); err != nil {