|
Some checks failed
CI / build (push) Failing after 12s
GitOrigin-RevId: 6370f6ea785709295b6abcf9c60717cacf3ac432 |
||
|---|---|---|
| .. | ||
| helm_support | ||
| BUILD.bazel | ||
| main.go | ||
| README.md | ||
Custom Jsonnet Compiler
This directory contains a custom Jsonnet compiler built with Go. It wraps the standard go-jsonnet library and adds a native function helmTemplate to support rendering Helm charts directly within Jsonnet.
helmTemplate Native Function
The helmTemplate function allows you to render a Helm chart located on the filesystem.
Signature
native("helmTemplate")(name, chartPath, opts)
name: The release name.chartPath: The path to the Helm chart directory (containingChart.yaml). Crucial: This path must be relative to the directory containing the file that callshelmTemplate. When using Bazel external repositories, this often means navigating up to the execution root (e.g.,../../external/repo_name).opts: A configuration object.calledFrom: (Required) The path of the file calling the function. Usuallystd.thisFile. The compiler uses this to resolve relative paths.nameFormat: (Optional) Format string for resource names.values: (Optional) Values to pass to the Helm chart.includeCRDs: (Optional) Boolean, defaulttrue.namespace: (Optional) Namespace for the release.
Usage Example
local helm = std.native("helmTemplate");
helm("my-release", "../../external/my_chart_repo", {
calledFrom: std.thisFile,
namespace: "default",
values: {
replicaCount: 2,
},
})
Bazel Integration
This compiler is registered as a custom toolchain in //tools/jsonnet_compiler:helm_jsonnet_toolchain and used by rules_jsonnet.
Imports and JPaths
When using rules_jsonnet, the imports attribute adds directories to the Jsonnet search path (-J).
imports = ["."]adds the package directory.depsonjsonnet_librarytargets adds their roots to the search path.
When importing files from external repositories (like tanka-util), ensure the import path matches the structure within that repository. For example, if tanka-util library is at the root of the @github_com_grafana_jsonnet_libs_tanka_util repo, you can import it as import "tanka-util/main.libsonnet" provided the repo root is in the search path (which deps handles).