Config
The Config custom resource can be provided by a vendor to specify a Config page in the Replicated Admin Console for collecting customer supplied values and template function rendering.
The settings that appear on the Admin Console Config page are specified as an array configuration groups and items.
The following example shows three groups defined in the Config custom resource manifest file, and how these groups are displayed on the Admin Console Config page.
For more information about the properties of groups and items, see Group Properties and Item Properties below.
apiVersion: kots.io/v1beta1
kind: Config
metadata:
name: my-application
spec:
groups:
- name: example_group
title: First Group
items:
- name: http_enabled
title: HTTP Enabled
type: bool
default: "0"
- name: example_group_2
title: Second Group
when: false
items:
- name: key
title: Key
type: textarea
- name: hostname
title: Hostname
type: text
- name: example_group_3
title: Third Group
items:
- name: email-address
title: Email Address
type: text
- name: password_text
title: Password
type: password
value: '{{repl RandomString 10}}'
View a larger version of this image
Group Properties
Groups have a name
, title
, description
and an array of items
.
description
Descriptive help text for the group that displays on the Admin Console Config page. Supports markdown formatting.
To provide help text for individual items on the Config page, use the item help-text
property. See help_text below.
spec:
groups:
- name: example_group
title: First Group
# Provide a description of the input fields in the group
description: Select whether or not to enable HTTP.
items:
- name: http_enabled
title: HTTP Enabled
type: bool
default: "0"
name
A unique identifier for the group.
spec:
groups:
# The name must be unique
- name: example_group
title: First Group
items:
- name: http_enabled
title: HTTP Enabled
type: bool
default: "0"
title
The title of the group that displays on the Admin Console Config page.
spec:
groups:
- name: example_group
# First Group is the heading that appears on the Config page
title: First Group
items:
- name: http_enabled
title: HTTP Enabled
type: bool
default: "0"
when
The when
property denotes groups that are displayed on the Admin Console Config page only when a condition evaluates to true. When the condition evaluates to false, the group is not displayed.
It can be useful to conditionally show or hide fields so that your users are only provided the configuration options that are relevant to them. This helps to reduce user error when configuring the application. Conditional statements in the when
property can be used to evaluate things like the user's environment, license entitlements, and configuration choices. For example:
- The Kubernetes distribution of the cluster
- If the license includes a specific feature entitlement
- The number of users that the license permits
- If the user chooses to bring their own external database, rather than using an embedded database offered with the application
You can construct conditional statements in the when
property using KOTS template functions. KOTS template functions are a set of custom template functions based on the Go text/template library. For more information, see About Template Functions.
when
is a property of both groups and items. See Item Properties > when
below.
Requirements and Limitations
The when
group property has the following requirements and limitations:
- The
when
property accepts the following types of values:- Booleans
- Strings that match "true", "True", "false", or "False"
- For the
when
property to evaluate to true, the values compared in the conditional statement must match exactly without quotes
Example
In the following example, the example_group_2
group of items will be displayed on the Config page only when the user enables the http_enabled
configuration field. This example uses the KOTS ConfigOptionEquals template function to evaluate the value of the http_enabled
configuration field.
spec:
groups:
- name: example_group
title: First Group
items:
- name: http_enabled
title: HTTP Enabled
type: bool
default: "0"
- name: example_group_2
title: Second Group
# This group is displayed only when the `http_enabled` field is selected
when: repl{{ ConfigOptionEquals "http_enabled" "1" }}
items:
- name: key
title: Key
type: textarea
- name: hostname
title: Hostname
type: text
- name: example_group_3
title: Third Group
items:
- name: email-address
title: Email Address
type: text
- name: password_text
title: Password
type: password
value: '{{repl RandomString 10}}'
View a larger version of this image
For additional examples, see Using Conditional Statements in Configuration Fields.
items
Each group contains an array of items that map to input fields on the Admin Console Config screen. All items have name
, title
, and type
properties and belong to a single group.
For more information, see Item Properties and Item Types below.
Item Properties
Items have a name
, title
, type
, and other optional properties.
affix
Description | Items can be affixed Specify the |
---|---|
Required? | No |
Example |
|
Supports Go templates? | Yes |