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

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