Skip to main content

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​

ActionRuns
planCheckov, then helm upgrade --install --dry-run
provisionCheckov, helm upgrade --install, then publishes resources
decommissionhelm 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.
danger

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​

KeyTypeDefaultDescription
kubernetes_clusterobjectOverrides the cluster credentials read from the kubernetes_cluster dependency, field by field. See Authentication.
kubernetes_cluster.authentication.cluster.serverstringKubernetes API server URL.
kubernetes_cluster.authentication.cluster.certificate-authority-datastringBase64-encoded cluster CA certificate.
kubernetes_cluster.authentication.user.tokenstringBearer token.
namespacestringdefaultNamespace to install the release into.
release_namestringmd_metadata.name_prefixHelm release name.
chart.repostringURL of the chart repository. Set with chart.name for a remote chart.
chart.namestringName of the chart in the repository.
chart.ocistringOCI URI of the chart. oci:// is added when missing.
chart.versionstringlatestChart version, for a remote or OCI chart.
debugbooleanfalseAdds --debug.
skip_crdsbooleanfalseAdds --skip-crds on plan and provision.
waitbooleantrueAdds --wait: waits for pods, PVCs, services, and other resources to be ready.
wait_for_jobsbooleantrueAdds --wait-for-jobs on plan and provision.
timeoutstringHelm's default, 5m0sAdds --timeout. A Go duration, such as 10m.
checkov.enablebooleantrueRuns Checkov.
checkov.quietbooleantrueShows only failed checks (--quiet).
checkov.halt_on_failurebooleanfalseFails 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:

json
{
"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:

massdriver.yamlyaml
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:

massdriver.yamlyaml
dependencies:
kubernetes_cluster:
resource_type: massdriver-kubernetes-cluster@~0.1
required: true

steps:
- path: chart
provisioner: helm
config:
kubernetes_cluster:
authentication: .dependencies.kubernetes_cluster
note

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.repo and chart.name are set, it adds the repository and uses that chart. Setting only one of them fails the deployment.
  • When chart.oci is set, it pulls the chart from that OCI registry. chart.oci takes priority over chart.repo.

For a remote or OCI chart, a values.yaml in path overrides the chart's defaults, as with helm -f.

Local Chart​

yaml
steps:
- path: chart
provisioner: helm
config:
namespace: .params.namespace

Remote Chart​

yaml
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​

yaml
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:

values.yamlyaml
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:

massdriver.yamlyaml
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:

params.jsonjson
{
"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:

params.jqjq
. += {"commonLabels": .md_metadata.default_tags} | del(.md_metadata)

The values file passed to Helm:

yaml
commonLabels:
managed-by: massdriver
md-instance: proj-env-somebundle
foo:
bar: bizzle
count: 10

connections.jq​

connections.json contains:

connections.jsonjson
{
"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:

connections.jqjq
{
"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:

yaml
postgres:
hostname: the.postgres.database
port: 5432
user: admin
password: s3cr3tV@lue
version: "14.6"

envs.jq​

envs.json contains:

envs.jsonjson
{
"LOG_LEVEL": "debug"
}

The chart expects envs under deployment.envs, as a list of name and value objects:

envs.jqjq
{
deployment: {
envs: [to_entries[] | {name: .key, value: .value}]
}
}

The values file passed to Helm:

yaml
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:

massdriver.yamlyaml
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:

json
{
"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:

resource_api_endpoint.jqjq
(.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"
}
}