{{- if and .Values.notificationController.create .Values.notificationController.webhookReceiver.ingress.create }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  labels:
    app.kubernetes.io/instance: {{ .Release.Namespace | quote }}
    app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
    app.kubernetes.io/version: {{ .Chart.AppVersion | quote  }}
    app.kubernetes.io/part-of: flux
    helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
    control-plane: controller
    {{- with .Values.notificationController.webhookReceiver.ingress.labels }}{{ toYaml . | nindent 4 }}{{ end }}
  {{- with .Values.notificationController.webhookReceiver.ingress.annotations }}
  annotations:
    {{- range $key, $value := . }}
    {{ $key }}: {{ tpl $value $ | quote }}
    {{- end }}
  {{- end }}
  name: webhook-receiver
spec:
  {{- if .Values.notificationController.webhookReceiver.ingress.ingressClassName }}
  ingressClassName: {{ .Values.notificationController.webhookReceiver.ingress.ingressClassName }}
  {{- end -}}
  {{- if .Values.notificationController.webhookReceiver.ingress.tls }}
  tls:
    {{- range .Values.notificationController.webhookReceiver.ingress.tls }}
    - hosts:
        {{- range .hosts }}
        - {{ . | quote }}
        {{- end }}
      secretName: {{ .secretName }}
    {{- end }}
  {{- end }}
  rules:
    {{- range .Values.notificationController.webhookReceiver.ingress.hosts }}
    - host: {{ .host | quote }}
      http:
        paths:
          {{- range .paths }}
          - path: {{ .path }}
            pathType: {{ .pathType }}
            backend:
              service:
                name: webhook-receiver
                port:
                  number: 80
          {{- end }}
    {{- end }}
{{- end }}
