mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-01-08 16:45:30 +00:00
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:
parent
bbafe3c386
commit
f7f78b2a3f
2 changed files with 6 additions and 0 deletions
|
@ -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)},
|
||||
})
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue