{{- /*
Catalyst HTTPRoute for Grafana — bp-grafana (issue #387, Cilium Gateway
API migration). Replaces the upstream chart's networking.k8s.io/v1.Ingress
on Sovereigns.

Backend reference: the upstream grafana/grafana chart's Service is named
`<release>` by default (the chart's `grafana.fullname` template). With
releaseName=grafana in the bootstrap-kit slot the Service is `grafana`.
The Service port is 80 → targets pod port 3000 (chart default; matches
values.yaml service.port=80, targetPort=3000).
*/}}
{{- if and .Values.gateway .Values.gateway.enabled -}}
{{- if .Values.gateway.host }}
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: {{ .Values.gateway.name | default "grafana" | quote }}
  namespace: {{ .Release.Namespace }}
  labels:
    catalyst.openova.io/blueprint: bp-grafana
    catalyst.openova.io/component: grafana
spec:
  parentRefs:
    - name: {{ .Values.gateway.parentRef.name | default "cilium-gateway" | quote }}
      namespace: {{ .Values.gateway.parentRef.namespace | default "kube-system" | quote }}
      {{- with .Values.gateway.parentRef.sectionName }}
      sectionName: {{ . | quote }}
      {{- end }}
  hostnames:
    - {{ .Values.gateway.host | quote }}
  rules:
    - matches:
        - path:
            type: PathPrefix
            value: {{ .Values.gateway.path | default "/" | quote }}
      backendRefs:
        - name: {{ .Values.gateway.backendService | default .Release.Name | quote }}
          port: {{ .Values.gateway.backendPort | default 80 }}
{{- end }}
{{- end }}
