
{{- if .Values.coder.ingress.enable }}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: coder
  labels:
    {{- include "coder.labels" . | nindent 4 }}
  annotations:
    {{- toYaml .Values.coder.ingress.annotations | nindent 4 }}
spec:
  {{- if .Values.coder.ingress.className }}
  {{/* If this is set to an empty string it fails validation on K8s */}}
  ingressClassName: {{ .Values.coder.ingress.className | quote }}
  {{- end }}

  rules:
    - host: {{ .Values.coder.ingress.host | quote }}
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: coder
                port:
                  name: "http"

    {{- if .Values.coder.ingress.wildcardHost }}
    - host: {{ include "coder.ingressWildcardHost" . | quote }}
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: coder
                port:
                  name: "http"
    {{- end }}

  {{- if .Values.coder.ingress.tls.enable }}
  tls:
    - hosts:
        - {{ .Values.coder.ingress.host | quote }}
      secretName: {{ .Values.coder.ingress.tls.secretName | quote}}
    {{- if .Values.coder.ingress.tls.wildcardSecretName }}
    - hosts:
        - {{ include "coder.ingressWildcardHost" . | quote }}
      secretName: {{ .Values.coder.ingress.tls.wildcardSecretName | quote}}
    {{- end }}
  {{- end }}
{{- end }}
