local tanka_util = import "github.com/grafana/jsonnet-libs/tanka-util/main.libsonnet"
Package tanka_util provides jsonnet tooling that works well with
Grafana Tanka features. This package implements
Helm and Kustomize
support for Grafana Tanka.
The helm.template function converts a Helm Chart into a
Jsonnet object to be consumed by tools like Tanka. Similarly the
kustomize.build function expands Kustomizations.
Helm Charts are required to be available on the local file system and are
resolved relative to the file that calls helm.template.
Kustomizations are also resolved relative to the file that calls
kustomize.build.
local tanka = import 'github.com/grafana/jsonnet-libs/tanka-util/main.libsonnet';local helm = tanka.helm.new(std.thisFile);local kustomize = tanka.kustomize.new(std.thisFile);{ // render the Grafana Chart, set namespace to "test" grafana: helm.template('grafana', './charts/grafana', { values: { persistence: { enabled: true }, plugins: ['grafana-clock-panel'], }, namespace: 'test', }), // render the Prometheus Kustomize // then entrypoint for `kustomize build` will be ./base/prometheus/kustomization.yaml prometheus: kustomize.build('./base/prometheus'),}
The functionality of helm.template is based on the helm template command.
Because Jsonnet does not support executing arbitrary command for good
reasons,
a different way was required.
To work around this, Tanka instead binds special
functionality into Jsonnet that provides helm template.
This however means this library and all libraries using this library are not
compatible with google/go-jsonnet or google/jsonnet.
Kustomize is build so that each kustomization can pull another kustomization
from the internet. Due to this feature it is not feasible to ensure hermetic and
reprodicible kustomize builds from within Tanka. Beware of that when using the
Kustomize functionality.
withApiServer sets the Kubernetes cluster this environment should apply to.
Must be the full URL, e.g. https://cluster.fqdn:6443
fn environment.withApplyStrategy
withApplyStrategy(applyStrategy)
withApplyStrategy sets the Kubernetes apply strategy used for this environment.
Must be client or server
fn environment.withData
withData(data)
withData adds the actual Kubernetes resources to the inline environment.
fn environment.withDataMixin
withDataMixin(data)
withDataMixin adds the actual Kubernetes resources to the inline environment.
Note: This function appends passed data to existing values
fn environment.withInjectLabels
withInjectLabels(bool)
withInjectLabels adds a “tanka.dev/environment” label to each created resource.
Required for garbage collection.
fn environment.withLabels
withLabels(labels)
withLabels adds arbitrary key:value labels.
fn environment.withLabelsMixin
withLabelsMixin(labels)
withLabelsMixin adds arbitrary key:value labels.
Note: This function appends passed data to existing values
fn environment.withName
withName(name)
withName sets the environment name.
fn environment.withNamespace
withNamespace(namespace)
withNamespace sets the default namespace for objects that don’t explicitely specify one.
fn environment.withResourceDefaults
withResourceDefaults(labels)
withResourceDefaults sets defaults for all resources in this environment.
fn environment.withResourceDefaultsMixin
withResourceDefaultsMixin(labels)
withResourceDefaultsMixin sets defaults for all resources in this environment.
Note: This function appends passed data to existing values
obj helm
helm allows the user to consume Helm Charts as plain Jsonnet resources.
This implements Helm support for Grafana Tanka.
fn helm.new
new(calledFrom)
new initiates the helm object. It must be called before any helm.template call:
// std.thisFile required to correctly resolve local Helm Chartshelm.new(std.thisFile)
fn helm.template
template(name, chart, conf)
template expands the Helm Chart to its underlying resources and returns them in an Object,
so they can be consumed and modified from within Jsonnet.
This functionality requires Helmraiser support in Jsonnet (e.g. using Grafana Tanka) and also
the helm binary installed on your $PATH.
obj k8s
k8s provides common utils to modify Kubernetes objects.
fn k8s.patchKubernetesObjects
patchKubernetesObjects(object, patch)
patchKubernetesObjects applies patch to all Kubernetes objects it finds in object.
fn k8s.patchLabels
patchLabels(object, labels)
patchLabels finds all Kubernetes objects and adds labels to them.
obj kustomize
kustomize allows the user to expand Kustomize manifests into plain Jsonnet resources.
This implements Kustomize support for Grafana Tanka.
fn kustomize.new
new(calledFrom)
new initiates the kustomize object. It must be called before any kustomize.build call:
// std.thisFile required to correctly resolve local Kustomize objectskustomize.new(std.thisFile)
fn kustomize.build
build(path, conf)
build expands the Kustomize object to its underlying resources and returns them in an Object,
so they can be consumed and modified from within Jsonnet.
This functionality requires Kustomize support in Jsonnet (e.g. using Grafana Tanka) and also
the kustomize binary installed on your $PATH.
path is relative to the file calling this function.