apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ kube_config_map }}
  namespace: {{ name_space }}
data: {}

---
apiVersion: batch.volcano.sh/v1alpha1
kind: Job
metadata:
  name: {{ kube_job_name }}
  namespace: {{ name_space }}
  labels:
    ring-controller.atlas: ascend-1980
    fault-scheduling: "force"
spec:
  minAvailable: {{ prefill_size + decode_size + router_size }}
  schedulerName: volcano
  policies:
    - event: PodEvicted
      action: RestartJob
  queue: default
  tasks:
  - name: "sglang-prefill"
    replicas: {{ prefill_size }}
    template:
      metadata:
        labels:
          app: sgl-ascend
          ring-controller.atlas: ascend-1980
      spec:
        hostNetwork: True
        containers:
        - image: {{ image }}
          imagePullPolicy: Always
          securityContext:
            privileged: true
          name: sgl-ascend
          env:
          - name: HOSTNAME
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
          - name: POD_IP
            valueFrom:
              fieldRef:
                fieldPath: status.hostIP
          - name: INSTALL_SGLANG_FROM_SOURCE
            value: "{{ install_sglang_from_source }}"
          - name: KUBECONFIG
            value: "{{ kube_config }}"
          - name: NAMESPACE
            value: "{{ name_space }}"
          - name: KUBE_CONFIG_MAP
            value: "{{ kube_config_map }}"
          - name: HF_ENDPOINT
            value: "https://hf-mirror.com"
          - name: METRICS_DATA_FILE
            value: "{{ metrics_data_file }}"
          - name: SGLANG_IS_IN_CI
            value: "{{ sglang_is_in_ci }}"
          - name: TRANSFORMERS_VERSION_FOR_SGLANG
            value: "{{ transformers_version }}"
          command: ["/bin/bash", "-c"]
          args:
            - |
               {% if env in ["ci", "debug"] %}
               bash /root/sglang/python/sglang/test/ascend/e2e/run_npu_testcase.sh {{ test_case }}
               {% endif %}
               {% if env == "green" %}
               bash /root/sglang/python/sglang/test/ascend/e2e/run_npu_testcase_green.sh {{ test_case }}
               {% endif %}
          resources:
            requests:
              {% if env in ["ci", "debug"] %}
              huawei.com/ascend-1980: 16
              {% endif %}
              {% if env == "green" %}
              huawei.com/Ascend910: 16
              {% endif %}
            limits:
              {% if env in ["ci", "debug"] %}
              huawei.com/ascend-1980: 16
              {% endif %}
              {% if env == "green" %}
              huawei.com/Ascend910: 16
              {% endif %}
          volumeMounts:
          - name: ascend-driver
            mountPath: /usr/local/Ascend/driver
          - name: localtime
            mountPath: /etc/localtime
          - name: share
            mountPath: /data/ascend-ci-share-pkking-sglang
          - name: share
            mountPath: /root/.cache
          - name: share
            mountPath: /root/sglang
            subPath: {{ sglang_source_relative_path }}
        volumes:
        {% if env in ["ci", "debug"] %}
        - name: share
          persistentVolumeClaim:
            claimName: sglang-guiyang004
        {% endif %}
        {% if env == "green" %}
        - name: share
          hostPath:
            path: /home
        {% endif %}
        - name: ascend-driver
          hostPath:
            path: /usr/local/Ascend/driver
        - name: localtime
          hostPath:
            path: /etc/localtime
        {% if env == "debug" %}
        tolerations:
          - key: "instance"
            operator: "Equal"
            value: "npu-class-service"
            effect: "NoSchedule"
        {% endif %}
        nodeSelector:
          {% if env in ["ci", "debug"] %}
          accelerator/huawei-npu: ascend-snt9c
          {% endif %}
          {% if env == "debug" %}
          node-status: debug
          {% endif %}
          {% if env == "green" %}
          accelerator: huawei-Ascend910
          accelerator-type: module-a3-16
          {% endif %}
        restartPolicy: OnFailure
  - name: "sglang-decode"
    replicas: {{ decode_size }}
    template:
      metadata:
        labels:
          app: sgl-ascend
          ring-controller.atlas: ascend-1980
      spec:
        hostNetwork: True
        containers:
        - image: {{ image }}
          imagePullPolicy: Always
          securityContext:
            privileged: true
          name: sgl-ascend
          env:
          - name: HOSTNAME
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
          - name: POD_IP
            valueFrom:
              fieldRef:
                fieldPath: status.hostIP
          - name: INSTALL_SGLANG_FROM_SOURCE
            value: "{{ install_sglang_from_source }}"
          - name: KUBECONFIG
            value: "{{ kube_config }}"
          - name: NAMESPACE
            value: "{{ name_space }}"
          - name: KUBE_CONFIG_MAP
            value: "{{ kube_config_map }}"
          - name: HF_ENDPOINT
            value: "https://hf-mirror.com"
          - name: METRICS_DATA_FILE
            value: "{{ metrics_data_file }}"
          - name: SGLANG_IS_IN_CI
            value: "{{ sglang_is_in_ci }}"
          - name: TRANSFORMERS_VERSION_FOR_SGLANG
            value: "{{ transformers_version }}"
          command: ["/bin/bash", "-c"]
          args:
            - |
               {% if env in ["ci", "debug"] %}
               bash /root/sglang/python/sglang/test/ascend/e2e/run_npu_testcase.sh {{ test_case }}
               {% endif %}
               {% if env == "green" %}
               bash /root/sglang/python/sglang/test/ascend/e2e/run_npu_testcase_green.sh {{ test_case }}
               {% endif %}
          resources:
            requests:
              {% if env in ["ci", "debug"] %}
              huawei.com/ascend-1980: 16
              {% endif %}
              {% if env == "green" %}
              huawei.com/Ascend910: 16
              {% endif %}
            limits:
              {% if env in ["ci", "debug"] %}
              huawei.com/ascend-1980: 16
              {% endif %}
              {% if env == "green" %}
              huawei.com/Ascend910: 16
              {% endif %}
          volumeMounts:
          - name: ascend-driver
            mountPath: /usr/local/Ascend/driver
          - name: localtime
            mountPath: /etc/localtime
          - name: share
            mountPath: /data/ascend-ci-share-pkking-sglang
          - name: share
            mountPath: /root/.cache
          - name: share
            mountPath: /root/sglang
            subPath: {{ sglang_source_relative_path }}
        volumes:
        {% if env in ["ci", "debug"] %}
        - name: share
          persistentVolumeClaim:
            claimName: sglang-guiyang004
        {% endif %}
        {% if env == "green" %}
        - name: share
          hostPath:
            path: /home
        {% endif %}
        - name: ascend-driver
          hostPath:
            path: /usr/local/Ascend/driver
        - name: localtime
          hostPath:
            path: /etc/localtime
        {% if env == "debug" %}
        tolerations:
          - key: "instance"
            operator: "Equal"
            value: "npu-class-service"
            effect: "NoSchedule"
        {% endif %}
        nodeSelector:
          {% if env in ["ci", "debug"] %}
          accelerator/huawei-npu: ascend-snt9c
          {% endif %}
          {% if env == "debug" %}
          node-status: debug
          {% endif %}
          {% if env == "green" %}
          accelerator: huawei-Ascend910
          accelerator-type: module-a3-16
          {% endif %}
        restartPolicy: OnFailure
  - name: "sglang-router"
    replicas: {{ router_size }}
    template:
      metadata:
        labels:
          app: sgl-ascend
          ring-controller.atlas: ascend-1980
      spec:
        hostNetwork: True
        containers:
        - image: {{ image }}
          imagePullPolicy: Always
          securityContext:
            privileged: true
          name: sgl-ascend
          env:
          - name: HOSTNAME
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
          - name: POD_IP
            valueFrom:
              fieldRef:
                fieldPath: status.hostIP
          - name: INSTALL_SGLANG_FROM_SOURCE
            value: "{{ install_sglang_from_source }}"
          - name: METRICS_DATA_FILE
            value: "{{ metrics_data_file }}"
          - name: KUBECONFIG
            value: "{{ kube_config }}"
          - name: NAMESPACE
            value: "{{ name_space }}"
          - name: KUBE_CONFIG_MAP
            value: "{{ kube_config_map }}"
          - name: HF_ENDPOINT
            value: "https://hf-mirror.com"
          - name: SGLANG_IS_IN_CI
            value: "{{ sglang_is_in_ci }}"
          - name: TRANSFORMERS_VERSION_FOR_SGLANG
            value: "{{ transformers_version }}"
          command: ["/bin/bash", "-c"]
          args:
            - |
               {% if env in ["ci", "debug"] %}
               bash /root/sglang/python/sglang/test/ascend/e2e/run_npu_testcase.sh {{ test_case }}
               {% endif %}
               {% if env == "green" %}
               bash /root/sglang/python/sglang/test/ascend/e2e/run_npu_testcase_green.sh {{ test_case }}
               {% endif %}
          resources:
            requests:
              cpu: "4"
            limits:
              cpu: "4"
          volumeMounts:
          - name: ascend-driver
            mountPath: /usr/local/Ascend/driver
          - name: localtime
            mountPath: /etc/localtime
          - name: share
            mountPath: /data/ascend-ci-share-pkking-sglang
          - name: share
            mountPath: /root/.cache
          - name: share
            mountPath: /root/sglang
            subPath: {{ sglang_source_relative_path }}
        volumes:
        {% if env in ["ci", "debug"] %}
        - name: share
          persistentVolumeClaim:
            claimName: sglang-guiyang004
        {% endif %}
        {% if env == "green" %}
        - name: share
          hostPath:
            path: /home
        {% endif %}
        - name: ascend-driver
          hostPath:
            path: /usr/local/Ascend/driver
        - name: localtime
          hostPath:
            path: /etc/localtime
        {% if env == "debug" %}
        tolerations:
          - key: "instance"
            operator: "Equal"
            value: "npu-class-service"
            effect: "NoSchedule"
        {% endif %}
        nodeSelector:
          {% if env in ["ci", "debug"] %}
          accelerator/huawei-npu: ascend-snt9c
          {% endif %}
          {% if env == "debug" %}
          node-status: debug
          {% endif %}
          {% if env == "green" %}
          accelerator: huawei-Ascend910
          accelerator-type: module-a3-16
          {% endif %}
        restartPolicy: OnFailure
