{{/*
HTTPRoute for Vault behind Gateway API (e.g. Envoy Gateway).
Only Helm files under templates/ are rendered; a sibling httproute.yaml at chart root is ignored by Argo CD Helm.
*/}}
{{- if .Values.server.httpRoute.enabled }}
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: {{ template "vault.fullname" . }}-httproute
  namespace: {{ include "vault.namespace" . }}
  labels:
    helm.sh/chart: {{ include "vault.chart" . }}
    app.kubernetes.io/name: {{ include "vault.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
  parentRefs:
{{- range .Values.server.httpRoute.parentRefs }}
    - group: gateway.networking.k8s.io
      kind: Gateway
      name: {{ .name }}
      namespace: {{ .namespace }}
{{- if .sectionName }}
      sectionName: {{ .sectionName }}
{{- end }}
{{- end }}
  hostnames:
{{- range .Values.server.httpRoute.hostnames }}
    - {{ . | quote }}
{{- end }}
  rules:
    - matches:
{{ toYaml .Values.server.httpRoute.matches | nindent 8 }}
      backendRefs:
        - group: ""
          kind: Service
          name: {{ template "vault.fullname" . }}
          port: {{ .Values.server.service.port }}
          weight: 1
{{- end }}
