yesod-mirror/k8s/configs/templates/README.md
Copybara 8157b39ea4
Some checks failed
CI / build (push) Failing after 12s
Project import generated by Copybara.
GitOrigin-RevId: 6370f6ea785709295b6abcf9c60717cacf3ac432
2026-01-20 21:26:21 +00:00

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:

  1. Ensure the Chart is Available:

    • Add the chart to third_party/helm/chartfile.yaml.
    • Run bazel run //tools:helm_sync to update the lockfile.
    • Add the generated repository name (e.g., helm_jetstack_cert_manager) to MODULE.bazel in the helm_deps use_repo list.
  2. Create the Libsonnet File:

    • Import base.libsonnet.
    • Define a Params struct.
    • Define an App function that calls params.context.helm.template.
    • Path Resolution: The chartPath passed to helm.template must 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 }
    
  3. Update BUILD.bazel:

    • Ensure the jsonnet_library target 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 the data attribute of jsonnet_to_json.
    jsonnet_to_json(
        name = "main",
        ...
        data = [
            "@helm_deps_my_chart_repo//:chart",
        ],
    )
    

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).