Repository navigation
fix(template): include hooks on request - #416
floriankoch wants to merge 1 commit into
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
bc56d60 to
bbdd5b8
Compare
manusa
left a comment
There was a problem hiding this comment.
Pull Request Review: #416
Thanks for picking this up! The problem is real: helm template prints a chart's hooks (including test hooks) after the regular manifests, but TemplateCommand currently drops them, so anyone following the rendered-manifests pattern loses resources. I rendered the same chart (a helm create chart plus a pre-install hook) with upstream Helm v3.22.1 and with this branch rebased onto current main: with .includeHooks() the output is byte-for-byte identical to helm template. The branch also applies cleanly on top of main (43 commits behind), and the Go template tests pass.
Main point: default and naming
helm-java mirrors the Helm CLI flags, and in the CLI hooks are on by default: helm template renders them unless --no-hooks is passed, and --skip-tests drops only the helm.sh/hook: test ones (cmd/helm/template.go, the if !client.DisableHooks block). UninstallCommand already follows that naming with noHooks().
So the CLI-consistent API would be:
- render hooks by default, the way
helm templatedoes; noHooks()to opt out (--no-hooks);- optionally
skipTests()to drop test hooks only (--skip-tests). Today.includeHooks()also emitstemplates/tests/test-connection.yamlfrom the default chart, which is what the CLI does without--skip-tests.
This changes what template() returns for existing users, but I'd rather go for CLI parity, since that is what people compare the output with. I'll call the change out in the release notes. Could you switch the PR to these semantics?
With CLI semantics, withDefaults in both HelmTemplateTest and template_test.go would assert that the hook is present, and a new noHooks test would assert that it is absent.
Smaller things
- Please add your
@authortag to the Java files you touched (TemplateCommand,TemplateOptions,HelmTemplateTest);make check-authorslooks for them. - Heads-up: #433 (
--output-dir) touches the sameTemplateOptionsstruct, so whichever lands second will need a small rebase. If both land, hooks should go to files when an output directory is set, the way the CLI does, rather than into the returned string.
The CI run for this PR never started any job, so it will need a re-run after a rebase.
| * | ||
| * @return this {@link TemplateCommand} instance. | ||
| */ | ||
| public TemplateCommand includeHooks() { |
There was a problem hiding this comment.
helm template renders hooks unless --no-hooks is set, and UninstallCommand already exposes that flag as noHooks(). Would you consider flipping this to hooks-on-by-default plus noHooks() (and maybe skipTests() for --skip-tests), so the builder maps one to one to the CLI flags? See the review summary for the trade-off.
| if _, fmtErr := fmt.Fprintln(&manifests, strings.TrimSpace(rel.Manifest)); fmtErr != nil { | ||
| return "", fmtErr | ||
| } | ||
| if options.IncludeHooks { |
There was a problem hiding this comment.
The rendering matches the CLI exactly (I compared the output with helm template from Helm v3.22.1 and it is identical). If you go with CLI semantics, this would become if !options.NoHooks, with a SkipTests check for hooks whose events include release.HookTest, as in cmd/helm/template.go.
| assertThat(result) | ||
| .contains("name: release-name-local-chart-test"); | ||
| .contains("name: release-name-local-chart-test") | ||
| .doesNotContain("marker: hook-manifest"); |
There was a problem hiding this comment.
With CLI semantics this assertion would flip (the hooks are present by default), and a separate noHooks() test would assert doesNotContain("marker: hook-manifest").
Add the ability to render the helm hooks.
This is needed when you follow the rendered manifest pattern, and use e.g. flux to rollout the generated manifests