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

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