Helm Provisioner
Runs a step with Helm. Source: provisioner-helm.
Structure​
For a local chart, the step's path is the chart directory, with at least Chart.yaml and values.yaml. For a remote or OCI chart, path holds the files that reshape inputs and render resources, and optionally a values.yaml.
Actions​
| Action | Runs |
|---|---|
plan | Checkov, then helm upgrade --install --dry-run |
provision | Checkov, helm upgrade --install, then publishes resources |
decommission | helm uninstall --ignore-not-found, then deletes the step's resources |
upgrade creates the namespace if it does not exist.
Tooling​
- Checkov scans the chart for policy and compliance violations.
Checkov scans only local charts. It needs a chart directory with a Chart.yaml to render, so remote and OCI charts are not scanned.
Configuration​
| Key | Type | Default | Description |
|---|---|---|---|
kubernetes_cluster | object | Overrides the cluster credentials read from the kubernetes_cluster dependency, field by field. See Authentication. | |
kubernetes_cluster.authentication.cluster.server | string | Kubernetes API server URL. | |
kubernetes_cluster.authentication.cluster.certificate-authority-data | string | Base64-encoded cluster CA certificate. | |
kubernetes_cluster.authentication.user.token | string | Bearer token. | |
namespace | string | default | Namespace to install the release into. |
release_name | string | md_metadata.name_prefix | Helm release name. |
chart.repo | string | URL of the chart repository. Set with chart.name for a remote chart. | |
chart.name | string | Name of the chart in the repository. | |
chart.oci | string | OCI URI of the chart. oci:// is added when missing. | |
chart.version | string | latest | Chart version, for a remote or OCI chart. |
debug | boolean | false | Adds --debug. |
skip_crds | boolean | false | Adds --skip-crds on plan and provision. |
wait | boolean | true | Adds --wait: waits for pods, PVCs, services, and other resources to be ready. |
wait_for_jobs | boolean | true | Adds --wait-for-jobs on plan and provision. |
timeout | string | Helm's default, 5m0s | Adds --timeout. A Go duration, such as 10m. |
checkov.enable | boolean | true | Runs Checkov. |
checkov.quiet | boolean | true | Shows only failed checks (--quiet). |
checkov.halt_on_failure | boolean | false | Fails the deployment on a failed check (drops --soft-fail). |
config strings are jq expressions, so a literal string needs @text, such as '@text "5m"'.
Authentication​
The provisioner authenticates to Kubernetes with a bearer token. It reads the credentials from the authentication block of the kubernetes_cluster dependency:
{
"authentication": {
"cluster": {
"server": "https://my.kubernetes.cluster.com",
"certificate-authority-data": "<base64-encoded CA certificate>"
},
"user": {
"token": "<bearer token>"
}
}
}
server, certificate-authority-data, and token are all required. Client certificates and exec plugins are not supported.
config.kubernetes_cluster is deep-merged over the dependency, so you can override one field or supply the whole credential. To read the server from a dependency with another shape:
steps:
- path: chart
provisioner: helm
config:
kubernetes_cluster:
authentication:
cluster:
server: .dependencies.my_other_cluster.some.custom.path.to.server
The official massdriver-kubernetes-cluster type has cluster and user at the top level, with no authentication block. With a token user, map the whole resource:
dependencies:
kubernetes_cluster:
resource_type: massdriver-kubernetes-cluster@~0.1
required: true
steps:
- path: chart
provisioner: helm
config:
kubernetes_cluster:
authentication: .dependencies.kubernetes_cluster
The provisioner also reads authentication from a nested data block of the dependency, for the legacy kubernetes-cluster type. This is deprecated.
Local, Remote, and OCI Charts​
The provisioner uses a local chart in path by default.
- When both
chart.repoandchart.nameare set, it adds the repository and uses that chart. Setting only one of them fails the deployment. - When
chart.ociis set, it pulls the chart from that OCI registry.chart.ocitakes priority overchart.repo.
For a remote or OCI chart, a values.yaml in path overrides the chart's defaults, as with helm -f.
Local Chart​
steps:
- path: chart
provisioner: helm
config:
namespace: .params.namespace
Remote Chart​
steps:
- path: chart
provisioner: helm
config:
chart:
repo: '@text "https://my.helm.net"'
name: '@text "mychart"'
version: '@text "1.2.3"'
namespace: .params.namespace
OCI Chart​
steps:
- path: chart
provisioner: helm
config:
chart:
oci: '@text "oci://path.to/your/chart"'
version: .params.version
namespace: .params.namespace
Inputs​
The provisioner converts params.json, connections.json, envs.json, and secrets.json to YAML and passes each as a values file. Without a template, envs are nested under a top-level envs key and secrets under secrets. Params and connections are passed as they are.
To reshape an input to fit the chart's values, add a jq file in path: params.jq, connections.jq, envs.jq, or secrets.jq. Each one runs against the matching JSON file, and its output replaces it.
Take a chart with these values:
commonLabels: {}
foo:
bar: "baz"
count: 4
postgres:
hostname: ""
port: 5432
user: "root"
password: ""
version: "12.1"
deployment:
envs: {}
commonLabels should come from md_metadata.default_tags, foo from params, and postgres from a database dependency. The bundle also depends on a Kubernetes cluster for the provisioner's credentials:
app:
envs:
LOG_LEVEL: '@text "debug"'
params:
required:
- foo
properties:
foo:
type: object
required:
- bar
- count
properties:
bar:
type: string
count:
type: integer
dependencies:
kubernetes_cluster:
resource_type: kubernetes-cluster@~1
required: true
database:
resource_type: postgresql-authentication@~1
required: true
params.jq​
params.json contains:
{
"foo": {
"bar": "bizzle",
"count": 10
},
"md_metadata": {
"default_tags": {
"managed-by": "massdriver",
"md-instance": "proj-env-somebundle"
},
"name_prefix": "proj-env-somebundle-0000"
}
}
foo already fits. Set commonLabels to the default tags, and drop md_metadata, which the chart does not use:
. += {"commonLabels": .md_metadata.default_tags} | del(.md_metadata)
The values file passed to Helm:
commonLabels:
managed-by: massdriver
md-instance: proj-env-somebundle
foo:
bar: bizzle
count: 10
connections.jq​
connections.json contains:
{
"kubernetes_cluster": {
"authentication": {
"cluster": {
"certificate-authority-data": "...",
"server": "https://my.kubernetes.cluster.com"
},
"user": {
"token": "..."
}
}
},
"database": {
"authentication": {
"hostname": "the.postgres.database",
"password": "s3cr3tV@lue",
"port": 5432,
"username": "admin"
},
"specs": {
"version": "14.6"
}
}
}
The chart does not use kubernetes_cluster. Drop it, and reshape database into postgres:
{
"postgres": {
"hostname": .database.authentication.hostname,
"port": .database.authentication.port,
"user": .database.authentication.username,
"password": .database.authentication.password,
"version": .database.specs.version
}
}
The values file passed to Helm:
postgres:
hostname: the.postgres.database
port: 5432
user: admin
password: s3cr3tV@lue
version: "14.6"
envs.jq​
envs.json contains:
{
"LOG_LEVEL": "debug"
}
The chart expects envs under deployment.envs, as a list of name and value objects:
{
deployment: {
envs: [to_entries[] | {name: .key, value: .value}]
}
}
The values file passed to Helm:
deployment:
envs:
- name: LOG_LEVEL
value: debug
Resources​
After helm upgrade, the provisioner renders a jq template for each resource. The template is steps[].resources.<name>.template in massdriver.yaml, or a resource_<name>.jq file in path. See Provisioners: Resources.
The template reads params, connections, envs, secrets, and outputs. These are the original JSON inputs, not the output of params.jq and the other input templates. outputs is the release's helm get manifest, as an array with one object per Kubernetes manifest.
Take a bundle that produces an api_endpoint resource:
params:
required:
- namespace
properties:
namespace:
type: string
dependencies:
kubernetes_cluster:
resource_type: kubernetes-cluster@~1
required: true
resources:
api_endpoint:
resource_type: api@~1
required: true
The chart renders a Service and a Deployment, so the template's input is:
{
"params": {
"namespace": "foo"
},
"connections": {
"kubernetes_cluster": {}
},
"envs": {
"LOG_LEVEL": "debug"
},
"secrets": {},
"outputs": [
{
"apiVersion": "v1",
"kind": "Service",
"metadata": { "name": "helm-prov-example-0000" },
"spec": {
"type": "ClusterIP",
"ports": [{ "port": 80, "targetPort": 80, "protocol": "TCP", "name": "http" }]
}
},
{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": { "name": "helm-prov-example-0000" },
"spec": {}
}
]
}
resource_api_endpoint.jq builds the endpoint from the Service's cluster DNS name and port, using select:
(.outputs[] | select(.kind == "Service" and .apiVersion == "v1")) as $svc
| {
"api": {
"hostname": "\($svc.metadata.name).\(.params.namespace).svc.cluster.local",
"port": ($svc.spec.ports[] | select(.name == "http") | .port),
"protocol": "http"
}
}