-
Notifications
You must be signed in to change notification settings - Fork 165
/
Copy pathhelm.libsonnet
81 lines (74 loc) · 2.23 KB
/
helm.libsonnet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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='`helm-util` provides utilities for using helm in jsonnet',
),
// 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 it's 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={})::
this.patchLabels(
std.native('helmTemplate')(name, chart, conf),
this.defaultLabels
),
'#patchKubernetesObjects':: d.fn(
'`patchKubernetesObjects` finds all Kubernetes objects and patches them`',
[
d.arg('object', d.T.object),
d.arg('patch', d.T.object),
]
),
patchKubernetesObjects(object, patch)::
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')
then object + patch
else
std.mapWithKey(
function(key, obj)
this.patchKubernetesObjects(obj, patch),
object
)
else if std.isArray(object)
then
std.map(
function(obj)
this.patchKubernetesObjects(obj, patch),
object
)
else object,
'#patchLabels':: d.fn(
'`patchLabels` finds all Kubernetes objects and adds labels',
[
d.arg('object', d.T.object),
d.arg('labels', d.T.object),
]
),
patchLabels(object, labels={})::
this.patchKubernetesObjects(
object,
{
metadata+: {
labels+: labels,
},
}
),
}