|
| 1 | +# Creating and Editing Configuration Fields |
| 2 | + |
| 3 | +This topic describes how to use the KOTS Config custom resource manifest file to add and edit fields in the KOTS Admin Console configuration screen. |
| 4 | + |
| 5 | +## About the Config Custom Resource |
| 6 | + |
| 7 | +Applications distributed with Replicated KOTS can include a configuration screen in the Admin Console to collect required or optional values from your users that are used to run your application. For more information about the configuration screen, see [About the Configuration Screen](config-screen-about). |
| 8 | + |
| 9 | +To include a configuration screen in the Admin Console for your application, you add a Config custom resource manifest file to a release for the application. |
| 10 | + |
| 11 | +You define the fields that appear on the configuration screen as an array of `groups` and `items` in the Config custom resource: |
| 12 | + * `groups`: A set of `items`. Each group must have a `name`, `title`, `description`, and `items`. For example, you can create a group of several user input fields that are all related to configuring an SMTP mail server. |
| 13 | + * `items`: An array of user input fields. Each array under `items` must have a `name`, `title`, and `type`. You can also include several optional properties. For example, in a group for configuring a SMTP mail server, you can have user input fields under `items` for the SMTP hostname, port, username, and password. |
| 14 | + |
| 15 | + There are several types of `items` supported in the Config manifest that allow you to collect different types of user inputs. For example, you can use the `password` input type to create a text field on the configuration screen that hides user input. |
| 16 | + |
| 17 | +For more information about the syntax of the Config custom resource manifest, see [Config](/reference/custom-resource-config). |
| 18 | + |
| 19 | +## About Regular Expression Validation |
| 20 | + |
| 21 | +You can use [RE2 regular expressions](https://github.com/google/re2/wiki/Syntax) (regex) to validate user input for config items, ensuring conformity to certain standards, such as valid email addresses, password complexity rules, IP addresses, and URLs. This prevents users from deploying an application with a verifiably invalid configuration. |
| 22 | + |
| 23 | +You add the `validation`, `regex`, `pattern` and `message` fields to items in the Config custom resource. Validation is supported for `text`, `textarea`, `password` and `file` config item types. For more information about regex validation fields, see [Item Validation](/reference/custom-resource-config#item-validation) in _Config_. |
| 24 | + |
| 25 | +The following example shows a common password complexity rule: |
| 26 | + |
| 27 | +``` |
| 28 | +- name: smtp-settings |
| 29 | + title: SMTP Settings |
| 30 | + items: |
| 31 | + - name: smtp_password |
| 32 | + title: SMTP Password |
| 33 | + type: password |
| 34 | + help_text: Set SMTP password |
| 35 | + validation: |
| 36 | + regex: |
| 37 | + pattern: ^(?:[\w@#$%^&+=!*()_\-{}[\]:;"'<>,.?\/|]){8,16}$ |
| 38 | + message: The password must be between 8 and 16 characters long and can contain a combination of uppercase letter, lowercase letters, digits, and special characters. |
| 39 | +``` |
| 40 | + |
| 41 | +## Add Fields to the Configuration Screen |
| 42 | + |
| 43 | +To add fields to the Admin Console configuration screen: |
| 44 | + |
| 45 | +1. In the [Vendor Portal](https://vendor.replicated.com/apps), click **Releases**. Then, either click **Create release** to create a new release, or click **Edit YAML** to edit an existing release. |
| 46 | +1. Create or open the Config custom resource manifest file in the desired release. A Config custom resource manifest file has `kind: Config`. |
| 47 | +1. In the Config custom resource manifest file, define custom user-input fields in an array of `groups` and `items`. |
| 48 | + |
| 49 | + **Example**: |
| 50 | + |
| 51 | + ```yaml |
| 52 | + apiVersion: kots.io/v1beta1 |
| 53 | + kind: Config |
| 54 | + metadata: |
| 55 | + name: my-application |
| 56 | + spec: |
| 57 | + groups: |
| 58 | + - name: smtp_settings |
| 59 | + title: SMTP Settings |
| 60 | + description: Configure SMTP Settings |
| 61 | + items: |
| 62 | + - name: enable_smtp |
| 63 | + title: Enable SMTP |
| 64 | + help_text: Enable SMTP |
| 65 | + type: bool |
| 66 | + default: "0" |
| 67 | + - name: smtp_host |
| 68 | + title: SMTP Hostname |
| 69 | + help_text: Set SMTP Hostname |
| 70 | + type: text |
| 71 | + - name: smtp_port |
| 72 | + title: SMTP Port |
| 73 | + help_text: Set SMTP Port |
| 74 | + type: text |
| 75 | + - name: smtp_user |
| 76 | + title: SMTP User |
| 77 | + help_text: Set SMTP User |
| 78 | + type: text |
| 79 | + - name: smtp_password |
| 80 | + title: SMTP Password |
| 81 | + type: password |
| 82 | + default: 'password' |
| 83 | + ``` |
| 84 | +
|
| 85 | + The example above includes a single group with the name `smtp_settings`. |
| 86 | + |
| 87 | + The `items` array for the `smtp_settings` group includes the following user-input fields: `enable_smtp`, `smtp_host`, `smtp_port`, `smtp_user`, and `smtp_password`. Additional item properties are available, such as `affix` to make items appear horizontally on the same line. For more information about item properties, see [Item Properties](/reference/custom-resource-config#item-properties) in Config. |
| 88 | + |
| 89 | + The following screenshot shows how the SMTP Settings group from the example YAML above displays in the Admin Console configuration screen during application installation: |
| 90 | + |
| 91 | +  |
| 92 | + |
| 93 | +1. (Optional) Add default values for the fields. You can add default values using one of the following properties: |
| 94 | + * **With the `default` property**: When you include the `default` key, KOTS uses this value when rendering the manifest files for your application. The value then displays as a placeholder on the configuration screen in the Admin Console for your users. KOTS only uses the default value if the user does not provide a different value. |
| 95 | + |
| 96 | + :::note |
| 97 | + If you change the `default` value in a later release of your application, installed instances of your application receive the updated value only if your users did not change the default from what it was when they initially installed the application. |
| 98 | + |
| 99 | + If a user did change a field from its default, the Admin Console does not overwrite the value they provided. |
| 100 | + ::: |
| 101 | + |
| 102 | + * **With the `value` property**: When you include the `value` key, KOTS does not overwrite this value during an application update. The value that you provide for the `value` key is visually indistinguishable from other values that your user provides on the Admin Console configuration screen. KOTS treats user-supplied values and the value that you provide for the `value` key as the same. |
| 103 | + |
| 104 | +2. (Optional) Add regular expressions to validate user input for `text`, `textarea`, `password` and `file` config item types. For more information, see [About Regular Expression Validation](#about-regular-expression-validation). |
| 105 | + |
| 106 | + **Example**: |
| 107 | + |
| 108 | + ```yaml |
| 109 | + - name: smtp_host |
| 110 | + title: SMTP Hostname |
| 111 | + help_text: Set SMTP Hostname |
| 112 | + type: text |
| 113 | + validation: |
| 114 | + regex: |
| 115 | + pattern: ^[a-zA-Z]([a-zA-Z0-9\-]+[\.]?)*[a-zA-Z0-9]$ |
| 116 | + message: Valid hostname starts with a letter (uppercase/lowercase), followed by zero or more groups of letters (uppercase/lowercase), digits, or hyphens, optionally followed by a period. Ends with a letter or digit. |
| 117 | + ``` |
| 118 | +3. (Optional) Mark fields as required by including `required: true`. When there are required fields, the user is prevented from proceeding with the installation until they provide a valid value for required fields. |
| 119 | + |
| 120 | + **Example**: |
| 121 | + |
| 122 | + ```yaml |
| 123 | + - name: smtp_password |
| 124 | + title: SMTP Password |
| 125 | + type: password |
| 126 | + required: true |
| 127 | + ``` |
| 128 | + |
| 129 | +4. Save and promote the release to a development environment to test your changes. |
| 130 | + |
| 131 | +## Next Steps |
| 132 | + |
| 133 | +After you add user input fields to the configuration screen, you use template functions to map the user-supplied values to manifest files in your release. If you use a Helm chart for your application, you map the values to the Helm chart `values.yaml` file using the HelmChart custom resource. |
| 134 | + |
| 135 | +For more information, see [Mapping User-Supplied Values](config-screen-map-inputs). |
0 commit comments