# 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 traffic
  name: canary-traffic
  namespace: vela-system
spec:
  appliesToWorkloads:
    - deployments.apps
  podDisruptive: true
  schematic:
    cue:
      template: |
        outputs: service: {
        		apiVersion: "v1"
        		kind:       "Service"
        		metadata: name: context.name
        		spec: {
        			selector: "app.oam.dev/component": context.name
        			ports: [
        				for p in parameter.port {
        					port:       p
        					targetPort: p
        				},
        			]
        			type: "ClusterIP"
        		}
        }

        outputs: virtualService: {
            apiVersion: "networking.istio.io/v1alpha3"
            kind: "VirtualService"
            metadata: {
                name:      context.name
                namespace: context.namespace
            }
            spec: {
               hosts: [context.name]
               http: [{route: [
               {destination: {
                  host: context.name
                  port: {number: parameter.port[0]}
               }}]}]
            }
        }

        outputs: destinationRule: {
               apiVersion: "networking.istio.io/v1alpha3"
               kind: "DestinationRule"
               metadata: {
                   name:      context.name
                   namespace: context.namespace
               }
               spec: {
                  host: context.name
                  subsets: [{
                     name: context.revision
                     labels: {"app.oam.dev/revision": context.revision}
                  }]
               }
        }

        parameter: {
           port: [int]
        }