suite: Deployment scheduling configuration
templates:
  - deployment.yaml
release:
  name: external-dns
  namespace: default
tests:
  - it: should not provide defaults for affinities or tolerations
    asserts:
      - isKind:
          of: Deployment
      - notExists:
          path: spec.template.spec.tolerations
      - notExists:
          path: spec.template.spec.affinity

  - it: should provide support for custom affinities
    set:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: topology.kubernetes.io/zone
                operator: In
                values:
                - zoneA
                - zoneB
    asserts:
      - equal:
          path: spec.template.spec.affinity
          value:
            nodeAffinity:
              requiredDuringSchedulingIgnoredDuringExecution:
                nodeSelectorTerms:
                - matchExpressions:
                  - key: topology.kubernetes.io/zone
                    operator: In
                    values:
                    - zoneA
                    - zoneB

  - it: should provide support for configuring node and pod affinities
    set:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - topologyKey: kubernetes.io/hostname
              labelSelector:
                matchExpressions:
                - key: app
                  operator: In
                  values:
                  - test-pod-scheduling-config
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                - key: datadog-agent
                  operator: In
                  values:
                  - standard
                - key: iam/scope
                  operator: In
                  values:
                  - namespace
    asserts:
      - equal:
          path: spec.template.spec.affinity
          value:
            nodeAffinity:
              requiredDuringSchedulingIgnoredDuringExecution:
                nodeSelectorTerms:
                  - matchExpressions:
                      - key: datadog-agent
                        operator: In
                        values:
                          - standard
                      - key: iam/scope
                        operator: In
                        values:
                          - namespace
            podAntiAffinity:
              requiredDuringSchedulingIgnoredDuringExecution:
                - labelSelector:
                    matchExpressions:
                      - key: app
                        operator: In
                        values:
                          - test-pod-scheduling-config
                  topologyKey: kubernetes.io/hostname

  - it: should provide support for configuring tolerations
    set:
      tolerations:
        - key: "key1"
          operator: "Equal"
          value: "value1"
          effect: "NoSchedule"
        - key: iam/scope
          operator: Equal
          value: namespace
          effect: NoExecute
    asserts:
      - notExists:
          path: spec.template.spec.affinity
      - exists:
          path: spec.template.spec.tolerations
      - equal:
          path: spec.template.spec.tolerations
          value:
            - effect: NoSchedule
              key: key1
              operator: Equal
              value: value1
            - effect: NoExecute
              key: iam/scope
              operator: Equal
              value: namespace

  - it: should include selector labels when setting topologySpreadConstraints
    set:
      topologySpreadConstraints:
        - maxSkew: 1
          topologyKey: topology.kubernetes.io/zone
          whenUnsatisfiable: ScheduleAnyway
    asserts:
      - exists:
          path: spec.template.spec.topologySpreadConstraints
      - equal:
          path: spec.template.spec.topologySpreadConstraints
          value:
            - maxSkew: 1
              topologyKey: topology.kubernetes.io/zone
              whenUnsatisfiable: ScheduleAnyway
              labelSelector:
                matchLabels:
                  app.kubernetes.io/name: external-dns
                  app.kubernetes.io/instance: external-dns
