feat(k8s): Add a port name to service definition (#2933)

It should cover this issue:  https://github.com/woodpecker-ci/woodpecker/issues/2931

To sum up, when several ports need to be specified, they must be named
This commit is contained in:
Nikolai Rodionov 2023-12-19 02:38:18 +01:00 committed by GitHub
parent bbafe3c386
commit f7f78b2a3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 0 deletions

View file

@ -15,6 +15,8 @@
package kubernetes
import (
"fmt"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
@ -24,6 +26,7 @@ func Service(namespace, name string, ports []uint16) (*v1.Service, error) {
var svcPorts []v1.ServicePort
for _, port := range ports {
svcPorts = append(svcPorts, v1.ServicePort{
Name: fmt.Sprintf("port-%d", port),
Port: int32(port),
TargetPort: intstr.IntOrString{IntVal: int32(port)},
})

View file

@ -32,14 +32,17 @@ func TestService(t *testing.T) {
"spec": {
"ports": [
{
"name": "port-1",
"port": 1,
"targetPort": 1
},
{
"name": "port-2",
"port": 2,
"targetPort": 2
},
{
"name": "port-3",
"port": 3,
"targetPort": 3
}