Repository navigation
feat: support output directories for helm template - #433
Ishubhammohole wants to merge 1 commit into
Conversation
Signed-off-by: Shubham Mohole <95623059+Ishubhammohole@users.noreply.github.com>
manusa
left a comment
There was a problem hiding this comment.
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)writesdir/<chart>/templates/*.yaml, anduseReleaseName()nests them underdir/<release-name>/. Both matchhelm 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 withwithOutputDir(...), 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) { |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
Summary
withOutputDir(Path)anduseReleaseName()to the template command APITesting
go test ./internal/helm -run '^TestTemplateFromLocal$' -count=1— passedmake test-go— passedgo vet ./...— passedmake build-native— passedmvn 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%20make check-authors— existing repository-wide check reports 8 unrelated files; all modified Java files include the contributor author tagAI-assisted development was used following the repository's
AGENTS.mdworkflow; the implementation, generated native interface alignment, diff, and reported results were reviewed before submission.Fixes #329