# Code generated by KubeVela templates. DO NOT EDIT. Please edit the original cue file.
# Definition source cue file: vela-templates/definitions/internal/volumes.cue
apiVersion: core.oam.dev/v1beta1
kind: TraitDefinition
metadata:
  annotations:
    definition.oam.dev/description: use istio to manage in-cluster traffic
  name: istio-gateway
  namespace: vela-system
spec:
  appliesToWorkloads:
    - deployments.apps
  podDisruptive: true
  schematic:
    cue:
      template: |

        outputs: gateway: {
            apiVersion: "networking.istio.io/v1alpha3"
            kind: "Gateway"
            metadata: {
                name:      context.name
                namespace: context.namespace
            }
            spec: {
              selector: {
                istio: parameter.gateway
              }
              servers: [{
                 hosts: parameter.hosts
                 port: {
                      name: "http"
                      number: 80
                      protocol: "HTTP"
                 }
              }]
            }
        }

        outputs: virtualService: {
            apiVersion: "networking.istio.io/v1alpha3"
            kind: "VirtualService"
            metadata: {
                 name:      context.name
                 namespace: context.namespace
            }
            spec: {
               gateways: [context.name]
               hosts: parameter.hosts
               http:[{
               match: [ for i, u in parameter.match { uri: u} ]
               route: [{destination: {
                   host: context.name
                   port: number: parameter.port
               }}]
               }]
            }
        }

        parameter: {
            hosts: [string]
            gateway: *"ingressgateway"|string
            match: [...#uri]
            port: int
        }

        #uri: {
           exact?: string
           prefix?: string
        }