apiVersion: troubleshoot.sh/v1beta2
kind: Preflight
metadata:
  name: sample
spec:
  analyzers:
    - nodeResources:
        checkName: Must have at least 3 nodes in the cluster
        outcomes:
          - fail:
              when: "< 3"
              message: This application requires at least 3 nodes
          - warn:
              when: "< 5"
              message: This application recommends at last 5 nodes.
          - pass:
              message: This cluster has enough nodes.
    - nodeResources:
        checkName: Must have 3 nodes with at least 6 cores each
        filters:
          cpuCapacity: "6"
        outcomes:
          - fail:
              when: "count() < 3"
              message: This application requires at least 3 nodes with 6 cores each
          - pass:
              message: This cluster has enough nodes with enough cores
    - nodeResources:
        checkName: Must have 1 node with 16 GB (available) memory and 10 cores (on a single node)
        filters:
          memoryAllocatable: 16Gi
          cpuCapacity: "10"
        outcomes:
          - fail:
              when: "< 1"
              message: This application requires at least 1 node with 16GB available memory
          - pass:
              message: This cluster has a node with enough memory.
    - nodeResources:
        checkName: Must have 1 node with 16 GB (available) memory and 4 cores of amd64 arch (on a single node)
        filters:
          memoryAllocatable: 16Gi
          cpuArchitecture: amd64
          cpuCapacity: "4"
        outcomes:
          - fail:
              when: "< 1"
              message: This application requires at least 1 node with amd64 arch and 16GB available memory
          - pass:
              message: This cluster has a node with the correct architecture and enough memory.
    - nodeResources:
        checkName: Must have 1 manager node with 16 GB (available) memory and 4 cores of amd64 arch
        filters:
          selector:
            matchLabel:
              node-role.kubernetes.io/master: ""
          memoryAllocatable: 16Gi
          cpuArchitecture: amd64
          cpuCapacity: "6"
        outcomes:
          - fail:
              when: "< 1"
              message: This application requires at least 1 manager node with amd64 arch, 16GB available memory, and the label `node-role.kubernetes.io/master=""`
          - pass:
              message: This cluster has a node with the correct architecture and enough memory.
    - nodeResources:
        checkName: There must be a total of at least 32Gi of memory on all nodes
        outcomes:
          - fail:
              when: "sum(memoryCapacity) < 32Gi"
              message: This application requires that 32Gi or more memory be available to the cluster
          - pass:
              message: This cluster has sufficient memory
    - nodeResources:
        checkName: There must be a total of at least 32Gi of memory on amd64 nodes
        filters:
          cpuArchitecture: amd64
        outcomes:
          - fail:
              when: "sum(memoryCapacity) < 32Gi"
              message: This application requires that 32Gi or more memory on amd64 nodes be available to the cluster
          - pass:
              message: This cluster has sufficient memory
