{{- if .Values.storegateway.ingress.grpc.enabled -}}
apiVersion: {{ include "common.capabilities.ingress.apiVersion" . }}
kind: Ingress
metadata:
  name: {{ include "common.names.fullname" . }}-storegateway-grpc
  namespace: {{ .Release.Namespace | quote }}
  labels: {{- include "common.labels.standard" . | nindent 4 }}
    app.kubernetes.io/component: storegateway
    {{- if .Values.commonLabels }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
  annotations:
    {{- if .Values.commonAnnotations }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
    {{- end }}
    {{- if .Values.storegateway.ingress.grpc.annotations }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.storegateway.ingress.grpc.annotations "context" $ ) | nindent 4 }}
    {{- end }}
spec:
  {{- if and .Values.storegateway.ingress.grpc.ingressClassName (include "common.ingress.supportsIngressClassname" .) }}
  ingressClassName: {{ .Values.storegateway.ingress.grpc.ingressClassName | quote }}
  {{- end }}
  rules:
    {{- if .Values.storegateway.ingress.grpc.hostname }}
    - host: {{ .Values.storegateway.ingress.grpc.hostname }}
      http:
        paths:
          - path: {{ .Values.storegateway.ingress.grpc.path }}
            {{- if eq "true" (include "common.ingress.supportsPathType" .) }}
            pathType: {{ .Values.storegateway.ingress.grpc.pathType }}
            {{- end }}
            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 }}
            {{- if eq "true" (include "common.ingress.supportsPathType" $) }}
            pathType: {{ default "ImplementationSpecific" .pathType }}
            {{- end }}
            backend: {{- include "common.ingress.backend" (dict "serviceName" (printf "%s-%s"  (include "common.names.fullname" $) "storegateway") "servicePort" "grpc" "context" $) | nindent 14 }}
    {{- end }}
  {{- if or (and .Values.storegateway.ingress.grpc.tls (or (include "thanos.ingress.certManagerRequest" .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 "thanos.ingress.certManagerRequest" .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 }}
    {{- toYaml .Values.storegateway.ingress.grpc.extraTls | nindent 4 }}
    {{- end }}
  {{- end }}
{{- end }}
