Skip to content

Commit

Permalink
Merge pull request #11980 from umohnani8/kube
Browse files Browse the repository at this point in the history
Do not add TCP to protocol in generated kube yaml
  • Loading branch information
openshift-merge-robot authored Oct 14, 2021
2 parents 8d44c54 + 16e7cc8 commit fecef15
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion libpod/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,8 @@ func ocicniPortMappingToContainerPort(portMappings []types.OCICNIPortMapping) ([
var protocol v1.Protocol
switch strings.ToUpper(p.Protocol) {
case "TCP":
protocol = v1.ProtocolTCP
// do nothing as it is the default protocol in k8s, there is no need to explicitly
// add it to the generated yaml
case "UDP":
protocol = v1.ProtocolUDP
default:
Expand Down
22 changes: 22 additions & 0 deletions test/e2e/generate_kube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,10 @@ var _ = Describe("Podman generate kube", func() {
foundOtherPort := 0
for _, ctr := range pod.Spec.Containers {
for _, port := range ctr.Ports {
// Since we are using tcp here, the generated kube yaml shouldn't
// have anything for protocol under the ports as tcp is the default
// for k8s
Expect(port.Protocol).To(BeEmpty())
if port.HostPort == 4000 {
foundPort4000 = foundPort4000 + 1
} else if port.HostPort == 5000 {
Expand All @@ -463,6 +467,24 @@ var _ = Describe("Podman generate kube", func() {
Expect(foundPort4000).To(Equal(1))
Expect(foundPort5000).To(Equal(1))
Expect(foundOtherPort).To(Equal(0))

// Create container with UDP port and check the generated kube yaml
ctrWithUDP := podmanTest.Podman([]string{"create", "--pod", "new:test-pod", "-p", "6666:66/udp", ALPINE, "top"})
ctrWithUDP.WaitWithDefaultTimeout()
Expect(ctrWithUDP).Should(Exit(0))

kube = podmanTest.Podman([]string{"generate", "kube", "test-pod"})
kube.WaitWithDefaultTimeout()
Expect(kube).Should(Exit(0))

pod = new(v1.Pod)
err = yaml.Unmarshal(kube.Out.Contents(), pod)
Expect(err).To(BeNil())

containers := pod.Spec.Containers
Expect(len(containers)).To(Equal(1))
Expect(len(containers[0].Ports)).To(Equal(1))
Expect(containers[0].Ports[0].Protocol).To(Equal(v1.ProtocolUDP))
})

It("podman generate and reimport kube on pod", func() {
Expand Down

0 comments on commit fecef15

Please sign in to comment.