{{- if .Values.controller.secondaryingress.enabled }}
{{- $kubeTargetVersion := default .Capabilities.KubeVersion.GitVersion .Values.kubeTargetVersionOverride }}
{{- $serviceName := include "jenkins.fullname" . -}}
{{- $servicePort := .Values.controller.servicePort -}}
{{- if semverCompare ">=1.19-0" $kubeTargetVersion -}}
apiVersion: networking.k8s.io/v1
{{- else if semverCompare ">=1.14-0" $kubeTargetVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: {{ .Values.controller.secondaryingress.apiVersion }}
{{- end }}
kind: Ingress
metadata:
  namespace: {{ template "jenkins.namespace" . }}
  labels:
    "app.kubernetes.io/name": '{{ template "jenkins.name" .}}'
    {{- if .Values.renderHelmLabels }}
    "helm.sh/chart": "{{ template "jenkins.label" .}}"
    {{- end }}
    "app.kubernetes.io/managed-by": "{{ .Release.Service }}"
    "app.kubernetes.io/instance": "{{ .Release.Name }}"
    "app.kubernetes.io/component": "{{ .Values.controller.componentName }}"
    {{- if .Values.controller.secondaryingress.labels -}}
    {{ toYaml .Values.controller.secondaryingress.labels | nindent 4 }}
    {{- end }}
  {{- if .Values.controller.secondaryingress.annotations }}
  annotations: {{ toYaml .Values.controller.secondaryingress.annotations | nindent 4 }}
  {{- end }}
  name: {{ template "jenkins.fullname" . }}-secondary
spec:
{{- if .Values.controller.secondaryingress.ingressClassName }}
  ingressClassName: {{ .Values.controller.secondaryingress.ingressClassName | quote }}
{{- end }}
  rules:
    - host: {{ .Values.controller.secondaryingress.hostName }}
      http:
        paths:
        {{- range .Values.controller.secondaryingress.paths }}
          - path: {{ . | quote }}
            backend:
{{ if semverCompare ">=1.19-0" $kubeTargetVersion }}
              service:
                name: {{ $serviceName }}
                port:
                  number: {{ $servicePort }}
            pathType: ImplementationSpecific
{{ else }}
              serviceName: {{ $serviceName }}
              servicePort: {{ $servicePort }}
{{ end }}
        {{- end}}
{{- if .Values.controller.secondaryingress.tls }}
  tls:
{{ toYaml .Values.controller.secondaryingress.tls | indent 4 }}
{{- end -}}
{{- end }}
