{{- if and .Values.notary.enabled (eq .Values.exposureType "ingress") }}
apiVersion: {{ template "common.capabilities.ingress.apiVersion" . }}
kind: Ingress
metadata:
  name: {{ include "harbor.ingress-notary" . }}
  namespace: {{ .Release.Namespace | quote }}
  labels: {{- include "common.labels.standard" . | nindent 4 }}
    {{- if .Values.commonLabels }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
  annotations:
  {{- if .Values.ingress.notary.annotations }}
    {{- include "common.tplvalues.render" (dict "value" .Values.ingress.notary.annotations "context" .) | nindent 4 }}
  {{- end }}
  {{- if .Values.commonAnnotations }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" .) | nindent 4 }}
  {{- end }}
spec:
  {{- if eq .Values.ingress.notary.controller "ncp" }}
  backend: {{- include "common.ingress.backend" (dict "serviceName" (include "harbor.notary-server" .) "servicePort" "notary-server" "context" $) | nindent 4 }}
  {{- end }}
  {{- if and .Values.ingress.notary.ingressClassName (eq "true" (include "common.ingress.supportsIngressClassname" .)) }}
  ingressClassName: {{ .Values.ingress.notary.ingressClassName | quote }}
  {{- end }}
  rules:
    {{- if .Values.ingress.notary.hostname }}
    - host: {{ include "common.tplvalues.render" ( dict "value" .Values.ingress.notary.hostname "context" $ ) }}
      http:
        paths:
          {{- if .Values.ingress.notary.extraPaths }}
          {{- toYaml .Values.ingress.notary.extraPaths | nindent 10 }}
          {{- end }}
          {{- if eq .Values.ingress.notary.controller "ncp" }}
          - path: /.*
          {{- else }}
          - path: /
          {{- end }}
            {{- if eq "true" (include "common.ingress.supportsPathType" .) }}
            pathType: {{ .Values.ingress.notary.pathType }}
            {{- end }}
            backend: {{- include "common.ingress.backend" (dict "serviceName" (include "harbor.notary-server" .) "servicePort" "notary-server" "context" $) | nindent 14 }}
    {{- end }}
    {{- range .Values.ingress.notary.extraHosts }}
    - host: {{ include "common.tplvalues.render" ( dict "value" .name "context" $ ) }}
      http:
        paths:
          - path: {{ default "/" .path }}
            {{- if eq "true" (include "common.ingress.supportsPathType" $) }}
            pathType: {{ default "ImplementationSpecific" .pathType }}
            {{- end }}
            backend: {{- include "common.ingress.backend" (dict "serviceName" (include "harbor.notary-server" $) "servicePort" "notary-server" "context" $) | nindent 14 }}
    {{- end }}
  {{- if or (and .Values.ingress.notary.tls (or (include "common.ingress.certManagerRequest" ( dict "annotations" .Values.ingress.notary.annotations )) .Values.ingress.notary.selfSigned)) .Values.ingress.notary.extraTls }}
  tls:
    {{- if and .Values.ingress.notary.tls (or (include "common.ingress.certManagerRequest" ( dict "annotations" .Values.ingress.notary.annotations )) .Values.ingress.notary.selfSigned) }}
    - hosts:
        - {{ .Values.ingress.notary.hostname | quote }}
      secretName: {{ printf "%s-tls" .Values.ingress.notary.hostname }}
    {{- end }}
    {{- if .Values.ingress.notary.extraTls }}
    {{- include "common.tplvalues.render" (dict "value" .Values.ingress.notary.extraTls "context" $) | nindent 4 }}
    {{- end }}
  {{- end }}
{{- end }}
