mirror of
https://github.com/helmfile/helmfile.git
synced 2026-09-30 13:27:18 +02:00
* feat: allow helmfile to continue on failed releases Co-authored-by: Peter Honeder <peter.honeder@unwired.at> Signed-off-by: Niklas Ott <niklas.ott@unwired.at> * fix: skip failed-prep releases, complete flag wiring, add tests and docs (#64) Review follow-ups for --allow-failed-releases (#2616): - Track per-release chart preparation failures in PrepareCharts (returned as a map keyed by release) and remove those releases from the state in Run.WithPreparedCharts when --allow-failed-releases is set, so a failed release is never executed against its original, un-prepared chart reference (which could either fail again with a duplicate error or, for charts requiring chartify, bypass patches/dependency modifications and produce an unintended result). All failures are still reported at the end via the aggregated MultiError. - Complete the release identity on error results from prepareChartForRelease so failures are attributed to the correct release. - With --allow-failed-releases, continue building dependencies of the remaining charts when 'helm dep build' fails for one release, and skip the affected releases during execution. - Wire --allow-failed-releases into 'helmfile unittest' and 'helmfile status'; remove the dead flag wiring for write-values and list (both never prepare charts, see commandsSkipChartPrep). - Simplify control flow (guard clauses, errors.As, drop dead code and redundant else branches). - Add end-to-end coverage in pkg/app/issue_2616_test.go and extend the state-level tests; document the flag in docs/cli.md and CHANGELOG.md. Signed-off-by: yxxhero <11087727+yxxhero@users.noreply.github.com> --------- Signed-off-by: Niklas Ott <niklas.ott@unwired.at> Signed-off-by: yxxhero <11087727+yxxhero@users.noreply.github.com> Co-authored-by: Peter Honeder <peter.honeder@unwired.at> Co-authored-by: yxxhero <11087727+yxxhero@users.noreply.github.com>
99 lines
3.4 KiB
Go
99 lines
3.4 KiB
Go
package state
|
|
|
|
import (
|
|
"sync"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"go.uber.org/zap"
|
|
|
|
"github.com/helmfile/helmfile/pkg/exectest"
|
|
)
|
|
|
|
// issue2616HelmfileContent defines two releases: one that prepares fine
|
|
// (grafana) and one that always fails chart preparation (error), because OCI
|
|
// charts do not support the "latest" version tag.
|
|
var issue2616HelmfileContent = []byte(`
|
|
repositories:
|
|
- name: stable
|
|
url: kubernetes-charts.storage.googleapis.com
|
|
oci: true
|
|
|
|
releases:
|
|
- name: grafana
|
|
namespace: grafana
|
|
chart: stable/grafana
|
|
- name: error
|
|
namespace: failed
|
|
chart: oci://example.com/chart/error
|
|
version: latest
|
|
`)
|
|
|
|
// issue2616PrepareCharts runs PrepareCharts for issue2616HelmfileContent.
|
|
func issue2616PrepareCharts(t *testing.T, opts ChartPrepareOptions) (map[PrepareChartKey]string, map[PrepareChartKey]error, []error) {
|
|
t.Helper()
|
|
|
|
resetChartCacheForTest()
|
|
|
|
logger := zap.NewExample().Sugar()
|
|
|
|
st, err := createFromYaml(issue2616HelmfileContent, "example/path/to/helmfile.yaml", DefaultEnv, logger)
|
|
require.NoError(t, err)
|
|
|
|
tempDir := t.TempDir()
|
|
|
|
helm := &exectest.Helm{
|
|
ChartsMutex: &sync.Mutex{},
|
|
}
|
|
|
|
// OutputDirTemplate includes .OutputDir so charts go into tempDir (auto-cleaned
|
|
// by t.TempDir), not the global cache or CWD.
|
|
opts.OutputDirTemplate = "{{ .OutputDir }}/{{ .Release.Name }}"
|
|
|
|
releaseToChart, failedReleases, errs := st.PrepareCharts(helm, tempDir, 1, "apply", opts)
|
|
return releaseToChart, failedReleases, errs
|
|
}
|
|
|
|
// TestAllowFailedReleasesFlag_Enabled verifies that the AllowFailedReleases flag
|
|
// works as intended with one release that should work and another release, that
|
|
// will fail: the healthy release is prepared and reported in the partial
|
|
// results, while the failing one is recorded in failedReleases so that callers
|
|
// can skip it during execution.
|
|
func TestAllowFailedReleasesFlag_Enabled(t *testing.T) {
|
|
releaseToChart, failedReleases, errs := issue2616PrepareCharts(t, ChartPrepareOptions{
|
|
Concurrency: 1,
|
|
AllowFailedReleases: true,
|
|
})
|
|
|
|
require.NotEmpty(t, errs, "PrepareCharts should return an error")
|
|
|
|
// Verify only the error chart is not prepared
|
|
assert.Contains(t, releaseToChart, PrepareChartKey{Name: "grafana", Namespace: "grafana"},
|
|
"grafana chart should be prepared")
|
|
assert.NotContains(t, releaseToChart, PrepareChartKey{Name: "error", Namespace: "failed"},
|
|
"error chart should not be prepared")
|
|
|
|
// Verify the failed release is attributed per-release, so that the caller
|
|
// can skip it instead of executing it against the un-prepared chart
|
|
assert.NotContains(t, failedReleases, PrepareChartKey{Name: "grafana", Namespace: "grafana"},
|
|
"grafana should not be marked as failed")
|
|
failedKey := PrepareChartKey{Name: "error", Namespace: "failed"}
|
|
assert.Contains(t, failedReleases, failedKey, "the failing release should be marked as failed")
|
|
assert.Error(t, failedReleases[failedKey])
|
|
}
|
|
|
|
// TestAllowFailedReleasesFlag_Disabled verifies that the AllowFailedReleases flag
|
|
// has no unintended side effects and the default abort on error still works.
|
|
func TestAllowFailedReleasesFlag_Disabled(t *testing.T) {
|
|
releaseToChart, failedReleases, errs := issue2616PrepareCharts(t, ChartPrepareOptions{
|
|
Concurrency: 1,
|
|
})
|
|
|
|
require.NotEmpty(t, errs, "PrepareCharts should return an error")
|
|
|
|
// Verify no partial results are returned on the default abort-on-error path
|
|
assert.Nil(t, releaseToChart)
|
|
assert.Nil(t, failedReleases)
|
|
}
|