# Refer to https://github.com/apache/skywalking-infra-e2e/blob/main/docs/en/setup/Configuration-File.md

setup:
  env: kind
  file: ./manifests/kind.yaml
  init-system-environment: env
  kind:
    import-images:
      - cluster-agent:local
      - pingcap/pd:v7.5.1
      - pingcap/tikv:v7.5.1
      - pingcap/tidb:v7.5.1
    expose-ports:
      - namespace: tidb123456789
        resource: service/cluster-agent
        port: 8080
  steps:
    - name: install kubectl
      command: bash ./scripts/install.sh kubectl

    - name: install helm
      command: bash ./scripts/install.sh helm

    - name: deploy tidb operator
      command: |
        for file in ../../../helm-charts/tidb-operator/*.yaml; do kubectl create -f $file || true; done
        helm install tidb-operator ../../../helm-charts/tidb-operator/$TIDB_OPERATOR_CHART/ \
          --namespace tidb-admin \
          --create-namespace \
          --values ./manifests/tidb-operator-values.yaml
      wait:
        - namespace: tidb-admin
          resource: pod
          for: condition=Ready

    - name: deploy cert-manager
      command: |
        kubectl apply -f ../../../helm-charts/certmanager/$CERT_MANAGER_CRD
        helm install cert-manager ../../../helm-charts/certmanager/$CERT_MANAGER_CHART \
          --namespace cert-manager \
          --create-namespace \
      wait:
        - namespace: cert-manager
          resource: pod
          for: condition=Ready

    - name: create a tidb cluster with tls enabled
      command: |
        kubectl create ns tidb123456789
        kubectl create -n tidb123456789 -f manifests/tidbcluster/

    - name: deploy cluster-agent
      command: |
        helm install cluster-agent ../../../helm-charts/cluster-agent/ \
          --namespace tidb123456789 \
          --values ./manifests/cluster-agent-values.yaml
      wait:
        - namespace: tidb123456789
          resource: pod
          for: condition=Ready

    - name: port-forward cluster-agent service
      command:
        kubectl port-forward svc/cluster-agent -n tidb123456789 8080:8080 &
  timeout: 25m

# only support verify yaml format
verify:
  retry:
    count: 2
    interval: 3s
  cases:
    - name: "[restart the tidb component gracefully]"
      query: "http --print=b --ignore-stdin POST localhost:8080/api/v1/clusters/123456789:restart operation_id=test cluster_id=123456789 target_type=COMPONENT target_name=tidb"
      expected: cases/success.yaml

    - name: "[restart the tidb component with the same operation_id]"
      query: "http --print=b --ignore-stdin POST localhost:8080/api/v1/clusters/123456789:restart operation_id=test cluster_id=123456789 target_type=COMPONENT target_name=tidb"
      expected: cases/tc_not_ready.yaml

cleanup:
  on: never # always, never, failure, success
