diff --git a/charts/vela-core/templates/defwithtemplate/export-service.yaml b/charts/vela-core/templates/defwithtemplate/export-service.yaml new file mode 100644 index 000000000..495e4a2fb --- /dev/null +++ b/charts/vela-core/templates/defwithtemplate/export-service.yaml @@ -0,0 +1,79 @@ +# Code generated by KubeVela templates. DO NOT EDIT. Please edit the original cue file. +# Definition source cue file: vela-templates/definitions/internal/export-service.cue +apiVersion: core.oam.dev/v1beta1 +kind: WorkflowStepDefinition +metadata: + annotations: + definition.oam.dev/description: Export service to clusters specified by topology. + name: export-service + namespace: {{ include "systemDefinitionNamespace" . }} +spec: + schematic: + cue: + template: | + import ( + "vela/op" + ) + + meta: { + name: *context.name | string + namespace: *context.namespace | string + if parameter.name != _|_ { + name: parameter.name + } + if parameter.namespace != _|_ { + namespace: parameter.namespace + } + } + objects: [{ + apiVersion: "v1" + kind: "Service" + metadata: meta + spec: { + type: "ClusterIP" + ports: [{ + protocol: "TCP" + port: parameter.port + targetPort: parameter.targetPort + }] + } + }, { + apiVersion: "v1" + kind: "Endpoints" + metadata: meta + subsets: [{ + addresses: [{ip: parameter.ip}] + ports: [{port: parameter.targetPort}] + }] + }] @step(1) + getPlacements: op.#GetPlacementsFromTopologyPolicies & { + policies: *[] | [...string] + if parameter.topology != _|_ { + policies: [parameter.topology] + } + } @step(2) + apply: op.#Steps & { + for p in getPlacements.placements { + for o in objects { + "\(p.cluster)-\(o.kind)": op.#Apply & { + value: o + cluster: p.cluster + } + } + } + } @step(3) + parameter: { + // +usage=Specify the name of the export destination + name?: string + // +usage=Specify the namespace of the export destination + namespace?: string + // +usage=Specify the ip to be export + ip: string + // +usage=Specify the port to be used in service + port: int + // +usage=Specify the port to be export + targetPort: int + // +usage=Specify the topology to export + topology?: string + } + diff --git a/charts/vela-minimal/templates/defwithtemplate/export-service.yaml b/charts/vela-minimal/templates/defwithtemplate/export-service.yaml new file mode 100644 index 000000000..495e4a2fb --- /dev/null +++ b/charts/vela-minimal/templates/defwithtemplate/export-service.yaml @@ -0,0 +1,79 @@ +# Code generated by KubeVela templates. DO NOT EDIT. Please edit the original cue file. +# Definition source cue file: vela-templates/definitions/internal/export-service.cue +apiVersion: core.oam.dev/v1beta1 +kind: WorkflowStepDefinition +metadata: + annotations: + definition.oam.dev/description: Export service to clusters specified by topology. + name: export-service + namespace: {{ include "systemDefinitionNamespace" . }} +spec: + schematic: + cue: + template: | + import ( + "vela/op" + ) + + meta: { + name: *context.name | string + namespace: *context.namespace | string + if parameter.name != _|_ { + name: parameter.name + } + if parameter.namespace != _|_ { + namespace: parameter.namespace + } + } + objects: [{ + apiVersion: "v1" + kind: "Service" + metadata: meta + spec: { + type: "ClusterIP" + ports: [{ + protocol: "TCP" + port: parameter.port + targetPort: parameter.targetPort + }] + } + }, { + apiVersion: "v1" + kind: "Endpoints" + metadata: meta + subsets: [{ + addresses: [{ip: parameter.ip}] + ports: [{port: parameter.targetPort}] + }] + }] @step(1) + getPlacements: op.#GetPlacementsFromTopologyPolicies & { + policies: *[] | [...string] + if parameter.topology != _|_ { + policies: [parameter.topology] + } + } @step(2) + apply: op.#Steps & { + for p in getPlacements.placements { + for o in objects { + "\(p.cluster)-\(o.kind)": op.#Apply & { + value: o + cluster: p.cluster + } + } + } + } @step(3) + parameter: { + // +usage=Specify the name of the export destination + name?: string + // +usage=Specify the namespace of the export destination + namespace?: string + // +usage=Specify the ip to be export + ip: string + // +usage=Specify the port to be used in service + port: int + // +usage=Specify the port to be export + targetPort: int + // +usage=Specify the topology to export + topology?: string + } + diff --git a/references/docgen/def-doc/workflowstep/export-service.eg.md b/references/docgen/def-doc/workflowstep/export-service.eg.md new file mode 100644 index 000000000..09baaffba --- /dev/null +++ b/references/docgen/def-doc/workflowstep/export-service.eg.md @@ -0,0 +1,53 @@ +```yaml +apiVersion: core.oam.dev/v1beta1 +kind: Application +metadata: + name: app-collect-service-endpoint-and-export +spec: + components: + - type: webservice + name: busybox + properties: + image: busybox + imagePullPolicy: IfNotPresent + cmd: + - sleep + - '1000000' + traits: + - type: expose + properties: + port: [8080] + type: LoadBalancer + policies: + - type: topology + name: local + properties: + clusters: ["local"] + - type: topology + name: worker + properties: + clusters: ["cluster-worker"] + workflow: + steps: + - type: deploy + name: deploy + properties: + policies: ["local"] + - type: collect-service-endpoints + name: collect-service-endpoints + outputs: + - name: host + valueFrom: value.endpoint.host + - name: port + valueFrom: value.endpoint.port + - type: export-service + name: export-service + properties: + name: busybox + topology: worker + inputs: + - from: host + parameterKey: ip + - from: port + parameterKey: port +``` \ No newline at end of file diff --git a/vela-templates/definitions/internal/workflowstep/export-service.cue b/vela-templates/definitions/internal/workflowstep/export-service.cue new file mode 100644 index 000000000..ac92284a6 --- /dev/null +++ b/vela-templates/definitions/internal/workflowstep/export-service.cue @@ -0,0 +1,76 @@ +import ( + "vela/op" +) + +"export-service": { + type: "workflow-step" + annotations: {} + labels: {} + description: "Export service to clusters specified by topology." +} +template: { + meta: { + name: *context.name | string + namespace: *context.namespace | string + if parameter.name != _|_ { + name: parameter.name + } + if parameter.namespace != _|_ { + namespace: parameter.namespace + } + } + objects: [{ + apiVersion: "v1" + kind: "Service" + metadata: meta + spec: { + type: "ClusterIP" + ports: [{ + protocol: "TCP" + port: parameter.port + targetPort: parameter.targetPort + }] + } + }, { + apiVersion: "v1" + kind: "Endpoints" + metadata: meta + subsets: [{ + addresses: [{ip: parameter.ip}] + ports: [{port: parameter.targetPort}] + }] + }] @step(1) + + getPlacements: op.#GetPlacementsFromTopologyPolicies & { + policies: *[] | [...string] + if parameter.topology != _|_ { + policies: [parameter.topology] + } + } @step(2) + + apply: op.#Steps & { + for p in getPlacements.placements { + for o in objects { + "\(p.cluster)-\(o.kind)": op.#Apply & { + value: o + cluster: p.cluster + } + } + } + } @step(3) + + parameter: { + // +usage=Specify the name of the export destination + name?: string + // +usage=Specify the namespace of the export destination + namespace?: string + // +usage=Specify the ip to be export + ip: string + // +usage=Specify the port to be used in service + port: int + // +usage=Specify the port to be export + targetPort: int + // +usage=Specify the topology to export + topology?: string + } +}