diff --git a/charts/vela-core/templates/defwithtemplate/webservice.yaml b/charts/vela-core/templates/defwithtemplate/webservice.yaml index 3f7af2356..7012ea8e7 100644 --- a/charts/vela-core/templates/defwithtemplate/webservice.yaml +++ b/charts/vela-core/templates/defwithtemplate/webservice.yaml @@ -11,6 +11,10 @@ spec: schematic: cue: template: | + import ( + "strconv" + ) + mountsArray: { pvc: *[ for v in parameter.volumeMounts.pvc { @@ -152,6 +156,12 @@ spec: { containerPort: v.port protocol: v.protocol + if v.name != _|_ { + name: v.name + } + if v.name == _|_ { + name: "port-" + strconv.FormatInt(v.port, 10) + } }}] } @@ -262,6 +272,12 @@ spec: for v in parameter.ports if v.expose == true { port: v.port targetPort: v.port + if v.name != _|_ { + name: v.name + } + if v.name == _|_ { + name: "port-" + strconv.FormatInt(v.port, 10) + } }, ] outputs: { @@ -304,6 +320,8 @@ spec: ports?: [...{ // +usage=Number of port to expose on the pod's IP address port: int + // +usage=Name of the port + name?: string // +usage=Protocol for port. Must be UDP, TCP, or SCTP protocol: *"TCP" | "UDP" | "SCTP" // +usage=Specify if the port should be exposed diff --git a/charts/vela-minimal/templates/defwithtemplate/webservice.yaml b/charts/vela-minimal/templates/defwithtemplate/webservice.yaml index 3f7af2356..7012ea8e7 100644 --- a/charts/vela-minimal/templates/defwithtemplate/webservice.yaml +++ b/charts/vela-minimal/templates/defwithtemplate/webservice.yaml @@ -11,6 +11,10 @@ spec: schematic: cue: template: | + import ( + "strconv" + ) + mountsArray: { pvc: *[ for v in parameter.volumeMounts.pvc { @@ -152,6 +156,12 @@ spec: { containerPort: v.port protocol: v.protocol + if v.name != _|_ { + name: v.name + } + if v.name == _|_ { + name: "port-" + strconv.FormatInt(v.port, 10) + } }}] } @@ -262,6 +272,12 @@ spec: for v in parameter.ports if v.expose == true { port: v.port targetPort: v.port + if v.name != _|_ { + name: v.name + } + if v.name == _|_ { + name: "port-" + strconv.FormatInt(v.port, 10) + } }, ] outputs: { @@ -304,6 +320,8 @@ spec: ports?: [...{ // +usage=Number of port to expose on the pod's IP address port: int + // +usage=Name of the port + name?: string // +usage=Protocol for port. Must be UDP, TCP, or SCTP protocol: *"TCP" | "UDP" | "SCTP" // +usage=Specify if the port should be exposed diff --git a/docs/examples/core-definitions/component/webservice.yaml b/docs/examples/core-definitions/component/webservice.yaml index 36d3588d5..7d081781a 100644 --- a/docs/examples/core-definitions/component/webservice.yaml +++ b/docs/examples/core-definitions/component/webservice.yaml @@ -14,8 +14,12 @@ spec: ports: - port: 8000 - port: 8001 + name: exposeport1 protocol: UDP - expose: true + expose: true + - port: 8002 + protocol: UDP + expose: true volumeMounts: pvc: - name: my-mount diff --git a/vela-templates/definitions/internal/component/webservice.cue b/vela-templates/definitions/internal/component/webservice.cue index 19c7e15da..20a84a501 100644 --- a/vela-templates/definitions/internal/component/webservice.cue +++ b/vela-templates/definitions/internal/component/webservice.cue @@ -1,3 +1,7 @@ +import ( + "strconv" +) + webservice: { type: "component" annotations: {} @@ -186,6 +190,12 @@ template: { { containerPort: v.port protocol: v.protocol + if v.name != _|_ { + name: v.name + } + if v.name == _|_ { + name: "port-" + strconv.FormatInt(v.port, 10) + } }}] } @@ -297,6 +307,12 @@ template: { for v in parameter.ports if v.expose == true { port: v.port targetPort: v.port + if v.name != _|_ { + name: v.name + } + if v.name == _|_ { + name: "port-" + strconv.FormatInt(v.port, 10) + } }, ] @@ -341,6 +357,8 @@ template: { ports?: [...{ // +usage=Number of port to expose on the pod's IP address port: int + // +usage=Name of the port + name?: string // +usage=Protocol for port. Must be UDP, TCP, or SCTP protocol: *"TCP" | "UDP" | "SCTP" // +usage=Specify if the port should be exposed