# Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

{{- $ingressName := (.Values.cluster).svIngressName | default (.Values.cluster).svNamespace }}
{{- if .Values.withSvIngress }}
  {{- if .Values.ingress.sv }}
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: sv-sv-{{ (.Values.cluster).svNamespace }}
  namespace: {{ .Release.Namespace }}
spec:
  hosts:
    - "sv.{{ $ingressName }}.{{ (.Values.cluster).hostname }}"
  gateways:
    - cluster-ingress/cn-http-gateway
  http:
    - match:
        - port: 443
          uri:
            prefix: "/api/sv/"
      route:
        - destination:
            port:
              number: 5014
            host: sv-app.{{ (.Values.cluster).svNamespace }}.svc.cluster.local
    - match:
        - port: 443
      route:
        - destination:
            port:
              number: 80
            host: sv-web-ui.{{ (.Values.cluster).svNamespace }}.svc.cluster.local
---
  {{- end }}
  {{- if .Values.ingress.scan }}
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: scan-sv-{{ (.Values.cluster).svNamespace }}
  namespace: {{ .Release.Namespace }}
spec:
  hosts:
    - "scan.{{ $ingressName }}.{{ (.Values.cluster).hostname }}"
  gateways:
    - cluster-ingress/cn-http-gateway
  http:
    - match:
        - port: 443
          uri:
            prefix: "/api/scan/"
        - port: 443
          uri:
            prefix: "/registry/"
      route:
        - destination:
            port:
              number: 5012
            host: scan-app.{{ (.Values.cluster).svNamespace }}.svc.cluster.local
    - match:
        - port: 443
      route:
        - destination:
            port:
              number: 80
            host: scan-web-ui.{{ (.Values.cluster).svNamespace }}.svc.cluster.local
  {{- end }}
{{- end }}
