Show/hide fields in the KOTS Config based on deployment t-shirt size

It’s often necessary to have different sets of default values and/or fields in the KOTS Config based on the size of the deployment.

For example:

  • Less than 100 users = Small Deployment configs
  • 101-500 users = Medium Deployment configs
  • 501+ = Large Deployment configs

One way to apply this type of “t-shirt sizing” in the KOTS config is to first create a custom field in the license that defines the customer’s number of users. For more information about how to add custom fields, see Managing Custom License Fields in the Replicated docs.

Then, in the KOTS Config custom resource, you can conditionally show or hide fields based on this custom license field using KOTS template functions in the when property, as shown below:

# KOTS Config custom resource
apiVersion: kots.io/v1beta1
kind: Config
metadata:
  name: config-sample
spec:
  groups:  
  - name: example_group
    title: Example Config
    items:
    - name: small
      title: Small (100 or Fewer Seats)
      type: text
      default: Default for small teams
      # Use le and atoi functions to display this config item 
      # only when the value of the numSeats entitlement is
      # less than or equal to 100
      when: repl{{ le (atoi (LicenseFieldValue "numSeats")) 100 }}
    - name: medium
      title: Medium (101-1000 Seats)
      type: text
      default: Default for medium teams
      # Use ge, le, and atoi functions to display this config item 
      # only when the value of the numSeats entitlement is
      # greater than or equal to 101 and less than or equal to 1000
      when: repl{{ (and (ge (atoi (LicenseFieldValue "numSeats")) 101) (le (atoi (LicenseFieldValue "numSeats")) 1000)) }}
    - name: large
      title: Large (More Than 1000 Seats)
      type: text
      default: Default for large teams
      # Use gt and atoi functions to display this config item 
      # only when the value of the numSeats entitlement is
      # greater than 1000
      when: repl{{ gt (atoi (LicenseFieldValue "numSeats")) 1000 }}

This example uses:

  • KOTS LicenseFieldValue template function to evaluate the number of seats permitted by the license by rendering the value of the numSeats license field
  • Sprig atoi function to convert the string values returned by LicenseFieldValue to integers
  • Go binary comparison operators gt, lt, ge, and le to compare the integers

For more examples of conditionally showing/hiding config fields using the when property, see Using Conditional Statements in Configuration Fields in the Replicated docs.