{{- if .Values.ingress.enabled -}}
{{- $fullName := include "notification-template-publisher.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- $ingressApiIsStable := eq (include "notification-template-publisher.ingress.isStable" .) "true" -}}
{{- $ingressSupportsIngressClassName := eq (include "notification-template-publisher.ingress.supportsIngressClassName" .) "true" -}}
{{- $ingressSupportsPathType := eq (include "notification-template-publisher.ingress.supportsPathType" .) "true" -}}
{{- $ingressPathType := .Values.ingress.pathType -}}
kind: Ingress
apiVersion: {{ include "notification-template-publisher.ingress.apiVersion" . }}
metadata:
  name: {{ $fullName }}
  labels:
    {{- include "notification-template-publisher.labels" . | nindent 4 }}
  {{- with .Values.ingress.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  {{- if and $ingressSupportsIngressClassName .Values.ingress.ingressClassName }}
  ingressClassName: {{ .Values.ingress.ingressClassName }}
  {{- end }}
  {{- if .Values.ingress.tls }}
  tls:
    {{- range .Values.ingress.tls }}
    {{- if .Values.ingress.host }}
    - host: {{ .Values.ingress.host }}
    {{else}}
    - host: {{ $fullName }}-{{ .Release.Namespace}}.{{ .Values.ingress.dnsWildcard}}
    {{end}}
      secretName: {{ .secretName }}
    {{- end }}
  {{- end }}
  rules:
    {{- if .Values.ingress.host }}
    - host: {{ .Values.ingress.host }}
    {{else}}
    - host: {{ $fullName }}-{{ .Release.Namespace}}.{{ .Values.ingress.dnsWildcard}}
    {{end}}
      http:
        paths:
          - path: {{ .Values.ingress.path }}
            {{- if $ingressSupportsPathType }}
            pathType: {{ $ingressPathType }}
            {{- end }}
            backend:
              {{- if $ingressApiIsStable }}
              service:
                name: {{ $fullName }}
                port: 
                  number: {{ $svcPort }}
              {{- else }}
              serviceName: {{ $fullName }}
              servicePort: {{ $svcPort }}
              {{- end }}
  {{- end }}