# 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.

# This file is used to show how to write configuration files and can be used to test.

setup:
  env: kind
  file: ../../../kind.yaml
  init-system-environment: ../../../../../../script/env
  kind:
    import-images:
      - skywalking/ui:latest
      - skywalking/oap:latest
      - test/continuous:test
    expose-ports:
      - namespace: istio-system
        resource: service/skywalking-ui
        port: 80
  steps:
    - name: set PATH
      command: export PATH=/tmp/skywalking-infra-e2e/bin:$PATH
    - name: install yq
      command: bash test/e2e-v2/script/prepare/setup-e2e-shell/install.sh yq
    - name: install swctl
      command: bash test/e2e-v2/script/prepare/setup-e2e-shell/install.sh swctl
    - name: install kubectl
      command: bash test/e2e-v2/script/prepare/setup-e2e-shell/install.sh kubectl
    - name: Install helm
      command: bash test/e2e-v2/script/prepare/setup-e2e-shell/install.sh helm
    - name: Install kubectl
      command: bash test/e2e-v2/script/prepare/setup-e2e-shell/install.sh kubectl
    - name: Install SkyWalking
      command: |
        kubectl create namespace istio-system
        helm -n istio-system install skywalking \
          oci://ghcr.io/apache/skywalking-helm/skywalking-helm \
          --version "0.0.0-${SW_KUBERNETES_COMMIT_SHA}" \
          --set fullnameOverride=skywalking \
          --set elasticsearch.replicas=1 \
          --set elasticsearch.minimumMasterNodes=1 \
          --set oap.replicas=1 \
          --set ui.image.repository=skywalking/ui \
          --set ui.image.tag=latest \
          --set oap.image.tag=latest \
          --set oap.image.repository=skywalking/oap \
          --set oap.storageType=elasticsearch \
          --set oap.env.SW_STORAGE_ES_LOGIC_SHARDING=true \
          -f test/e2e-v2/cases/profiling/ebpf/kubernetes-values.yaml
      wait:
        - namespace: istio-system
          resource: deployments/skywalking-oap
          for: condition=available
    - name: Deploy services
      command: |
        export IMAGE_NAME=test/continuous:test
        export HAS_SERVICE_EXP=".Pod.HasContainer \\\"test-continuous\\\""
        export SERVICE_NAME_EXP="sqrt"
        envsubst < test/e2e-v2/cases/profiling/ebpf/continuous/service.yaml | kubectl apply -f -
        envsubst < test/e2e-v2/cases/profiling/ebpf/rover.yaml | kubectl apply -f -
      wait:
        - namespace: default
          resource: pod
          for: condition=Ready
  timeout: 25m

verify:
  retry:
    count: 20
    interval: 10s
  cases:
    - includes:
        - ../../profiling-cases.yaml