{{- if .Values.master.ingress.enabled }}
{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: {{ .Values.master.ingress.apiVersion }}
{{- end }}
kind: Ingress
metadata:
  namespace: {{ template "jenkins.namespace" . }}
  labels:
    "app.kubernetes.io/name": '{{ template "jenkins.name" .}}'
    "helm.sh/chart": "{{ .Chart.Name }}-{{ .Chart.Version }}"
    "app.kubernetes.io/managed-by": "{{ .Release.Service }}"
    "app.kubernetes.io/instance": "{{ .Release.Name }}"
    "app.kubernetes.io/component": "{{ .Values.master.componentName }}"
{{- if .Values.master.ingress.labels }}
{{ toYaml .Values.master.ingress.labels | indent 4 }}
{{- end }}
{{- if .Values.master.ingress.annotations }}
  annotations:
{{ toYaml .Values.master.ingress.annotations | indent 4 }}
{{- end }}
  name: {{ template "jenkins.fullname" . }}
spec:
  rules:
  - http:
      paths:
{{- if len (.Values.master.ingress.paths) }}
{{ tpl (toYaml .Values.master.ingress.paths | indent 6) . }}
{{- else }}
      - backend:
          serviceName: {{ template "jenkins.fullname" . }}
          servicePort: {{ .Values.master.servicePort }}
{{- if .Values.master.ingress.path }}
        path: {{ .Values.master.ingress.path }}
{{- end -}}
{{- end -}}
{{- if .Values.master.ingress.hostName }}
    host: {{ .Values.master.ingress.hostName | quote }}
{{- end }}
{{- if .Values.master.ingress.resourceRootUrl }}
  - http:
      paths:
      - backend:
          serviceName: {{ template "jenkins.fullname" . }}
          servicePort: {{ .Values.master.servicePort }}
    host: {{ .Values.master.ingress.resourceRootUrl | quote }}
{{- end }}
{{- if .Values.master.ingress.tls }}
  tls:
{{ toYaml .Values.master.ingress.tls | indent 4 }}
{{- end -}}
{{- end }}
