Helm Functions

Helm functions are provided by the jhelm-gotemplate-helm module. They are auto-discovered via ServiceLoader when the module is on the classpath (priority 200, overrides Sprig on name collision).

1. Template Functions

Function Description

include

Execute named template and return output as string. Returns empty string on error.

mustInclude

Execute named template and return output. Throws on error.

tpl

Evaluate string as template inline. Returns empty string on error.

mustTpl

Evaluate string as template inline. Throws on error.

required

Validate that a value is present and non-empty. Throws with the provided message if validation fails.

Example: include
metadata:
  labels:
    {{- include "mychart.labels" . | nindent 4 }}
Example: required
image: {{ required "image.repository is required" .Values.image.repository }}

2. Conversion Functions

2.1. YAML

Function Description

toYaml

Converts object to YAML string. Null fields are omitted, numeric-looking strings are quoted. Returns empty string on error.

mustToYaml

Same as toYaml but throws on error.

fromYaml

Parses YAML string into a Map. Returns empty map on error.

mustFromYaml

Same as fromYaml but throws on error.

fromYamlArray

Parses YAML string into a List. Returns empty list on error.

mustFromYamlArray

Same as fromYamlArray but throws on error.

2.2. JSON

Function Description

toJson

Converts object to JSON string. Returns "null" for null input.

mustToJson

Same as toJson but throws on error.

toPrettyJson

Converts object to pretty-printed JSON. Returns "null" for null input.

mustToPrettyJson

Same as toPrettyJson but throws on error.

toRawJson

Converts object to JSON without HTML escaping. Returns "null" for null input.

mustToRawJson

Same as toRawJson but throws on error.

fromJson

Parses JSON string into a Map. Returns empty map for null, blank, or "null" input.

mustFromJson

Same as fromJson but throws on error.

fromJsonArray

Parses JSON string into a List. Returns empty list for null, blank, or "null" input.

mustFromJsonArray

Same as fromJsonArray but throws on error.

2.3. must* Variant Pattern

Functions prefixed with must throw a RuntimeException on error instead of returning empty/default values. Use must* variants when strict validation is required (e.g., CI pipelines).

3. Kubernetes Functions

Function Description

lookup

Query Kubernetes API for resources. Syntax: lookup "apiVersion" "kind" "namespace" "name". Returns empty map when no KubernetesProvider is available.

kubeVersion

Returns Kubernetes cluster version info as a Map with keys Major, Minor, GitVersion. Returns stub v1.28.0 when no provider is available.

Kubernetes functions require a KubernetesProvider implementation. When using ServiceLoader auto-discovery (default), stub implementations are used. Wire a real provider via GoTemplate.Builder or Spring auto-configuration in jhelm-kube.