github.com/oam-dev/kubevela@v1.9.11/vela-templates/definitions/internal/workflowstep/collect-service-endpoints.cue (about) 1 import ( 2 "vela/op" 3 "vela/ql" 4 "strconv" 5 ) 6 7 "collect-service-endpoints": { 8 type: "workflow-step" 9 annotations: {} 10 labels: {} 11 annotations: { 12 "category": "Application Delivery" 13 } 14 description: "Collect service endpoints for the application." 15 } 16 template: { 17 collect: ql.#CollectServiceEndpoints & { 18 app: { 19 name: *context.name | string 20 namespace: *context.namespace | string 21 if parameter.name != _|_ { 22 name: parameter.name 23 } 24 if parameter.namespace != _|_ { 25 namespace: parameter.namespace 26 } 27 filter: { 28 if parameter.components != _|_ { 29 components: parameter.components 30 } 31 } 32 } 33 } @step(1) 34 35 outputs: { 36 eps_port_name_filtered: *[] | [...] 37 if parameter.portName == _|_ { 38 eps_port_name_filtered: collect.list 39 } 40 if parameter.portName != _|_ { 41 eps_port_name_filtered: [ for ep in collect.list if parameter.portName == ep.endpoint.portName {ep}] 42 } 43 44 eps_port_filtered: *[] | [...] 45 if parameter.port == _|_ { 46 eps_port_filtered: eps_port_name_filtered 47 } 48 if parameter.port != _|_ { 49 eps_port_filtered: [ for ep in eps_port_name_filtered if parameter.port == ep.endpoint.port {ep}] 50 } 51 eps: eps_port_filtered 52 endpoints: *[] | [...] 53 if parameter.outer != _|_ { 54 tmps: [ for ep in eps { 55 ep 56 if ep.endpoint.inner == _|_ { 57 outer: true 58 } 59 if ep.endpoint.inner != _|_ { 60 outer: !ep.endpoint.inner 61 } 62 }] 63 endpoints: [ for ep in tmps if (!parameter.outer || ep.outer) {ep}] 64 } 65 if parameter.outer == _|_ { 66 endpoints: eps_port_filtered 67 } 68 } 69 70 wait: op.#ConditionalWait & { 71 continue: len(outputs.endpoints) > 0 72 } @step(2) 73 74 value: { 75 if len(outputs.endpoints) > 0 { 76 endpoint: outputs.endpoints[0].endpoint 77 _portStr: strconv.FormatInt(endpoint.port, 10) 78 url: "\(parameter.protocal)://\(endpoint.host):\(_portStr)" 79 } 80 } 81 82 parameter: { 83 // +usage=Specify the name of the application 84 name?: string 85 // +usage=Specify the namespace of the application 86 namespace?: string 87 // +usage=Filter the component of the endpoints 88 components?: [...string] 89 // +usage=Filter the port of the endpoints 90 port?: int 91 // +usage=Filter the port name of the endpoints 92 portName?: string 93 // +usage=Filter the endpoint that are only outer 94 outer?: bool 95 // +usage=The protocal of endpoint url 96 protocal: *"http" | "https" 97 } 98 }