{{- if and .Values.gitea.enabled .Values.gitea.istio.enabled }}
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: gitea
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "kubezero-lib.labels" $ | nindent 4 }}
spec:
  gateways:
  - {{ .Values.gitea.istio.gateway }}
  hosts:
  - {{ .Values.gitea.istio.url }}
  http:
  {{- if .Values.gitea.istio.authProvider }}
  # https://github.com/go-gitea/gitea/issues/13606
  - match:
    - uri:
        regex: ^/user/login.*
    redirect:
      uri: /user/oauth2/{{ .Values.gitea.istio.authProvider }}
      redirectCode: 302
  {{- end }}
  - route:
    - destination:
        host: gitea-http
  tcp:
  - match:
    - port: 22
    route:
    - destination:
        host: gitea-ssh
{{- end }}