From afd363b896e877cba530ec7e23c63ebbb74f5980 Mon Sep 17 00:00:00 2001 From: Somefive Date: Wed, 9 Nov 2022 13:14:27 +0800 Subject: [PATCH] Feat: support webservice containing duplicate port with different protocol (#5034) Signed-off-by: Somefive Signed-off-by: Somefive --- .../templates/defwithtemplate/webservice.yaml | 16 ++++++++++++++-- .../templates/defwithtemplate/webservice.yaml | 16 ++++++++++++++-- .../internal/component/webservice.cue | 16 ++++++++++++++-- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/charts/vela-core/templates/defwithtemplate/webservice.yaml b/charts/vela-core/templates/defwithtemplate/webservice.yaml index 266c0667e..229ce5fa7 100644 --- a/charts/vela-core/templates/defwithtemplate/webservice.yaml +++ b/charts/vela-core/templates/defwithtemplate/webservice.yaml @@ -13,6 +13,7 @@ spec: template: | import ( "strconv" + "strings" ) mountsArray: [ @@ -167,7 +168,11 @@ spec: name: v.name } if v.name == _|_ { - name: "port-" + strconv.FormatInt(v.port, 10) + _name: "port-" + strconv.FormatInt(v.port, 10) + name: *_name | string + if v.protocol != "TCP" { + name: _name + "-" + strings.ToLower(v.protocol) + } } }}] } @@ -283,11 +288,18 @@ spec: name: v.name } if v.name == _|_ { - name: "port-" + strconv.FormatInt(v.port, 10) + _name: "port-" + strconv.FormatInt(v.port, 10) + name: *_name | string + if v.protocol != "TCP" { + name: _name + "-" + strings.ToLower(v.protocol) + } } if v.nodePort != _|_ && parameter.exposeType == "NodePort" { nodePort: v.nodePort } + if v.protocol != _|_ { + protocol: v.protocol + } }, ] outputs: { diff --git a/charts/vela-minimal/templates/defwithtemplate/webservice.yaml b/charts/vela-minimal/templates/defwithtemplate/webservice.yaml index 266c0667e..229ce5fa7 100644 --- a/charts/vela-minimal/templates/defwithtemplate/webservice.yaml +++ b/charts/vela-minimal/templates/defwithtemplate/webservice.yaml @@ -13,6 +13,7 @@ spec: template: | import ( "strconv" + "strings" ) mountsArray: [ @@ -167,7 +168,11 @@ spec: name: v.name } if v.name == _|_ { - name: "port-" + strconv.FormatInt(v.port, 10) + _name: "port-" + strconv.FormatInt(v.port, 10) + name: *_name | string + if v.protocol != "TCP" { + name: _name + "-" + strings.ToLower(v.protocol) + } } }}] } @@ -283,11 +288,18 @@ spec: name: v.name } if v.name == _|_ { - name: "port-" + strconv.FormatInt(v.port, 10) + _name: "port-" + strconv.FormatInt(v.port, 10) + name: *_name | string + if v.protocol != "TCP" { + name: _name + "-" + strings.ToLower(v.protocol) + } } if v.nodePort != _|_ && parameter.exposeType == "NodePort" { nodePort: v.nodePort } + if v.protocol != _|_ { + protocol: v.protocol + } }, ] outputs: { diff --git a/vela-templates/definitions/internal/component/webservice.cue b/vela-templates/definitions/internal/component/webservice.cue index db310ff90..3fe5f8bdc 100644 --- a/vela-templates/definitions/internal/component/webservice.cue +++ b/vela-templates/definitions/internal/component/webservice.cue @@ -1,5 +1,6 @@ import ( "strconv" + "strings" ) webservice: { @@ -211,7 +212,11 @@ template: { name: v.name } if v.name == _|_ { - name: "port-" + strconv.FormatInt(v.port, 10) + _name: "port-" + strconv.FormatInt(v.port, 10) + name: *_name | string + if v.protocol != "TCP" { + name: _name + "-" + strings.ToLower(v.protocol) + } } }}] } @@ -328,11 +333,18 @@ template: { name: v.name } if v.name == _|_ { - name: "port-" + strconv.FormatInt(v.port, 10) + _name: "port-" + strconv.FormatInt(v.port, 10) + name: *_name | string + if v.protocol != "TCP" { + name: _name + "-" + strings.ToLower(v.protocol) + } } if v.nodePort != _|_ && parameter.exposeType == "NodePort" { nodePort: v.nodePort } + if v.protocol != _|_ { + protocol: v.protocol + } }, ]