#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

suite: Test Celeborn worker statefulset

templates:
  - worker/statefulset.yaml

release:
  name: celeborn

tests:
  - it: Should add extra pod annotations if `podAnnotations` is specified
    set:
      podAnnotations:
        key1: value1
        key2: value2
    asserts:
      - equal:
          path: spec.template.metadata.annotations.key1
          value: value1
      - equal:
          path: spec.template.metadata.annotations.key2
          value: value2

  - it: Should use the specified image if `image.repository` and `image.tag` is set
    set:
      image:
        repository: test-repository
        tag: test-tag
    asserts:
      - equal:
          path: spec.template.spec.containers[0].image
          value: test-repository:test-tag

  - it: Should use the specified image pull policy if `image.pullPolicy` is set
    set:
      image:
        pullPolicy: Always
    asserts:
      - equal:
          path: spec.template.spec.containers[0].imagePullPolicy
          value: Always

  - it: Should add secrets if `imagePullSecrets` is set
    set:
      imagePullSecrets:
        - name: test-secret1
        - name: test-secret2
    asserts:
      - equal:
          path: spec.template.spec.imagePullSecrets[0].name
          value: test-secret1
      - equal:
          path: spec.template.spec.imagePullSecrets[1].name
          value: test-secret2

  - it: Should add node selector if `nodeSelector` is set
    set:
      nodeSelector:
        key1: value1
        key2: value2
    asserts:
      - equal:
          path: spec.template.spec.nodeSelector.key1
          value: value1
      - equal:
          path: spec.template.spec.nodeSelector.key2
          value: value2

  - it: Should add tolerations if `tolerations` is set
    set:
      tolerations:
        - key: key1
          operator: Equal
          value: value1
          effect: NoSchedule
        - key: key2
          operator: Exists
          effect: NoSchedule
    asserts:
      - equal:
          path: spec.template.spec.tolerations
          value:
            - key: key1
              operator: Equal
              value: value1
              effect: NoSchedule
            - key: key2
              operator: Exists
              effect: NoSchedule

  - it: Should use the specified affinity if `affinity.worker` is specified
    set:
      affinity:
        worker:
          nodeAffinity:
            requiredDuringSchedulingIgnoredDuringExecution:
              nodeSelectorTerms:
                - matchExpressions:
                    - key: topology.kubernetes.io/zone
                      operator: In
                      values:
                        - antarctica-east1
                        - antarctica-west1
            preferredDuringSchedulingIgnoredDuringExecution:
              - weight: 1
                preference:
                  matchExpressions:
                    - key: another-node-label-key
                      operator: In
                      values:
                        - another-node-label-value
    asserts:
      - equal:
          path: spec.template.spec.affinity.nodeAffinity
          value:
            requiredDuringSchedulingIgnoredDuringExecution:
              nodeSelectorTerms:
                - matchExpressions:
                    - key: topology.kubernetes.io/zone
                      operator: In
                      values:
                        - antarctica-east1
                        - antarctica-west1
            preferredDuringSchedulingIgnoredDuringExecution:
              - weight: 1
                preference:
                  matchExpressions:
                    - key: another-node-label-key
                      operator: In
                      values:
                        - another-node-label-value

  - it: Should use the specified priority class name if `priorityClass.worker.name` is set
    set:
      priorityClass:
        worker:
          name: test-priority-class
    asserts:
      - equal:
          path: spec.template.spec.priorityClassName
          value: test-priority-class

  - it: Should use the specified dns policy if `dnsPolicy` is set
    set:
      dnsPolicy: ClusterFirstWithHostNet
    asserts:
      - equal:
          path: spec.template.spec.dnsPolicy
          value: ClusterFirstWithHostNet

  - it: Should enable host network if `hostNetwork` is set to true
    set:
      hostNetwork: true
    asserts:
      - equal:
          path: spec.template.spec.hostNetwork
          value: true

  - it: Should use the specified security context if `podSecurityContext` is set
    set:
      securityContext:
        runAsUser: 1000
        runAsGroup: 2000
        fsGroup: 3000
    asserts:
      - equal:
          path: spec.template.spec.securityContext.runAsUser
          value: 1000
      - equal:
          path: spec.template.spec.securityContext.runAsGroup
          value: 2000
      - equal:
          path: spec.template.spec.securityContext.fsGroup
          value: 3000

  - it: Should use the specified replicas if `workerReplicas` is set
    set:
      workerReplicas: 10
    asserts:
      - equal:
          path: spec.replicas
          value: 10
