How Can I Use License Custom Fields Value in a Pre-Flight Check?

The short answer is YES!

Let’s illustrate how to do this with a somewhat contrived example. Let’s say we want to license our product based on the number of nodes in the cluster. When we run a pre flight check, or even a support bundle, we want to check the number of nodes in the cluster against what we have licensed our customer.

Step 1 - Create Custom License Field

First, we’ll create our Custom License Field as shown below:

Step 2 - Create Pre-Flight Check Using the Custom License Field

Then, we’ll define a simple pre-flight check that uses the node resources analyzer to check against the value:

apiVersion: troubleshoot.replicated.com/v1beta1
kind: Preflight
metadata:
  name: example-preflight-checks
spec:
  analyzers:
    - nodeResources:
        checkName: Node Count Check
        outcomes:
          - fail:
              when: 'count() > {{repl LicenseFieldValue "node_count"}}'
              message: The cluster has more nodes than the {{repl LicenseFieldValue "node_count"}} you are licensed for.
          - pass:
              message: The number of nodes matches your license ({{repl LicenseFieldValue "node_count"}})

Step 3 - Create Test License

Now, we’ll create the license and set up to fail. My cluster has 3 nodes, so I will set the value initially to 2:

Step 4 - Validate!

To quickly test this, I am going to deploy my app to a test cluster. Since my cluster has 3 nodes, the preflight fails:

To test the other condition, we’ll update the license field to 4, and then sync the license:

Once we sync the license, we are prompted to update the application and run the preflights again. This time, they pass:

Note that you can also use the value in the Custom License Field in the message that is displayed to the end user.