feat: skip chart prep for local (#1681)

* skip chart prep for local

Signed-off-by: zhaque44 <haque.zubair@gmail.com>

* rm whitespace

Signed-off-by: zhaque44 <haque.zubair@gmail.com>

* update based on linting comments

Signed-off-by: zhaque44 <haque.zubair@gmail.com>

* use func

Signed-off-by: zhaque44 <haque.zubair@gmail.com>

* update slices & handle concurrency

Signed-off-by: zhaque44 <haque.zubair@gmail.com>

* rm misc comment

Signed-off-by: zhaque44 <haque.zubair@gmail.com>

* default to 1 value

Signed-off-by: zhaque44 <haque.zubair@gmail.com>

* rm concurrency handling

Signed-off-by: zhaque44 <haque.zubair@gmail.com>

---------

Signed-off-by: zhaque44 <haque.zubair@gmail.com>
This commit is contained in:
Zubair Haque
2024-08-28 09:06:43 +08:00
committed by GitHub
parent 2cc995e508
commit 04a258dc15
+20 -11
View File
@@ -3,6 +3,7 @@ package app
import (
"fmt"
"os"
"slices"
"sort"
"strings"
@@ -39,6 +40,21 @@ func (r *Run) askForConfirmation(msg string) bool {
return AskForConfirmation(msg)
}
func (r *Run) prepareChartsIfNeeded(helmfileCommand string, dir string, concurrency int, opts state.ChartPrepareOptions) (map[state.PrepareChartKey]string, error) {
// Skip chart preparation for certain commands
skipCommands := []string{"write-values", "list"}
if slices.Contains(skipCommands, strings.ToLower(helmfileCommand)) {
return nil, nil
}
releaseToChart, errs := r.state.PrepareCharts(r.helm, dir, concurrency, helmfileCommand, opts)
if len(errs) > 0 {
return nil, fmt.Errorf("%v", errs)
}
return releaseToChart, nil
}
func (r *Run) withPreparedCharts(helmfileCommand string, opts state.ChartPrepareOptions, f func()) error {
if r.ReleaseToChart != nil {
panic("Run.PrepareCharts can be called only once")
@@ -71,12 +87,9 @@ func (r *Run) withPreparedCharts(helmfileCommand string, opts state.ChartPrepare
return err
}
concurrency := opts.Concurrency
releaseToChart, errs := r.state.PrepareCharts(r.helm, dir, concurrency, helmfileCommand, opts)
if len(errs) > 0 {
return fmt.Errorf("%v", errs)
releaseToChart, err := r.prepareChartsIfNeeded(helmfileCommand, dir, opts.Concurrency, opts)
if err != nil {
return err
}
for i := range r.state.Releases {
@@ -87,9 +100,6 @@ func (r *Run) withPreparedCharts(helmfileCommand string, opts state.ChartPrepare
KubeContext: rel.KubeContext,
}
if chart := releaseToChart[key]; chart != rel.Chart {
// In this case we assume that the chart is downloaded and modified by Helmfile and chartify.
// So we take note of the local filesystem path to the modified version of the chart
// and use it later via the Release.ChartPathOrName() func.
rel.ChartPath = chart
}
}
@@ -98,8 +108,7 @@ func (r *Run) withPreparedCharts(helmfileCommand string, opts state.ChartPrepare
f()
_, err := r.state.TriggerGlobalCleanupEvent(helmfileCommand)
_, err = r.state.TriggerGlobalCleanupEvent(helmfileCommand)
return err
}