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

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