{{- if .Values.deployKF.gateway.tls.enabled }}
apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
  name: {{ .Values.deployKF.gateway.httpsRedirectName | quote }}
  labels:
    helm.sh/chart: {{ include "deploykf-istio-gateway.labels.chart" . }}
    app.kubernetes.io/name: {{ include "deploykf-istio-gateway.labels.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
  selector:
    {{- toYaml .Values.deployKF.gateway.selectorLabels | nindent 4 }}
  servers:
    ################################################################################
    ## HTTP
    ################################################################################
    - hosts:
        ## this gateway only needs to select the `VirtualService/https-redirect`, even for the subdomains
        - "{{ .Release.Namespace }}/{{ .Values.deployKF.gateway.hostname }}"
        {{- if .Values.deployKF.argoWorkflows.enabled }}
        - "{{ .Release.Namespace }}/argo-server.{{ .Values.deployKF.gateway.hostname }}"
        {{- end }}
        {{- if .Values.deployKF.minio.enabled }}
        - "{{ .Release.Namespace }}/minio-api.{{ .Values.deployKF.gateway.hostname }}"
        - "{{ .Release.Namespace }}/minio-console.{{ .Values.deployKF.gateway.hostname }}"
        {{- end }}
      port:
        name: http
        number: {{ .Values.deployKF.gateway.ports.http | int }}
        protocol: HTTP
      tls:
        ## NOTE: our `VirtualService/https-redirect` handles HTTP to HTTPS redirects,
        ##       as this is more robust than `httpsRedirect` because it can redirect to non-standard HTTPS ports
        httpsRedirect: false
{{- end }}