From ab16605fa8406d255832ccc01c9271b7eccec87c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 26 Apr 2026 04:37:51 +0000 Subject: [PATCH] fix: clean up stale templates dir on re-runs in Helm 3 post-renderer workaround Agent-Logs-Url: https://github.com/helmfile/helmfile/sessions/f6c66284-8eca-4db3-8711-c9b6d3a9c179 Co-authored-by: yxxhero <11087727+yxxhero@users.noreply.github.com> --- pkg/helmexec/exec.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/helmexec/exec.go b/pkg/helmexec/exec.go index acc73fc6..9478dd41 100644 --- a/pkg/helmexec/exec.go +++ b/pkg/helmexec/exec.go @@ -695,6 +695,11 @@ func (helm *execer) TemplateRelease(name string, chart string, flags ...string) return fmt.Errorf("failed to remove legacy output file %s: %w", legacyOutputPath, removeErr) } + // Clean up any stale files from previous runs before writing new output. + if removeErr := os.RemoveAll(templatesDir); removeErr != nil { + return fmt.Errorf("failed to remove stale templates directory %s: %w", templatesDir, removeErr) + } + if len(out) > 0 { if mkdirErr := os.MkdirAll(templatesDir, 0755); mkdirErr != nil { return fmt.Errorf("failed to create templates directory %s: %w", templatesDir, mkdirErr)