forked from grafana/jsonnet-libs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: helm-util into tanka-util (grafana#396)
- Loading branch information
Showing
16 changed files
with
434 additions
and
255 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1 @@ | ||
--- | ||
permalink: / | ||
--- | ||
|
||
# package helm-util | ||
|
||
```jsonnet | ||
local helm-util = import "github.com/grafana/jsonnet-libs/helm-util/helm.libsonnet" | ||
``` | ||
|
||
Package `helm-util` allows the user to consume Helm Charts as plain Jsonnet | ||
resources. This package implements [Helm support](https://tanka.dev/helm) for | ||
Grafana Tanka. | ||
|
||
### Usage | ||
|
||
> **Warning:** [Functionality required](#internals) by this library is still experimental and may break. | ||
The [`helm.template`](#fn-helmtemplate) function to converts a Helm Chart into Jsonnet objects, | ||
to be consumed by tools like [Grafana Tanka](https://tanka.dev). | ||
|
||
Helm Charts are required to be available on the local file system and are | ||
resolved relative to the file that calls `helm.template`: | ||
|
||
```jsonnet | ||
local helm = (import 'github.com/grafana/jsonnet-libs/helm-util/helm.libsonnet').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', | ||
}), | ||
} | ||
``` | ||
|
||
For more information on that see https://tanka.dev/helm | ||
|
||
### Internals | ||
|
||
The functionality of `helm-util` is based on the `helm template` command. | ||
Because Jsonnet does not support executing arbitrary command for [good | ||
reasons](https://jsonnet.org/ref/language.html#independence-from-the-environment-hermeticity), | ||
a different way was required. | ||
|
||
To work around this, [Tanka](https://tanka.dev) 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`. | ||
|
||
|
||
## Index | ||
|
||
* [`fn new(calledFrom)`](#fn-new) | ||
* [`fn patchKubernetesObjects(object, patch)`](#fn-patchkubernetesobjects) | ||
* [`fn patchLabels(object, labels)`](#fn-patchlabels) | ||
* [`fn template(name, chart, conf)`](#fn-template) | ||
|
||
## Fields | ||
|
||
### fn new | ||
|
||
```ts | ||
new(calledFrom) | ||
``` | ||
|
||
`new` initiates the `helm-util` library. It must be called before any `helm.template` call: | ||
> ```jsonnet | ||
> // std.thisFile required to correctly resolve local Helm Charts | ||
> helm.new(std.thisFile) | ||
> ``` | ||
### fn patchKubernetesObjects | ||
```ts | ||
patchKubernetesObjects(object, patch) | ||
``` | ||
`patchKubernetesObjects` applies `patch` to all Kubernetes objects it finds in `object`. | ||
|
||
### fn patchLabels | ||
|
||
```ts | ||
patchLabels(object, labels) | ||
``` | ||
|
||
`patchLabels` finds all Kubernetes objects and adds labels to them. | ||
|
||
### fn template | ||
|
||
```ts | ||
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`. | ||
**Deprecated**: Please use [`tanka-util`](../tanka-util) instead. |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,5 @@ | ||
local d = import 'github.com/sh0rez/docsonnet/doc-util/main.libsonnet'; | ||
{ | ||
local this = self, | ||
|
||
'#':: d.pkg( | ||
name='helm-util', | ||
url='github.com/grafana/jsonnet-libs/helm-util/helm.libsonnet', | ||
help=(importstr 'README.md.tmpl') % (importstr '_example.jsonnet'), | ||
), | ||
|
||
'#_config':: 'ignore', | ||
_config: { | ||
calledFrom:: error 'new(std.thisFile) was not called', | ||
}, | ||
|
||
|
||
'#new': d.fn( | ||
||| | ||
`new` initiates the `helm-util` library. It must be called before any `helm.template` call: | ||
> ```jsonnet | ||
> // std.thisFile required to correctly resolve local Helm Charts | ||
> helm.new(std.thisFile) | ||
> ``` | ||
|||, | ||
[d.arg('calledFrom', d.T.string)] | ||
), | ||
new(calledFrom):: self { | ||
_config+: { calledFrom: calledFrom }, | ||
}, | ||
|
||
// This common label is usually set to 'Helm', this is not true anymore. | ||
// You can override this with any value you choose. | ||
// https://helm.sh/docs/chart_best_practices/labels/#standard-labels | ||
defaultLabels:: { 'app.kubernetes.io/managed-by': 'Helmraiser' }, | ||
|
||
'#template':: d.fn( | ||
||| | ||
`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`. | ||
|||, | ||
[ | ||
d.arg('name', d.T.string), | ||
d.arg('chart', d.T.string), | ||
d.arg('conf', d.T.object), | ||
] | ||
), | ||
template(name, chart, conf={}):: | ||
local cfg = conf { calledFrom: this._config.calledFrom }; | ||
local chartData = std.native('helmTemplate')(name, chart, cfg); | ||
|
||
this.patchLabels(chartData, this.defaultLabels), | ||
|
||
'#patchKubernetesObjects':: d.fn( | ||
'`patchKubernetesObjects` applies `patch` to all Kubernetes objects it finds in `object`.', | ||
[ | ||
d.arg('object', d.T.object), | ||
d.arg('patch', d.T.object), | ||
] | ||
), | ||
patchKubernetesObjects(object, patch, kind=null, name=null):: | ||
if std.isObject(object) | ||
then | ||
// a Kubernetes object is characterized by having an apiVersion and Kind | ||
if std.objectHas(object, 'apiVersion') && std.objectHas(object, 'kind') | ||
&& (kind == null || object.kind == kind) && (name == null || object.metadata.name == name) | ||
then object + patch | ||
else | ||
std.mapWithKey( | ||
function(key, obj) | ||
this.patchKubernetesObjects(obj, patch, kind, name), | ||
object | ||
) | ||
else if std.isArray(object) | ||
then | ||
std.map( | ||
function(obj) | ||
this.patchKubernetesObjects(obj, patch, kind, name), | ||
object | ||
) | ||
else object, | ||
|
||
'#patchLabels':: d.fn( | ||
'`patchLabels` finds all Kubernetes objects and adds labels to them.', | ||
[ | ||
d.arg('object', d.T.object), | ||
d.arg('labels', d.T.object), | ||
] | ||
), | ||
patchLabels(object, labels={}):: | ||
this.patchKubernetesObjects( | ||
object, | ||
{ | ||
metadata+: { | ||
labels+: labels, | ||
}, | ||
} | ||
), | ||
} | ||
std.trace( | ||
'Deprecated, please use `github.com/grafana/jsonnet-libs/tanka-util/` instead. (2020-12-11)', | ||
(import 'github.com/grafana/jsonnet-libs/tanka-util/helm.libsonnet') | ||
+ (import 'github.com/grafana/jsonnet-libs/tanka-util/k8s.libsonnet') | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"version": 1, | ||
"dependencies": [ | ||
{ | ||
"source": { | ||
"git": { | ||
"remote": "https://github.com/grafana/jsonnet-libs.git", | ||
"subdir": "tanka-util" | ||
} | ||
}, | ||
"version": "master" | ||
} | ||
], | ||
"legacyImports": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.PHONY: docs | ||
docs: | ||
docsonnet -o . main.libsonnet |
Oops, something went wrong.