Skip to content

feat: support --output-dir on helm template #329

@abcqdsdchina

Description

@abcqdsdchina

Background

helm template --output-dir <dir> writes each rendered manifest to a separate file under <dir> instead of concatenating to stdout. With --use-release-name, files go under <dir>/<release-name>/. Common use: GitOps workflows that commit rendered manifests to a repo.

Helm SDK exposes this as (*action.Install).OutputDir (install.go:93) — template internally uses an Install action with ClientOnly=true.

Acceptance criteria

  • TemplateCommand.withOutputDir(Path dir) writes each manifest to a separate file under dir
  • TemplateCommand.useReleaseName() toggles the <dir>/<release-name>/ nesting (matches helm CLI's --use-release-name)
  • Without withOutputDir, current behavior is preserved (concatenated YAML returned as string)
  • Test asserts the expected files exist under the output dir and contain the expected manifests

Proposed Java API

helm.template()
    .withOutputDir(Paths.get("/tmp/rendered"))
    .useReleaseName()
    .call();
// → files like /tmp/rendered/release-name/templates/deployment.yaml

Implementation guide

Reference impl to copy patterns from: existing TemplateCommand + template.go (which delegates to install(...) internally).

Go (native/internal/helm/install.go + template.go)

  • Add OutputDir string and UseReleaseName bool to InstallOptions struct (internal Go type). Only template will set these; install ignores them — that's fine.
  • In install(...), set client.OutputDir = options.OutputDir and client.UseReleaseName = options.UseReleaseName.
  • In template.go, plumb the new fields from TemplateOptions → the internal InstallOptions call.

CGO bridge (native/main.go)

  • Add char* outputDir; and int useReleaseName; to struct TemplateOptions. Field order must match the JNA struct.
  • Pass through to helm.TemplateOptions{OutputDir, UseReleaseName}.

JNA + Java

  • Add public String outputDir; public int useReleaseName; to lib/api/.../TemplateOptions.java. Update @Structure.FieldOrder and constructor.
  • Add withOutputDir(Path) and useReleaseName() builders to TemplateCommand.

Tests

  • Add to HelmTemplateTest.
  • Use @TempDir for the output dir.
  • Scenarios:
    • withOutputDir: after .call(), assert files exist (e.g. dir/templates/<chart-name>/...)
    • withOutputDir + useReleaseName: assert files are nested under <release-name>/
    • No output dir: stdout return value still contains all manifests (existing behavior unchanged)

Contributor checklist

  • Java 8 syntax only
  • Apache 2.0 header
  • @author Javadoc tag
  • DCO sign-off
  • make build-native && ./mvnw test -pl helm-java -Dtest=HelmTemplateTest green

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions