How can I prevent installs when a Preflight Check fails

In the 0.30.0 release of Troubleshoot and version 1.67 of App Manager, we added a new property called strict to analyzers. When this is set to true and the Analyzer fails, it will block the deployment of the application. This applies to new installs as well as to updates.

Take the following preflight check:

apiVersion: troubleshoot.replicated.com/v1beta1
kind: Preflight
metadata:
  name: example-preflight-checks
spec:
  analyzers:
    - containerRuntime:
        outcomes:
          - pass:
              when: "== containerd"
              message: ContainerD container runtime was found.
          - fail:
              message: Did not find ContainerD container runtime.

In the above example, if we run the preflight on a cluster that does not have containerd as the Container Runtime Interface (CRI) it will fail. However, you would be able to continue and deploy the application.

If we modify it by adding the strict shared property as shown below, the deployment is blocked.

apiVersion: troubleshoot.replicated.com/v1beta1
kind: Preflight
metadata:
  name: example-preflight-checks
spec:
  analyzers:
    - containerRuntime:
        strict: true
        outcomes:
          - pass:
              when: "== containerd"
              message: ContainerD container runtime was found.
          - fail:
              message: Did not find ContainerD container runtime.

There may be some instances in which you may want to set the strict property to true only under certain conditions. For example, during a POC, or when deploying to a test environment, we may not want to block the deployment even if the analyzer fails.

To accomplish this, use template functions. There are several available that allow you to use runtime values in your manifests.

In this example, we are going to use information about the license, specifically the license type:

apiVersion: troubleshoot.replicated.com/v1beta1
kind: Preflight
metadata:
  name: example-preflight-checks
spec:
  analyzers:
    - containerRuntime:
        strict: 'repl{{  eq (LicenseFieldValue "licenseType") "prod" }}'
        outcomes:
          - pass:
              when: "== containerd"
              message: ContainerD container runtime was found.
          - fail:
              message: Did not find ContainerD container runtime.