apiVersion: v1
policies:
  - name: labels_best_practices
    isDefault: true
    rules:
      - identifier: CUSTOM_WORKLOAD_INCORRECT_ENVIRONMENT_LABELS
        messageOnFailure: ""
      - identifier: CUSTOM_WORKLOAD_MISSING_LABEL_OWNER_VALUE
        messageOnFailure: ""
      - identifier: CUSTOM_WORKLOAD_INVALID_LABELS_VALUE
        messageOnFailure: ""

customRules:
  - identifier: CUSTOM_WORKLOAD_INCORRECT_ENVIRONMENT_LABELS
    name: Ensure correct environment labels are used [CUSTOM RULE]
    defaultMessageOnFailure: Use only approved environment labels (`prod`, `staging` and `test`)
    schema:
      properties:
        metadata:
          properties:
            labels:
              properties:
                environment:
                  enum:
                    - prod
                    - staging
                    - test
              required:
                - environment
          required:
            - labels

  - identifier: CUSTOM_WORKLOAD_MISSING_LABEL_OWNER_VALUE
    name: Ensure workload has a configured `owner` label [CUSTOM RULE]
    defaultMessageOnFailure: Add a proper owner label to know which person/team to ping when needed
    schema:
      properties:
        metadata:
          properties:
            labels:
              required:
                - owner
          required:
            - labels

  - identifier: CUSTOM_WORKLOAD_INVALID_LABELS_VALUE
    name: Ensure workload has valid label values [CUSTOM RULE]
    defaultMessageOnFailure: All lables values must follow the RFC 1123 hostname standard (https://knowledge.broadcom.com/external/article/49542/restrictions-on-valid-host-names.html)
    schema:
      properties:
        metadata:
          properties:
            labels:
              patternProperties:
                ^.*$:
                  format: hostname
              additionalProperties: false
