diff options
author | Urvashi Mohnani <umohnani@redhat.com> | 2021-10-14 16:58:27 -0400 |
---|---|---|
committer | Urvashi Mohnani <umohnani@redhat.com> | 2021-10-14 17:03:26 -0400 |
commit | 8db62d04fd0d740a9cd04bd2f674d2533ab3bd51 (patch) | |
tree | 01a0648e1e5b7790780b50bdac7f67125ce1b427 /libpod/kube.go | |
parent | 8d44c548c085c65cae33398b322eabadb6b237f7 (diff) | |
download | podman-8db62d04fd0d740a9cd04bd2f674d2533ab3bd51.tar.gz podman-8db62d04fd0d740a9cd04bd2f674d2533ab3bd51.tar.bz2 podman-8db62d04fd0d740a9cd04bd2f674d2533ab3bd51.zip |
Set targetPort to the port value in the kube yaml
When the targetPort is not defined, it is supposed to
be set to the port value according to the k8s docs.
Add tests for targetPort.
Update tests to be able to check the Service yaml that
is generated.
Signed-off-by: Urvashi Mohnani <umohnani@redhat.com>
Diffstat (limited to 'libpod/kube.go')
-rw-r--r-- | libpod/kube.go | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/libpod/kube.go b/libpod/kube.go index d68140d5e..ee6c99af0 100644 --- a/libpod/kube.go +++ b/libpod/kube.go @@ -25,6 +25,7 @@ import ( v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" v12 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/intstr" ) // GenerateForKube takes a slice of libpod containers and generates @@ -196,10 +197,11 @@ func containerPortsToServicePorts(containerPorts []v1.ContainerPort) []v1.Servic for _, cp := range containerPorts { nodePort := 30000 + rand.Intn(32767-30000+1) servicePort := v1.ServicePort{ - Protocol: cp.Protocol, - Port: cp.ContainerPort, - NodePort: int32(nodePort), - Name: strconv.Itoa(int(cp.ContainerPort)), + Protocol: cp.Protocol, + Port: cp.ContainerPort, + NodePort: int32(nodePort), + Name: strconv.Itoa(int(cp.ContainerPort)), + TargetPort: intstr.Parse(strconv.Itoa(int(cp.ContainerPort))), } sps = append(sps, servicePort) } |