mirror of
https://github.com/helmfile/helmfile.git
synced 2026-10-20 22:52:51 +02:00
feat: add --repo-retries for helm repo and registry login commands (#2683)
* feat: add --repo-retries for retrying helm repo and registry login commands Add a configurable retry mechanism for chart repository operations to handle unstable networks (corporate proxies, slow internal registries). Closes #1894 - New --repo-retries N flag and HELMFILE_REPO_RETRIES env var (default 0 = opt-in, backward compatible) - Retry applies to helm repo add, helm repo update (incl. ACR), and helm registry login with exponential backoff (1s, 2s, 4s, ..., capped 30s) - Single retryRepoOp helper; per-attempt args/buffer are local to avoid state leaking across retries - Tests cover succeed-after-retry, exhausted-retries, disabled-by-default, and regression guards for password-buffer and args-accumulation Signed-off-by: yxxhero <aiopsclub@163.com> * fix: address PR review (overflow guard, cancellable sleep, flag-override, docs) Address Copilot review feedback on #2683: - Cap backoff shift exponent at 5 to prevent time.Duration overflow on large --repo-retries values - Make retry sleep context-aware (sleepCtx) so Ctrl+C aborts the retry loop promptly via the ShellRunner context - Log a concise exit status instead of the verbose ExitError dump, and clarify the retry-counter wording ('retry N/M') - Use -1 sentinel as the CLI default so --repo-retries=0 can explicitly disable retries even when HELMFILE_REPO_RETRIES is set - Align help text and docs: retry applies 'on failure' (not just transient errors), document the 0-disables behavior - Add tests for overflow guard, cancellable sleep, and flag-zero-disables Signed-off-by: yxxhero <aiopsclub@163.com> * fix: abort retries on canceled context, hide sentinel default, align comment Address follow-up Copilot review on #2683: - Fix tight-loop bug: sleepCtx now returns whether it completed vs was interrupted by context cancellation, and retryRepoOp aborts the retry loop on interruption so Ctrl+C no longer spins into rapid helm calls - Hide the -1 sentinel from --help by overriding the displayed default to 0 (pflag DefValue), matching the documented default while keeping the flag-override semantics - Correct HelmExecOptions.RepoRetry comment: 'on failure' not 'transient network errors', matching the actual retry behavior - Add Test_Retry_AbortsOnCanceledContext covering the no-tight-loop path Signed-off-by: yxxhero <aiopsclub@163.com> * fix: copy args per retry in RegistryLogin, make cancel test deterministic Address follow-up Copilot review on #2683: - RegistryLogin: pass a per-attempt copy of args to execStdIn so its internal append (for helm.extra) can't alias the shared slice across retries - Test_Retry_AbortsOnCanceledContext: cancel the context deterministically inside the op closure after the first attempt, replacing the flaky time.Sleep(20ms) goroutine Signed-off-by: yxxhero <aiopsclub@163.com> * fix: return error on unknown managed repo type instead of silent skip Address Copilot review on #2683: AddRepo logged an error for an unknown managed type but returned nil, silently succeeding while skipping the repo add. Now returns an error so misconfigurations fail loudly. Signed-off-by: yxxhero <aiopsclub@163.com> --------- Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
@@ -37,6 +37,7 @@ type App struct {
|
||||
DisableForceUpdate bool
|
||||
EnforcePluginVerification bool
|
||||
HelmOCIPlainHTTP bool
|
||||
RepoRetry int
|
||||
DisableKubeVersionAutoDetection bool
|
||||
SequentialHelmfiles bool
|
||||
|
||||
@@ -87,6 +88,7 @@ func New(conf ConfigProvider) *App {
|
||||
DisableForceUpdate: conf.DisableForceUpdate(),
|
||||
EnforcePluginVerification: conf.EnforcePluginVerification(),
|
||||
HelmOCIPlainHTTP: conf.HelmOCIPlainHTTP(),
|
||||
RepoRetry: conf.RepoRetry(),
|
||||
SequentialHelmfiles: conf.SequentialHelmfiles(),
|
||||
Logger: conf.Logger(),
|
||||
Kubeconfig: conf.Kubeconfig(),
|
||||
@@ -983,6 +985,7 @@ func (a *App) getHelm(st *state.HelmState) (helmexec.Interface, error) {
|
||||
DisableForceUpdate: a.DisableForceUpdate,
|
||||
EnforcePluginVerification: a.EnforcePluginVerification,
|
||||
HelmOCIPlainHTTP: a.HelmOCIPlainHTTP,
|
||||
RepoRetry: a.RepoRetry,
|
||||
}, a.Logger, kubeconfig, kubectx, &helmexec.ShellRunner{
|
||||
Logger: a.Logger,
|
||||
Ctx: a.ctx,
|
||||
|
||||
@@ -15,6 +15,7 @@ type ConfigProvider interface {
|
||||
DisableForceUpdate() bool
|
||||
EnforcePluginVerification() bool
|
||||
HelmOCIPlainHTTP() bool
|
||||
RepoRetry() int
|
||||
SkipDeps() bool
|
||||
SkipRefresh() bool
|
||||
SequentialHelmfiles() bool
|
||||
|
||||
Reference in New Issue
Block a user