{{- /*
Copyright Broadcom, Inc. All Rights Reserved.
SPDX-License-Identifier: APACHE-2.0
*/}}

{{- if and .Values.queryFrontend.enabled .Values.queryFrontend.ingress.enabled -}}
apiVersion: {{ include "common.capabilities.ingress.apiVersion" . }}
kind: Ingress
metadata:
  name: {{ include "thanos.query-frontend.fullname" . }}
  namespace: {{ include "common.names.namespace" . }}
  {{- $labels := include "common.tplvalues.merge" ( dict "values" ( list .Values.queryFrontend.ingress.labels .Values.commonLabels ) "context" . ) }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" $labels "context" $ ) | nindent 4 }}
    app.kubernetes.io/component: query-frontend
  {{- if or .Values.queryFrontend.ingress.annotations .Values.commonAnnotations }}
  {{- $annotations := include "common.tplvalues.merge" ( dict "values" ( list .Values.queryFrontend.ingress.annotations .Values.commonAnnotations ) "context" . ) }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $) | nindent 4 }}
  {{- end }}
spec:
  {{- if .Values.queryFrontend.ingress.ingressClassName }}
  ingressClassName: {{ .Values.queryFrontend.ingress.ingressClassName | quote }}
  {{- end }}
  rules:
    {{- if .Values.queryFrontend.ingress.hostname }}
    - host: {{ include "common.tplvalues.render" ( dict "value" .Values.queryFrontend.ingress.hostname "context" $ ) }}
      http:
        paths:
          - path: {{ .Values.queryFrontend.ingress.path }}
            pathType: {{ .Values.queryFrontend.ingress.pathType }}
            backend: {{- include "common.ingress.backend" (dict "serviceName" (printf "%s-%s"  (include "common.names.fullname" .) "query-frontend") "servicePort" "http" "context" $)  | nindent 14 }}
    {{- end }}
    {{- range .Values.queryFrontend.ingress.extraHosts }}
    - host: {{ .name }}
      http:
        paths:
          - path: {{ default "/" .path }}
            pathType: {{ default "ImplementationSpecific" .pathType }}
            backend: {{- include "common.ingress.backend" (dict "serviceName" (printf "%s-%s"  (include "common.names.fullname" $) "query-frontend") "servicePort" "http" "context" $) | nindent 14 }}
    {{- end }}
    {{- if .Values.queryFrontend.ingress.extraRules }}
    {{- include "common.tplvalues.render" (dict "value" .Values.queryFrontend.ingress.extraRules "context" $) | nindent 4 }}
    {{- end }}
  {{- if or (and .Values.queryFrontend.ingress.tls (or (include "common.ingress.certManagerRequest" ( dict "annotations" .Values.queryFrontend.ingress.annotations )) .Values.queryFrontend.ingress.selfSigned)) .Values.queryFrontend.ingress.extraTls }}
  tls:
    {{- if and .Values.queryFrontend.ingress.tls (or (include "common.ingress.certManagerRequest" ( dict "annotations" .Values.queryFrontend.ingress.annotations )) .Values.queryFrontend.ingress.selfSigned) }}
    - hosts:
        - {{ .Values.queryFrontend.ingress.hostname }}
      secretName: {{ printf "%s-query-frontend" (include "common.names.fullname" .) }}
    {{- end }}
    {{- if .Values.queryFrontend.ingress.extraTls }}
    {{- include "common.tplvalues.render" (dict "value" .Values.queryFrontend.ingress.extraTls "context" $) | nindent 4 }}
    {{- end }}
  {{- end }}
{{- end }}
