{{- 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 }}
{{- end }}