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

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