github.com/oam-dev/kubevela@v1.9.11/charts/vela-core/templates/defwithtemplate/expose.yaml (about)

     1  # Code generated by KubeVela templates. DO NOT EDIT. Please edit the original cue file.
     2  # Definition source cue file: vela-templates/definitions/internal/expose.cue
     3  apiVersion: core.oam.dev/v1beta1
     4  kind: TraitDefinition
     5  metadata:
     6    annotations:
     7      definition.oam.dev/description: Expose port to enable web traffic for your component.
     8    name: expose
     9    namespace: {{ include "systemDefinitionNamespace" . }}
    10  spec:
    11    appliesToWorkloads:
    12      - deployments.apps
    13      - statefulsets.apps
    14    podDisruptive: false
    15    schematic:
    16      cue:
    17        template: |
    18          import (
    19          	"strconv"
    20          	"strings"
    21          )
    22  
    23          outputs: service: {
    24          	apiVersion: "v1"
    25          	kind:       "Service"
    26          	metadata: name:        context.name
    27          	metadata: annotations: parameter.annotations
    28          	spec: {
    29          		if parameter["matchLabels"] == _|_ {
    30          			selector: "app.oam.dev/component": context.name
    31          		}
    32          		if parameter["matchLabels"] != _|_ {
    33          			selector: parameter["matchLabels"]
    34          		}
    35  
    36          		// compatible with the old way
    37          		if parameter["port"] != _|_ if parameter["ports"] == _|_ {
    38          			ports: [
    39          				for p in parameter.port {
    40          					name:       "port-" + strconv.FormatInt(p, 10)
    41          					port:       p
    42          					targetPort: p
    43          				},
    44          			]
    45          		}
    46          		if parameter["ports"] != _|_ {
    47          			ports: [ for v in parameter.ports {
    48          				port:       v.port
    49          				targetPort: v.port
    50          				if v.name != _|_ {
    51          					name: v.name
    52          				}
    53          				if v.name == _|_ {
    54          					_name: "port-" + strconv.FormatInt(v.port, 10)
    55          					name:  *_name | string
    56          					if v.protocol != "TCP" {
    57          						name: _name + "-" + strings.ToLower(v.protocol)
    58          					}
    59          				}
    60          				if v.nodePort != _|_ if parameter.type == "NodePort" {
    61          					nodePort: v.nodePort
    62          				}
    63          				if v.protocol != _|_ {
    64          					protocol: v.protocol
    65          				}
    66          			},
    67          			]
    68          		}
    69          		type: parameter.type
    70          	}
    71          }
    72          parameter: {
    73          	// +usage=Deprecated, the old way to specify the exposion ports
    74          	port?: [...int]
    75  
    76          	// +usage=Specify portsyou want customer traffic sent to
    77          	ports?: [...{
    78          		// +usage=Number of port to expose on the pod's IP address
    79          		port: int
    80          		// +usage=Name of the port
    81          		name?: string
    82          		// +usage=Protocol for port. Must be UDP, TCP, or SCTP
    83          		protocol: *"TCP" | "UDP" | "SCTP"
    84          		// +usage=exposed node port. Only Valid when exposeType is NodePort
    85          		nodePort?: int
    86          	}]
    87  
    88          	// +usage=Specify the annotations of the exposed service
    89          	annotations: [string]: string
    90  
    91          	matchLabels?: [string]: string
    92  
    93          	// +usage=Specify what kind of Service you want. options: "ClusterIP","NodePort","LoadBalancer","ExternalName"
    94          	type: *"ClusterIP" | "NodePort" | "LoadBalancer" | "ExternalName"
    95          }
    96    stage: PostDispatch
    97    status:
    98      customStatus: |-
    99        message: *"" | string
   100        service: context.outputs.service
   101        if service.spec.type == "ClusterIP" {
   102        	message: "ClusterIP: \(service.spec.clusterIP)"
   103        }
   104        if service.spec.type == "LoadBalancer" {
   105        	status: service.status
   106        	isHealth: *false | bool
   107        	if status != _|_ if status.loadBalancer != _|_ if status.loadBalancer.ingress != _|_ if len(status.loadBalancer.ingress) > 0 if status.loadBalancer.ingress[0].ip != _|_ {
   108        		isHealth: true
   109        	}
   110        	if !isHealth {
   111        		message: "ExternalIP: Pending"
   112        	}
   113        	if isHealth {
   114        		message: "ExternalIP: \(status.loadBalancer.ingress[0].ip)"
   115        	}
   116        }
   117      healthPolicy: |-
   118        service: context.outputs.service
   119        if service.spec.type == "LoadBalancer" {
   120        	status: service.status
   121        	isHealth: *false | bool
   122        	if status != _|_ if status.loadBalancer != _|_ if status.loadBalancer.ingress != _|_ if len(status.loadBalancer.ingress) > 0 if status.loadBalancer.ingress[0].ip != _|_ {
   123        		isHealth: true
   124        	}
   125        }
   126        if service.spec.type != "LoadBalancer" {
   127        	isHealth: true
   128        }
   129