{{- if and .Values.jenkins.enabled .Values.jenkins.istio.enabled }}
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: {{ template "kubezero-lib.fullname" (merge (dict "subchart" "jenkins") .) }}
  namespace: {{ template "jenkins.namespace" . }}
spec:
  hosts:
  - {{ .Values.jenkins.istio.url }}
  gateways:
  - {{ .Values.jenkins.istio.gateway }}
  http:
  - route:
    - destination:
        host: {{ template "kubezero-lib.fullname" (merge (dict "subchart" "jenkins") .) }}
        port:
          number: 8080

{{- if .Values.jenkins.istio.webhook.enabled }}
---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: {{ template "kubezero-lib.fullname" (merge (dict "subchart" "jenkins") .) }}-webhook
  namespace: {{ template "jenkins.namespace" . }}
spec:
  hosts:
  - {{ .Values.jenkins.istio.webhook.url }}
  gateways:
  - {{ .Values.jenkins.istio.webhook.gateway }}
  http:
  - route:
    - destination:
        host: {{ template "kubezero-lib.fullname" (merge (dict "subchart" "jenkins") .) }}
        port:
          number: 8080
    match:
    - uri:
        exact: "/bitbucket-scmsource-hook/notify"
      method:
        exact: "POST"
    - uri:
        exact: "/github-webhook/"
      method:
        exact: "POST"
{{- end }}
{{- if .Values.jenkins.istio.agent.enabled }}
---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: {{ template "kubezero-lib.fullname" (merge (dict "subchart" "jenkins") .) }}-agent
  namespace: {{ template "jenkins.namespace" . }}
spec:
  hosts:
  - {{ .Values.jenkins.istio.agent.url }}
  gateways:
  - {{ .Values.jenkins.istio.agent.gateway }}
  tcp:
    - match:
      - port: 50000
      route:
      - destination:
          host: {{ template "kubezero-lib.fullname" (merge (dict "subchart" "jenkins") .) }}-agent
          port:
            number: 50000
{{- end }}
{{- end }}
