yesod-mirror/k8s/configs/templates/README.md

59 lines
2.2 KiB
Markdown
Raw Normal View History

# 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`.
```jsonnet
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`.
```python
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:
```jsonnet
local tanka = import "tanka-util/main.libsonnet";
```
(Assuming `tanka-util` directory is at the root of the dependency).