Some checks failed
CI / build (push) Failing after 12s
GitOrigin-RevId: 6370f6ea785709295b6abcf9c60717cacf3ac432
2.2 KiB
2.2 KiB
Kubernetes Configuration Templates
This directory contains Jsonnet templates that define reusable application configurations. Many of these templates wrap Helm charts.
Creating a Template for a Helm Chart
To create a template that wraps a Helm chart:
-
Ensure the Chart is Available:
- Add the chart to
third_party/helm/chartfile.yaml. - Run
bazel run //tools:helm_syncto update the lockfile. - Add the generated repository name (e.g.,
helm_jetstack_cert_manager) toMODULE.bazelin thehelm_depsuse_repolist.
- Add the chart to
-
Create the Libsonnet File:
- Import
base.libsonnet. - Define a
Paramsstruct. - Define an
Appfunction that callsparams.context.helm.template. - Path Resolution: The
chartPathpassed tohelm.templatemust be relative to the caller (this libsonnet file) and point to the external repository. In the Bazel sandbox, this usually looks like../../external/+helm_deps+repo_name.
local base = import "k8s/configs/base.libsonnet"; local Params = base.SimpleFieldStruct(["namespace", "name", "context", "values"]); local App(params) = { local chartPath = "../../external/+helm_deps+my_chart_repo", app: params.context.helm.template(params.name, chartPath, { namespace: params.namespace, values: params.values, }) }; { Params: Params, App: App } - Import
-
Update
BUILD.bazel:- Ensure the
jsonnet_librarytarget in this directory includes the new file. - In the environment's
BUILD.bazel(e.g.,k8s/configs/environments/my-app/BUILD.bazel), add the chart's filegroup to thedataattribute ofjsonnet_to_json.
jsonnet_to_json( name = "main", ... data = [ "@helm_deps_my_chart_repo//:chart", ], ) - Ensure the
Import Paths
When importing tanka-util or other external libraries, use the path relative to the repository root. rules_jsonnet configured with deps adds the repository root to the import path.
Example:
local tanka = import "tanka-util/main.libsonnet";
(Assuming tanka-util directory is at the root of the dependency).