Skip to content

feat: support output directories for helm template - #433

Open
Ishubhammohole wants to merge 1 commit into
manusa:mainfrom
Ishubhammohole:feature-329-output-dir
Open

Ishubhammohole wants to merge 1 commit into
manusa:mainfrom
Ishubhammohole:feature-329-output-dir

Conversation

@Ishubhammohole

Copy link
Copy Markdown

Summary

  • Added withOutputDir(Path) and useReleaseName() to the template command API
  • Wired both options through JNA and CGO to Helm's native install action
  • Added Go and Java regression tests for manifest files and release-name nesting

Testing

  • go test ./internal/helm -run '^TestTemplateFromLocal$' -count=1 — passed
  • make test-go — passed
  • go vet ./... — passed
  • make build-native — passed
  • mvn test -pl helm-java -am -Dtest=HelmTemplateTest -Dsurefire.failIfNoSpecifiedTests=false -Denforcer.skipRules=requireFilesExist — passed (16 tests)
  • make build-current-platform — 106 passed, 2 skipped, 5 unrelated environment failures: two macOS native-keychain logout expectations and three signing fixtures whose resource paths contain the workspace's URL-encoded %20
  • make check-authors — existing repository-wide check reports 8 unrelated files; all modified Java files include the contributor author tag

AI-assisted development was used following the repository's AGENTS.md workflow; the implementation, generated native interface alignment, diff, and reported results were reviewed before submission.

Fixes #329

Signed-off-by: Shubham Mohole <95623059+Ishubhammohole@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: #433

Thanks for this, and for following the implementation guide in #329 so closely! withOutputDir(Path) and useReleaseName() do what the issue asks. I applied the branch on top of current main (it is 33 commits behind and applies cleanly), built it, and compared it with upstream Helm v3.22.1 on the same chart:

  • withOutputDir(dir) writes dir/<chart>/templates/*.yaml, and useReleaseName() nests them under dir/<release-name>/. Both match helm template --output-dir / --release-name. Every non-hook file is identical to the CLI's.
  • The Go template tests on the branch pass.

A couple of things before this is ready:

1. call() returns null when an output directory is set

With an output directory, Helm writes the manifests to disk and leaves rel.Manifest empty. Template then returns only a newline, and the native bridge turns a blank string into NULL (toCString in native/main.go). So helm.template().withOutputDir(dir).call() returns null from a String API. I hit this in a small program against the public API. Both new Java tests ignore the return value, so they don't notice.

Could you either return something meaningful, such as the list of written files (the CLI prints a wrote <path> line per file, and those lines already reach Result.stdOut), or at least return an empty string? Please document it in the withOutputDir Javadoc and add an assertion on the return value to the tests.

2. Hooks are not written to the output directory

helm template --output-dir also writes hook manifests, including test hooks, into the directory (cmd/helm/template.go, the if !client.DisableHooks block). With this branch, templates/hook.yaml and templates/tests/test-connection.yaml are missing compared with the CLI. This is the same pre-existing gap that #416 addresses for the stdout case, so it doesn't have to be solved here. Whichever of the two PRs lands second should make sure hooks go to files when an output directory is set, not into the returned string. Note that the two PRs also touch the same TemplateOptions fields, so one of them will need a small rebase.

Minor

  • useReleaseName() only has an effect together with withOutputDir(...), and its CLI counterpart is --release-name. Mentioning both in the Javadoc would help users find it.
  • The README's template example lists every option; adding .withOutputDir(...) and .useReleaseName() there would keep it complete.

The CI run for this PR never started any job, so it will need a re-run after a rebase.

* @param outputDir the directory for rendered manifest files.
* @return this {@link TemplateCommand} instance.
*/
public TemplateCommand withOutputDir(Path outputDir) {

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.

When this is set, call() returns null: Helm writes the manifests to disk and leaves rel.Manifest empty, and toCString in native/main.go turns the remaining blank string into NULL. Could call() return the written file list (the wrote <path> lines are already captured in Result.stdOut), or at least an empty string? Either way, please document the return value here.

}

/**
* Include the release name in the output directory path.

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.

Nit: maybe mention that this only applies together with withOutputDir(...) and maps to the CLI's --release-name flag.

@Test
void withOutputDir() throws IOException {
final Path outputDir = tempDir.resolve("rendered");
helm.template().withOutputDir(outputDir).call();

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 return value of call() is dropped here. Asserting on it, for example isNotNull() or the list of written files, would cover the API contract. Today it would fail, because call() returns null.

ValuesFiles: options.ValuesFiles,
Debug: options.Debug,
RepositoryConfig: options.RepositoryConfig,
OutputDir: options.OutputDir,

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.

For parity with helm template --output-dir: the CLI also writes hook manifests into the directory (cmd/helm/template.go, the if !client.DisableHooks block), which this path does not do yet. That's fine to leave to #416, which adds hook rendering, but whichever lands second should route hooks to files when OutputDir is set.

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.

feat: support --output-dir on helm template

2 participants