{{/*
  全局 HPA 模板示例（参考用）。
  实际 HPA 应在各服务自身的 chart 中定义，以便针对服务特性调参。
  本模板在 edu-platform 中默认不渲染（hpa.targetService 为空时跳过）。
*/}}
{{- if and .Values.hpa.enabled .Values.hpa.targetService }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: {{ .Values.hpa.targetService }}-hpa
  namespace: edu-services
  labels:
    {{- include "edu-platform.labels" . | nindent 4 }}
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: {{ .Values.hpa.targetService }}
  minReplicas: {{ .Values.hpa.minReplicas }}
  maxReplicas: {{ .Values.hpa.maxReplicas }}
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: {{ .Values.hpa.targetCPUUtilizationPercentage }}
    - type: Resource
      resource:
        name: memory
        target:
          type: Utilization
          averageUtilization: {{ .Values.hpa.targetMemoryUtilizationPercentage }}
{{- end }}
