{{- if .Values.ingress.enabled }}
{{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1/Ingress" }}
apiVersion: networking.k8s.io/v1
{{- else }}
apiVersion: networking.k8s.io/v1beta1
{{- end }}
kind: Ingress
metadata:
  name: {{ template "rancher.fullname" . }}
  labels:
{{ include "rancher.labels" . | indent 4 }}
  annotations:
{{- if .Values.ingress.configurationSnippet }}
    nginx.ingress.kubernetes.io/configuration-snippet: |
      {{- template "configurationSnippet" . }}
{{- end }}
{{- if eq .Values.tls "external" }}
    nginx.ingress.kubernetes.io/ssl-redirect: "false" # turn off ssl redirect for external.
{{- else }}
  {{- if ne .Values.ingress.tls.source "secret" }}
    {{- $certmanagerVer :=  split "." .Values.certmanager.version -}}
    {{- if or (.Capabilities.APIVersions.Has "certmanager.k8s.io/v1alpha1") (and (gt (len $certmanagerVer._0) 0) (eq (int $certmanagerVer._0) 0) (lt (int $certmanagerVer._1) 11)) }}
    certmanager.k8s.io/issuer: {{ template "rancher.fullname" . }}
    {{- else }}
{{- /*    cert-manager.io/issuer: {{ template "rancher.fullname" . }}*/}}
{{- /*    cert-manager.io/issuer-kind: Issuer*/}}
    cert-manager.io/issuer: "cm-cf"
    cert-manager.io/issuer-kind: ClusterIssuer
    {{- end }}
  {{- end }}
{{- end }}
{{- if .Values.ingress.includeDefaultExtraAnnotations }}
    nginx.ingress.kubernetes.io/proxy-connect-timeout: "30"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "1800"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "1800"
{{- end }}
{{- if .Values.ingress.extraAnnotations }}
{{ toYaml .Values.ingress.extraAnnotations | indent 4 }}
{{- end }}
spec:
  rules:
  - host: {{ .Values.hostname }}  # hostname to access rancher server
    http:
      paths:
      - backend:
          {{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1/Ingress" }}
          service:
            name: {{ template "rancher.fullname" . }}
            port:
              number: 80
          {{- else }}
          serviceName: {{ template "rancher.fullname" . }}
          servicePort: 80
          {{- end }}
        {{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1/Ingress" }}
        pathType: ImplementationSpecific
        {{- end }}
{{- if eq .Values.tls "ingress" }}
  tls:
  - hosts:
    - {{ .Values.hostname }}
    secretName: {{ .Values.ingress.tls.secretName }}
{{- end }}
{{- end }}
