Skip to content

Commit

Permalink
Collect errors during reconciliaion in extension controller
Browse files Browse the repository at this point in the history
This way, the reconciliation gets as close as possible to the desired
state, even if some things in between are failing.

Signed-off-by: Tom Wieczorek <twieczorek@mirantis.com>
(cherry picked from commit e0aa6a4)
  • Loading branch information
twz123 committed Jul 4, 2024
1 parent 6dc802c commit 9db7b1e
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions pkg/component/controller/extensions_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,17 @@ func (ec *ExtensionsController) Reconcile(ctx context.Context, clusterConfig *k0
ec.L.Info("Extensions reconciliation started")
defer ec.L.Info("Extensions reconciliation finished")

var errs []error
helmSettings, err := ec.configureStorage(clusterConfig)
if err != nil {
return fmt.Errorf("cannot configure storage: %w", err)
errs = append(errs, fmt.Errorf("cannot configure storage: %w", err))
}

if err := ec.reconcileHelmExtensions(helmSettings); err != nil {
return fmt.Errorf("can't reconcile helm based extensions: %w", err)
errs = append(errs, fmt.Errorf("can't reconcile helm based extensions: %w", err))
}

return nil
return errors.Join(errs...)
}

func (ec *ExtensionsController) configureStorage(clusterConfig *k0sAPI.ClusterConfig) (*k0sAPI.HelmExtensions, error) {
Expand Down Expand Up @@ -171,9 +172,10 @@ func (ec *ExtensionsController) reconcileHelmExtensions(helmSpec *k0sAPI.HelmExt
return nil
}

var errs []error
for _, repo := range helmSpec.Repositories {
if err := ec.addRepo(repo); err != nil {
return fmt.Errorf("can't init repository %q: %w", repo.URL, err)
errs = append(errs, fmt.Errorf("can't init repository %q: %w", repo.URL, err))
}
}

Expand All @@ -191,13 +193,16 @@ func (ec *ExtensionsController) reconcileHelmExtensions(helmSpec *k0sAPI.HelmExt
}
buf := bytes.NewBuffer([]byte{})
if err := tw.WriteToBuffer(buf); err != nil {
return fmt.Errorf("can't create chart CR instance %q: %w", chart.ChartName, err)
errs = append(errs, fmt.Errorf("can't create chart CR instance %q: %w", chart.ChartName, err))
continue
}
if err := ec.saver.Save(chart.ManifestFileName(), buf.Bytes()); err != nil {
return fmt.Errorf("can't save addon CRD manifest for chart CR instance %q: %w", chart.ChartName, err)
errs = append(errs, fmt.Errorf("can't save addon CRD manifest for chart CR instance %q: %w", chart.ChartName, err))
continue
}
}
return nil

return errors.Join(errs...)
}

type ChartReconciler struct {
Expand Down

0 comments on commit 9db7b1e

Please sign in to comment.