Skip to content

fix(template): include hooks on request - #416

Open
floriankoch wants to merge 1 commit into
manusa:mainfrom
floriankoch:fix-template-hooks
Open

floriankoch wants to merge 1 commit into
manusa:mainfrom
floriankoch:fix-template-hooks

Conversation

@floriankoch

Copy link
Copy Markdown

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

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

@manusa manusa left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 template does;
  • noHooks() to opt out (--no-hooks);
  • optionally skipTests() to drop test hooks only (--skip-tests). Today .includeHooks() also emits templates/tests/test-connection.yaml from 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 @author tag to the Java files you touched (TemplateCommand, TemplateOptions, HelmTemplateTest); make check-authors looks for them.
  • Heads-up: #433 (--output-dir) touches the same TemplateOptions struct, 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() {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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");

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With CLI semantics this assertion would flip (the hooks are present by default), and a separate noHooks() test would assert doesNotContain("marker: hook-manifest").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants