Background
helm template currently runs client-only in helm-java — template.go:50 passes ClientOnly: true to the internal install call. This means the lookup template function (which queries the live cluster during rendering) doesn't work.
Helm CLI's helm template supports --kube-config / --kube-context / etc. precisely to enable lookup and other cluster-aware rendering paths.
Acceptance criteria
Proposed Java API
helm.template()
.withKubeConfig(kubeConfigPath)
.call();
// chart can now use {{ (lookup "v1" "ConfigMap" "default" "my-cm").data.key }}
Implementation guide
Reference impl: existing TemplateCommand + template.go. The change is small — plumb kubeConfig fields through, and flip ClientOnly based on whether kubeConfig was supplied.
Go (native/internal/helm/template.go)
- Add
KubeConfig string and KubeConfigContents string to TemplateOptions.
- In
Template(...):
clientOnly := options.KubeConfig == "" && options.KubeConfigContents == ""
rel, _, err := install(&InstallOptions{
DryRun: true,
ClientOnly: clientOnly,
KubeConfig: options.KubeConfig,
KubeConfigContents: options.KubeConfigContents,
// … existing fields …
})
CGO bridge (native/main.go)
- Add
char* kubeConfig; and char* kubeConfigContents; to struct TemplateOptions. Field order must match JNA struct.
- Pass through.
JNA + Java
- Add
public String kubeConfig; public String kubeConfigContents; to lib/api/.../TemplateOptions.java. Update @Structure.FieldOrder and constructor.
- Add
withKubeConfig(Path) and withKubeConfigContents(String) to TemplateCommand (copy the methods from InstallCommand).
Tests
- Add a nested
Template class to HelmKubernetesTest (shares the KinD container).
- Scenario: pre-create a
ConfigMap in the test namespace; render a chart that has {{ (lookup "v1" "ConfigMap" "<ns>" "<name>").data.key }}; assert the rendered output contains the lookup'd value.
- Also keep at least one test in the client-only
HelmTemplateTest confirming the no-kubeConfig path still works.
Contributor checklist
References
Background
helm templatecurrently runs client-only in helm-java —template.go:50passesClientOnly: trueto the internal install call. This means thelookuptemplate function (which queries the live cluster during rendering) doesn't work.Helm CLI's
helm templatesupports--kube-config/--kube-context/ etc. precisely to enablelookupand other cluster-aware rendering paths.Acceptance criteria
TemplateCommand.withKubeConfig(Path)andwithKubeConfigContents(String)worklookupcalls against the live clusterHelmKubernetesTest.Template) renders a chart usinglookupand asserts the rendered manifest contains data from a Kubernetes object created in the testProposed Java API
Implementation guide
Reference impl: existing
TemplateCommand+template.go. The change is small — plumb kubeConfig fields through, and flipClientOnlybased on whether kubeConfig was supplied.Go (
native/internal/helm/template.go)KubeConfig stringandKubeConfigContents stringtoTemplateOptions.Template(...):CGO bridge (
native/main.go)char* kubeConfig;andchar* kubeConfigContents;tostruct TemplateOptions. Field order must match JNA struct.JNA + Java
public String kubeConfig; public String kubeConfigContents;tolib/api/.../TemplateOptions.java. Update@Structure.FieldOrderand constructor.withKubeConfig(Path)andwithKubeConfigContents(String)toTemplateCommand(copy the methods fromInstallCommand).Tests
Templateclass toHelmKubernetesTest(shares the KinD container).ConfigMapin the test namespace; render a chart that has{{ (lookup "v1" "ConfigMap" "<ns>" "<name>").data.key }}; assert the rendered output contains the lookup'd value.HelmTemplateTestconfirming the no-kubeConfig path still works.Contributor checklist
@authorJavadoc tagmake build-native && ./mvnw test -pl helm-java -Dtest=HelmTemplateTest,HelmKubernetesTestgreenReferences
lookupfunction: https://helm.sh/docs/chart_template_guide/functions_and_pipelines/#using-the-lookup-functionInstallCommand.java