Skip to content

Commit a5ab6fe

Browse files
authored
Merge pull request #3097 from replicatedhq/repl-config-functions-examples
Add HelmChart examples to Config template func page
2 parents efe9a6a + e89cb42 commit a5ab6fe

11 files changed

+193
-53
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Template functions in the config context are available when rendering an application that includes the KOTS [Config](/reference/custom-resource-config) custom resource, which defines the KOTS Admin Console config screen. At execution time, template functions in the config context also can use the static context functions. For more information about configuring the Admin Console config screen, see [About the Configuration Screen](/vendor/config-screen-about).
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
:::note
2+
The KOTS identity service feature is deprecated and is not available to new users.
3+
:::
4+
5+
Template functions in the Identity context have access to Replicated KOTS identity service information.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Template functions in the kURL context have access to information about applications installed with Replicated kURL. For more information about kURL, see [Introduction to kURL](/vendor/kurl-about).
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Template functions in the license context have access to customer license and version data. For more information about managing customer licenses, see [About Customers and Licensing](/vendor/licenses-about).
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The context necessary to render the static template functions is always available.
2+
3+
The static context also includes the Masterminds Sprig function library. For more information, see [Sprig Function Documentation](http://masterminds.github.io/sprig/) on the sprig website.

docs/reference/template-functions-about.mdx

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
import UseCases from "../partials/template-functions/_use-cases.mdx"
2+
import StaticContext from "../partials/template-functions/_static-context.mdx"
3+
import ConfigContext from "../partials/template-functions/_config-context.mdx"
4+
import LicenseContext from "../partials/template-functions/_license-context.mdx"
5+
import KurlContext from "../partials/template-functions/_kurl-context.mdx"
6+
import IdentityContext from "../partials/template-functions/_identity-context.mdx"
7+
import KurlAvailability from "../partials/kurl/_kurl-availability.mdx"
28

39
# About Template Functions
410

@@ -126,33 +132,32 @@ KOTS template functions are grouped into different contexts, depending on the ph
126132

127133
### Static Context
128134

129-
The context necessary to render the static template functions is always available.
135+
<StaticContext/>
130136

131-
The static context also includes the Masterminds Sprig function library. For more information, see [Sprig Function Documentation](http://masterminds.github.io/sprig/) on the sprig website.
132-
133-
For a list of all KOTS template functions available in the static context, see [Static context](template-functions-static-context).
137+
For a list of all KOTS template functions available in the static context, see [Static Context](template-functions-static-context).
134138

135139
### Config Context
136140

137-
Template functions in the config context are available when rendering an application that includes a Config custom resource.
138-
At execution time, template functions in the config context also can use the static context functions.
141+
<ConfigContext/>
139142

140-
For a list of all KOTS template functions available in the config context, see [Config context](template-functions-config-context).
143+
For a list of all KOTS template functions available in the config context, see [Config Context](template-functions-config-context).
141144

142145
### License Context
143146

144-
Template functions in the license context have access to customer license and version data.
147+
<LicenseContext/>
145148

146-
For a list of all KOTS template functions available in the license context, see [License context](template-functions-license-context).
149+
For a list of all KOTS template functions available in the license context, see [License Context](template-functions-license-context).
147150

148151
### kURL Context
149152

150-
Template functions in the kURL context have access to information about applications installed in embedded clusters created by Replicated kURL.
153+
<KurlAvailability/>
154+
155+
<KurlContext/>
151156

152-
For a list of all KOTS template functions available in the kURL context, see [kURL context](template-functions-kurl-context).
157+
For a list of all KOTS template functions available in the kURL context, see [kURL Context](template-functions-kurl-context).
153158

154159
### Identity Context
155160

156-
Template functions in the Identity context have access to Replicated identity service information.
161+
<IdentityContext/>
157162

158-
For a list of all KOTS template functions available in the identity context, see [Identity context](template-functions-identity-context).
163+
For a list of all KOTS template functions available in the identity context, see [Identity Context](template-functions-identity-context).

docs/reference/template-functions-config-context.md

Lines changed: 144 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,82 @@
1+
import ConfigContext from "../partials/template-functions/_config-context.mdx"
2+
13
# Config Context
24

5+
<ConfigContext/>
6+
37
## ConfigOption
48

59
```go
610
func ConfigOption(optionName string) string
711
```
812

9-
Returns the value of the config option as a string.
13+
Returns the value of the specified option from the KOTS Config custom resource as a string.
1014

11-
For information about the config screen and associated options, see [Config](custom-resource-config) in the _Custom Resources_ section.
15+
For the `file` config option type, `ConfigOption` returns the base64 encoded file. To return the decoded contents of a file, use [ConfigOptionData](#configoptiondata) instead.
1216

1317
```yaml
1418
'{{repl ConfigOption "hostname" }}'
1519
```
1620
17-
`ConfigOption` returns the base64 **encoded** value of the `file` config option.
21+
#### Example
1822
19-
```yaml
20-
'{{repl ConfigOption "ssl_key"}}'
21-
```
23+
The following KOTS [HelmChart](/reference/custom-resource-helmchart-v2) custom resource uses the ConfigOption template function to set the port, node port, and annotations for a LoadBalancer service using the values supplied by the user on the KOTS Admin Console config screen. These values are then mapped to the `values.yaml` file for the associated Helm chart during deployment.
2224
23-
To use files in a Secret, use `ConfigOption`:
2425
```yaml
25-
apiVersion: v1
26-
kind: Secret
26+
# KOTS HelmChart custom resource
27+
apiVersion: kots.io/v1beta2
28+
kind: HelmChart
2729
metadata:
28-
name: tls-secret
29-
type: kubernetes.io/tls
30-
data:
31-
tls.crt: '{{repl ConfigOption "tls_certificate_file" }}'
32-
tls.key: '{{repl ConfigOption "tls_private_key_file" }}'
30+
name: samplechart
31+
spec:
32+
chart:
33+
name: samplechart
34+
chartVersion: 3.1.7
35+
values:
36+
myapp:
37+
service:
38+
type: LoadBalancer
39+
port: repl{{ ConfigOption "myapp_load_balancer_port"}}
40+
nodePort: repl{{ ConfigOption "myapp_load_balancer_node_port"}}
41+
annotations: repl{{ ConfigOption `myapp_load_balancer_annotations` | nindent 14 }}
3342
```
34-
35-
For more information about using TLS certificates, see [Using TLS Certificates](../vendor/packaging-using-tls-certs).
43+
For more information, see [Setting Helm Values with KOTS](/vendor/helm-optional-value-keys).
3644
3745
## ConfigOptionData
3846
3947
```go
4048
func ConfigOptionData(optionName string) string
4149
```
4250
43-
`ConfigOptionData` returns the base64 **decoded** value of a `file` config option.
51+
For the `file` config option type, `ConfigOptionData` returns the base64 decoded contents of the file. To return the base64 encoded file, use [ConfigOption](#configoption) instead.
4452
4553
```yaml
4654
'{{repl ConfigOptionData "ssl_key"}}'
4755
```
4856
49-
To use files in a ConfigMap, use `ConfigOptionData`:
57+
#### Example
58+
59+
The following KOTS [HelmChart](/reference/custom-resource-helmchart-v2) custom resource uses the ConfigOptionData template function to set the TLS cert and key using the files supplied by the user on the KOTS Admin Console config screen. These values are then mapped to the `values.yaml` file for the associated Helm chart during deployment.
60+
5061
```yaml
51-
apiVersion: v1
52-
kind: ConfigMap
62+
# KOTS HelmChart custom resource
63+
apiVersion: kots.io/v1beta2
64+
kind: HelmChart
5365
metadata:
54-
name: tls-config
55-
data:
56-
tls.crt: |
57-
repl{{- ConfigOptionData "tls_certificate_file" | nindent 4 }}
58-
59-
tls.key: |
60-
repl{{- ConfigOptionData "tls_private_key_file" | nindent 4 }}
66+
name: samplechart
67+
spec:
68+
chart:
69+
name: samplechart
70+
chartVersion: 3.1.7
71+
values:
72+
myapp:
73+
tls:
74+
enabled: true
75+
genSelfSignedCert: repl{{ ConfigOptionEquals "myapp_ingress_tls_type" "self_signed" }}
76+
cert: repl{{ print `|`}}repl{{ ConfigOptionData `tls_certificate_file` | nindent 12 }}
77+
key: repl{{ print `|`}}repl{{ ConfigOptionData `tls_private_key_file` | nindent 12 }}
6178
```
79+
For more information, see [Setting Helm Values with KOTS](/vendor/helm-optional-value-keys).
6280
6381
## ConfigOptionFilename
6482
@@ -73,7 +91,9 @@ It will return an empty string if used erroneously with other types.
7391
'{{repl ConfigOptionFilename "pom_file"}}'
7492
```
7593
76-
As an example, if you have the following Config Spec defined:
94+
#### Example
95+
96+
For example, if you have the following KOTS Config defined:
7797
7898
```yaml
7999
apiVersion: kots.io/v1beta1
@@ -91,7 +111,8 @@ spec:
91111
required: true
92112
```
93113
94-
You can use `ConfigOptionFilename` in a Pod Spec to mount a file like so:
114+
The following example shows how to use `ConfigOptionFilename` in a Pod Spec to mount a file:
115+
95116
```yaml
96117
apiVersion: v1
97118
kind: Pod
@@ -137,6 +158,26 @@ Returns true if the configuration option value is equal to the supplied value.
137158
'{{repl ConfigOptionEquals "http_enabled" "1" }}'
138159
```
139160
161+
#### Example
162+
163+
The following KOTS [HelmChart](/reference/custom-resource-helmchart-v2) custom resource uses the ConfigOptionEquals template function to set the `postgres.enabled` value depending on if the user selected the `embedded_postgres` option on the KOTS Admin Console config screen. This value is then mapped to the `values.yaml` file for the associated Helm chart during deployment.
164+
165+
```yaml
166+
# KOTS HelmChart custom resource
167+
apiVersion: kots.io/v1beta2
168+
kind: HelmChart
169+
metadata:
170+
name: samplechart
171+
spec:
172+
chart:
173+
name: samplechart
174+
chartVersion: 3.1.7
175+
values:
176+
postgresql:
177+
enabled: repl{{ ConfigOptionEquals `postgres_type` `embedded_postgres`}}
178+
```
179+
For more information, see [Setting Helm Values with KOTS](/vendor/helm-optional-value-keys).
180+
140181
## ConfigOptionNotEquals
141182
142183
```go
@@ -168,6 +209,29 @@ Returns the host of the local registry that the user configured. Alternatively,
168209

169210
Includes the port if one is specified.
170211

212+
#### Example
213+
214+
The following KOTS [HelmChart](/reference/custom-resource-helmchart-v2) custom resource uses the HasLocalRegistry, LocalRegistryHost, and LocalRegistryNamespace template functions to conditionally rewrite an image registry and repository depending on if a local registry is used. These values are then mapped to the `values.yaml` file for the associated Helm chart during deployment.
215+
216+
```yaml
217+
# KOTS HelmChart custom resource
218+
apiVersion: kots.io/v1beta2
219+
kind: HelmChart
220+
metadata:
221+
name: samplechart
222+
spec:
223+
chart:
224+
name: samplechart
225+
chartVersion: 3.1.7
226+
values:
227+
myapp:
228+
image:
229+
registry: '{{repl HasLocalRegistry | ternary LocalRegistryHost "images.mycompany.com" }}'
230+
repository: '{{repl HasLocalRegistry | ternary LocalRegistryNamespace "proxy/myapp/quay.io/my-org" }}/nginx'
231+
tag: v1.0.1
232+
```
233+
For more information, see [Setting Helm Values with KOTS](/vendor/helm-optional-value-keys).
234+
171235
## LocalRegistryNamespace
172236

173237
```go
@@ -176,6 +240,29 @@ func LocalRegistryNamespace() string
176240

177241
Returns the namespace of the local registry that the user configured. Alternatively, for air gap installations with Embedded Cluster or kURL, LocalRegistryNamespace returns the namespace of the built-in registry.
178242

243+
#### Example
244+
245+
The following KOTS [HelmChart](/reference/custom-resource-helmchart-v2) custom resource uses the HasLocalRegistry, LocalRegistryHost, and LocalRegistryNamespace template functions to conditionally rewrite an image registry and repository depending on if a local registry is used. These values are then mapped to the `values.yaml` file for the associated Helm chart during deployment.
246+
247+
```yaml
248+
# KOTS HelmChart custom resource
249+
apiVersion: kots.io/v1beta2
250+
kind: HelmChart
251+
metadata:
252+
name: samplechart
253+
spec:
254+
chart:
255+
name: samplechart
256+
chartVersion: 3.1.7
257+
values:
258+
myapp:
259+
image:
260+
registry: '{{repl HasLocalRegistry | ternary LocalRegistryHost "images.mycompany.com" }}'
261+
repository: '{{repl HasLocalRegistry | ternary LocalRegistryNamespace "proxy/myapp/quay.io/my-org" }}/nginx'
262+
tag: v1.0.1
263+
```
264+
For more information, see [Setting Helm Values with KOTS](/vendor/helm-optional-value-keys).
265+
179266
## LocalImageName
180267

181268
```go
@@ -206,6 +293,8 @@ Returns the base64 encoded local registry image pull secret value.
206293
This is often needed when an operator is deploying images to a namespace that is not managed by Replicated KOTS.
207294
Image pull secrets must be present in the namespace of the pod.
208295
296+
#### Example
297+
209298
```yaml
210299
apiVersion: v1
211300
kind: Secret
@@ -239,6 +328,8 @@ Returns the name of the image pull secret that can be added to pod specs that us
239328
The secret will be automatically created in all application namespaces.
240329
It will contain authentication information for any private registry used with the application.
241330
331+
#### Example
332+
242333
```yaml
243334
apiVersion: apps/v1
244335
kind: Deployment
@@ -258,4 +349,27 @@ func HasLocalRegistry() bool
258349
```
259350
260351
Returns true if the environment is configured to rewrite images to a local registry.
261-
HasLocalRegistry is always true for air gap installations. HasLocalRegistry is true in online installations if the user pushed images to a local registry.
352+
HasLocalRegistry is always true for air gap installations. HasLocalRegistry is true in online installations if the user pushed images to a local registry.
353+
354+
#### Example
355+
356+
The following KOTS [HelmChart](/reference/custom-resource-helmchart-v2) custom resource uses the HasLocalRegistry, LocalRegistryHost, and LocalRegistryNamespace template functions to conditionally rewrite an image registry and repository depending on if a local registry is used. These values are then mapped to the `values.yaml` file for the associated Helm chart during deployment.
357+
358+
```yaml
359+
# KOTS HelmChart custom resource
360+
apiVersion: kots.io/v1beta2
361+
kind: HelmChart
362+
metadata:
363+
name: samplechart
364+
spec:
365+
chart:
366+
name: samplechart
367+
chartVersion: 3.1.7
368+
values:
369+
myapp:
370+
image:
371+
registry: '{{repl HasLocalRegistry | ternary LocalRegistryHost "images.mycompany.com" }}'
372+
repository: '{{repl HasLocalRegistry | ternary LocalRegistryNamespace "proxy/myapp/quay.io/my-org" }}/nginx'
373+
tag: v1.0.1
374+
```
375+
For more information, see [Setting Helm Values with KOTS](/vendor/helm-optional-value-keys).

docs/reference/template-functions-identity-context.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
import IdentityContext from "../partials/template-functions/_identity-context.mdx"
2+
13
# Identity Context
24

5+
<IdentityContext/>
6+
37
## IdentityServiceEnabled
48

59
```go

docs/reference/template-functions-kurl-context.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1+
import KurlContext from "../partials/template-functions/_kurl-context.mdx"
2+
import KurlAvailability from "../partials/kurl/_kurl-availability.mdx"
3+
14
# kURL Context
25

3-
## kURL Context Functions
6+
<KurlAvailability/>
7+
8+
## Overview
49

5-
For applications installed in embedded clusters created with Replicated kURL, you can use template functions to show all options the cluster was installed with.
10+
<KurlContext/>
611

7-
The creation of the Installer custom resource will reflect both install script changes made by posting YAML to the kURL API and changes made with -s flags at runtime. These functions are not available on the config page.
12+
The creation of the kURL Installer custom resource will reflect both install script changes made by posting YAML to the kURL API and changes made with -s flags at runtime. These functions are not available on the KOTS Admin Console config page.
813

914
KurlBool, KurlInt, KurlString, and KurlOption all take a string yamlPath as a param.
10-
This path is the path from the manifest file, and is delineated between addon and subfield by a period ’.’.
15+
This is the path from the manifest file, and is delineated between add-on and subfield by a period ’.’.
1116
For example, the kURL Kubernetes version can be accessed as `{{repl KurlString "Kubernetes.Version" }}`.
1217

1318
KurlBool, KurlInt, KurlString respectively return a bool, integer, and string value.
1419
If used on a valid field but with the wrong type these will return the falsy value for their type, false, 0, and “string respectively.
1520
The `KurlOption` function will convert all bool, int, and string fields to string.
1621
All functions will return falsy values if there is nothing at the yamlPath specified, or if these functions are run in a cluster with no installer custom resource (as in, not a cluster created by kURL).
1722

18-
The following provides a complete list of the Installer custom resource with annotations:
19-
2023
## KurlBool
2124

2225
```go

docs/reference/template-functions-license-context.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
import LicenseContext from "../partials/template-functions/_license-context.mdx"
2+
13
# License Context
24

5+
<LicenseContext/>
6+
37
## LicenseFieldValue
48
```go
59
func LicenseFieldValue(name string) string

0 commit comments

Comments
 (0)