-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathcheatsheet.html
231 lines (197 loc) · 7.2 KB
/
cheatsheet.html
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Helm template syntax cheat sheet</title>
<meta
name="description"
content="Copy-paste snippets of common Helm template syntax."
/>
<link rel="stylesheet" href="codemirror/codemirror.css" />
<link rel="stylesheet" href="codemirror/material.css" />
<link rel="stylesheet" href="style.css" />
<link rel="icon" type="image/png" href="favicon.png" />
</head>
<body>
<div class="app">
<div class="top">
<a class="logo" href="/">Helm-playground.com</a>
<a class="top__link" href="/cheatsheet.html">Syntax cheatsheet</a>
<a
style="margin-left: auto"
class="top__link hide-on-mobile"
href="https://shipmight.com"
>Brought to you by Shipmight - Kubernetes-powered PaaS in your
cloud</a
>
</div>
<div class="content content--page">
<h2><a href="#variables" id="variables">Variables</a></h2>
<p>
<a href="https://helm.sh/docs/chart_template_guide/function_list/"
>See Helm documentation for full list of available functions</a
>
</p>
<pre><code>name: {{ .Values.storageClassName }}
name: {{ .Values.storageClassName | quote }}
name: {{ .Values.storageClassName | default "default value" }}
name: {{ .Values.storageClassName | required ".storageClassName must be set" }}
name: {{ .Values.storageClassName | trim }}
name: {{ printf "%s-%d" .Values.storageClassName .Values.storageClassVersion }}
name: {{ .Values.storageClassName | replace "{placeholder}" "example" }}
{{ $fullName := printf "%s %s" .Values.firstName .Values.lastName }}
name: {{ .Values.storageClassName | trimAll "/" }}
name: {{ .Values.storageClassName | trimPrefix "/" }}
name: {{ .Values.storageClassName | trimSuffix "/" }}
name: {{ .Values.storageClassName | lower }}
name: {{ .Values.storageClassName | upper }}</code></pre>
<h2><a href="#built-ins" id="built-ins">Built-ins</a></h2>
<p>
<a href="https://helm.sh/docs/chart_template_guide/builtin_objects/"
>See Helm documentation for all options</a
>
</p>
<pre><code>{{ .Release.Name }}
{{ .Release.Namespace }}
{{ .Chart.Name }}
{{ .Chart.Version }}
{{ .Files.Get config.ini }}</code></pre>
<h2><a href="#conditionals" id="conditionals">Conditionals</a></h2>
<pre><code>{{ if .Values.enablePersistence }}
# ...
{{ else if .Values.enableFilesystem }}
# ...
{{ else }}
# ...
{{ end }}
# equal, not equal
{{ if eq .Values.environment "production" }}
{{ if ne .Values.environment "production" }}
# and, or
{{ if and (eq .Values.environment "production") (eq .Values.host "minikube") }}
{{ if or (eq .Values.environment "production") (eq .Values.host "minikube") }}
# not (negation)
{{ if not (eq .Values.environment "production") }}
# greater than, less than
{{ if gt (len .Values.items) 3 }}
{{ if gte (len .Values.items) 3 }}
{{ if lt (len .Values.items) 3 }}
{{ if lte (len .Values.items) 3 }}
# strings
{{ if .Values.name | contains "example" }}
{{ if .Values.name | hasPrefix "foobar-" }}
{{ if .Values.name | hasSuffix "-foobar" }}
{{ if .Values.name | regexMatch "^[a-z]+$" }}
# lists
{{ if .Values.items | has "example" }}
# ternary
{{ ternary "returned if true" "returned if false" .Values.someBoolean }}</code></pre>
<h2><a href="#loops" id="loops">Loops</a></h2>
<pre><code># simple
volumes:
{{ range .Values.volumeIds }}
- volumeName: {{ . }}
{{ end }}
# with named variable
volumes:
{{ range $volumeId := .Values.volumeIds }}
- volumeName: {{ $volumeId }}
{{ end }}
# with index (array) or key (dict)
volumes:
{{ range $key, $value := .Values.configuration }}
- {{ $key }}: {{ $value }}
{{ end }}</code></pre>
<h2><a href="#indentation" id="indentation">Indentation</a></h2>
<pre><code>env:
{{ .Values.environmentVariables | toYaml | indent 2 }}
env: {{ .Values.environmentVariables | toYaml | nindent 2 }}</code></pre>
<h2><a href="#includes" id="includes">Includes</a></h2>
<pre><code># define templates in _helpers.tpl
{{- define "your-project.image" -}}
{{ printf "%s:%s" .Values.image.name .Values.image.tag | quote }}
{{- end -}}
# use in other files
image: {{ include "your-project.image" . }}
# more specific parameters as the scope
{{- define "your-project.someInclude" -}}
{{ . | replace "{placeholder}" "example" }}
{{- end -}}
# usage
foobar: {{ include "your-project.someInclude" .Values.foobar }}</code></pre>
<h2><a href="#lookup" id="lookup">Lookup</a></h2>
<pre><code>{{ $previous := lookup "v1" "Secret" .Release.Namespace "some-secret" }}
data:
{{- if $previous }}
foobarPassword: {{ $previous.data.foobarPassword | quote }}
{{- else if .Values.foobarPassword }}
foobarPassword: {{ .Values.foobarPassword | b64enc | quote }}
{{- else }}
foobarPassword: {{ randAlphaNum 40 | b64enc | quote }}
{{- end }}</code></pre>
<h2><a href="#fail" id="fail">Fail</a></h2>
<pre><code>{{ if eq .Values.storageClassName "foobar1" }}
# ...
{{ else if eq .Values.storageClassName "foobar2" }}
# ...
{{ else }}
{{ fail ".storageClassName is not recognized" }}
{{ end }}</code></pre>
<h2><a href="#dates" id="dates">Dates</a></h2>
<p>
<a
href="https://helm.sh/docs/chart_template_guide/function_list/#date"
>See Helm documentation for notes about formatting</a
>
</p>
<pre><code># ISO 8601, format string is provided as a lookalike-string
{{ now | date "2006-01-02T15:04:05" }}</code></pre>
<h2><a href="#base64" id="base64">Base64</a></h2>
<pre><code>{{ .Values.someData | b64enc }}
{{ .Values.someData | b64dec }}</code></pre>
<h2><a href="#uuids" id="uuids">UUIDs</a></h2>
<pre><code>id: {{ uuidv4 }}</code></pre>
<h2><a href="#crypto" id="crypto">Crypto</a></h2>
<pre><code>{{ .Values.someData | sha256sum }}
{{ .Values.someData | encryptAES "secret key" }}
{{ .Values.someData | decryptAES "secret key" }}</code></pre>
<hr />
<p>
Source code for this page can be found on
<a href="https://github.com/shipmight/helm-playground">GitHub</a>.
</p>
<p class="ad">
FYI! This site uses Fathom Analytics which does not use cookies. Use
<a href="https://usefathom.com/ref/4HFQGS" target="_blank"
>this link</a
>
for a $10 discount.
</p>
</div>
</div>
<script src="codemirror/codemirror.js"></script>
<script src="codemirror/yaml.js"></script>
<script>
const preElements = Array.from(document.querySelectorAll("pre"));
for (const preElement of preElements) {
new CodeMirror(
(codemirror) => {
preElement.replaceWith(codemirror);
},
{
mode: "yaml",
theme: "material",
readOnly: true,
value: preElement.textContent,
}
);
}
</script>
<script
src="https://cdn.usefathom.com/script.js"
data-site="ZNCHLJMX"
defer
></script>
</body>
</html>