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

---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: {{ kube_job_name }}-sglang-prefill
  namespace: {{ name_space }}
spec:
  replicas: {{ prefill_size }}
  serviceName: {{ kube_job_name }}-sglang-prefill-headless
  selector:
    matchLabels:
      app: sgl-ascend
      task: prefill
  template:
    metadata:
      labels:
        app: sgl-ascend
        task: prefill
    spec:
      restartPolicy: Always
      hostNetwork: True
      containers:
      - image: {{ image }}
        imagePullPolicy: IfNotPresent
        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 }}"
        command: ["/bin/bash", "-c"]
        args:
          - |
             bash /root/sglang/python/sglang/test/ascend/e2e/run_npu_testcase.sh {{ test_case }}
             exit $?
        resources:
          requests:
            huawei.com/Ascend910: 16
          limits:
            huawei.com/Ascend910: 16
        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:
      - name: share
        hostPath:
          path: /home
      - name: ascend-driver
        hostPath:
          path: /usr/local/Ascend/driver
      - name: localtime
        hostPath:
          path: /etc/localtime
      nodeSelector:
        accelerator: huawei-Ascend910
        accelerator-type: module-a3-16

---
apiVersion: v1
kind: Service
metadata:
  name: {{ kube_job_name }}-sglang-prefill-headless
  namespace: {{ name_space }}
spec:
  clusterIP: None
  selector:
    app: sgl-ascend
    task: prefill
  ports:
  - port: 80
    name: dummy-port

---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: {{ kube_job_name }}-sglang-decode
  namespace: {{ name_space }}
spec:
  replicas: {{ decode_size }}
  serviceName: {{ kube_job_name }}-sglang-decode-headless
  selector:
    matchLabels:
      app: sgl-ascend
      task: decode
  template:
    metadata:
      labels:
        app: sgl-ascend
        task: decode
    spec:
      restartPolicy: Always
      hostNetwork: True
      containers:
      - image: {{ image }}
        imagePullPolicy: IfNotPresent
        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 }}"
        command: ["/bin/bash", "-c"]
        args:
          - |
             bash /root/sglang/python/sglang/test/ascend/e2e/run_npu_testcase.sh {{ test_case }}
             exit $?
        resources:
          requests:
            huawei.com/Ascend910: 16
          limits:
            huawei.com/Ascend910: 16
        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:
      - name: share
        hostPath:
          path: /home
      - name: ascend-driver
        hostPath:
          path: /usr/local/Ascend/driver
      - name: localtime
        hostPath:
          path: /etc/localtime
      nodeSelector:
        accelerator: huawei-Ascend910
        accelerator-type: module-a3-16

---
apiVersion: v1
kind: Service
metadata:
  name: {{ kube_job_name }}-sglang-decode-headless
  namespace: {{ name_space }}
spec:
  clusterIP: None
  selector:
    app: sgl-ascend
    task: decode
  ports:
  - port: 80
    name: dummy-port

---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: {{ kube_job_name }}-sglang-router
  namespace: {{ name_space }}
spec:
  replicas: {{ router_size }}
  serviceName: {{ kube_job_name }}-sglang-router-headless
  selector:
    matchLabels:
      app: sgl-ascend
      task: router
  template:
    metadata:
      labels:
        app: sgl-ascend
        task: router
    spec:
      hostNetwork: True
      containers:
      - image: {{ image }}
        imagePullPolicy: IfNotPresent
        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 }}"
        command: ["/bin/bash", "-c"]
        args:
          - |
             bash /root/sglang/python/sglang/test/ascend/e2e/run_npu_testcase.sh {{ test_case }}
        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:
      - name: share
        hostPath:
          path: /home
      - name: ascend-driver
        hostPath:
          path: /usr/local/Ascend/driver
      - name: localtime
        hostPath:
          path: /etc/localtime
      nodeSelector:
        accelerator: huawei-Ascend910
        accelerator-type: module-a3-16

---
apiVersion: v1
kind: Service
metadata:
  name: {{ kube_job_name }}-sglang-router-headless
  namespace: {{ name_space }}
spec:
  clusterIP: None
  selector:
    app: sgl-ascend
    task: router
  ports:
  - port: 80
    name: dummy-port
