Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default missing hostPort to containerPort is defined in kube.yaml #15946

Merged
merged 1 commit into from Sep 27, 2022

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Sep 26, 2022

If user does not specify hostPort in a kube.yml file but does specify a containerPort, then the hostPort should default to the containerPort.

Fixes: #15942

Signed-off-by: Daniel J Walsh dwalsh@redhat.com

Does this PR introduce a user-facing change?

podman kube play will default hostPort of Pod to containerPort if hostPort is not specified by containerPort is specified.

@openshift-ci openshift-ci bot added the do-not-merge/release-note-label-needed Enforce release-note requirement, even if just None label Sep 26, 2022
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Sep 26, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rhatdan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 26, 2022
@rhatdan
Copy link
Member Author

rhatdan commented Sep 26, 2022

@openshift-ci openshift-ci bot added release-note and removed do-not-merge/release-note-label-needed Enforce release-note requirement, even if just None labels Sep 26, 2022
Copy link
Collaborator

@edsantiago edsantiago left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran your new test against main @ aaeabb0. It passes (local & remote, root & rootless). That suggests that your test is not testing what you think it's testing. (Or, I'm missing something crucial, which is always a high probability).


@test "podman kube play - hostport" {
HOST_PORT=$(random_free_port)
TESTDIR=$PODMAN_TMPDIR/testdir
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$PODMAN_TMPDIR is fresh and new for each @test; so I don't think you need $TESTDIR.

@haircommander
Copy link
Collaborator

haircommander commented Sep 26, 2022

LGTM; nice and easy


run_podman kube play $PODMAN_TMPDIR/testpod.yaml
run_podman pod inspect test_pod --format "{{.InfraConfig.PortBindings}}"
is "$output" "map[$HOST_PORT/tcp:[{ $HOST_PORT}]]"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whew! Figured out why test passes on main. It's because the is function tries an equal-match (==) first, but then tries expr if that fails. Which means all those brackets end up meaning "map, plus maybe other stuff". Fix:

-    is "$output" "map[$HOST_PORT/tcp:[{ $HOST_PORT}]]"
+    assert "$output" = "map[$HOST_PORT/tcp:[{ $HOST_PORT}]]"

asserts, with explicit =, will not try a regex match. With this fix, the test fails on main and passes with your PR.

@mheon
Copy link
Member

mheon commented Sep 26, 2022

LGTM

@rhatdan
Copy link
Member Author

rhatdan commented Sep 26, 2022

/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 26, 2022
@rhatdan rhatdan added the lgtm Indicates that a PR is ready to be merged. label Sep 26, 2022
@vrothberg
Copy link
Member

int tests are barking

@edsantiago
Copy link
Collaborator

rootless is failing, and I'm kind of almost sure that it's this:

- containerPort: 80
(also line 148). Haven't looked closely enough to know how to fix: maybe skip if rootless, maybe change the port, maybe remove that port line entirely.

@edsantiago
Copy link
Collaborator

Friendly suggestion:

diff --git a/test/e2e/play_kube_test.go b/test/e2e/play_kube_test.go
index 67c88953a..651cb1074 100644
--- a/test/e2e/play_kube_test.go
+++ b/test/e2e/play_kube_test.go
@@ -133,8 +133,6 @@ spec:
   containers:
   - name: podnameEqualsContainerNameYaml
     image: quay.io/libpod/alpine:latest
-    ports:
-    - containerPort: 80
 `
 
 var podWithoutAName = `
@@ -239,8 +237,6 @@ spec:
         - "1.5"
         name: alpine
         image: quay.io/libpod/alpine:latest
-        ports:
-        - containerPort: 80
         livenessProbe:
           exec:
             command:
@@ -274,8 +270,6 @@ spec:
         - "1.5"
         name: alpine
         image: quay.io/libpod/alpine:latest
-        ports:
-        - containerPort: 80
         livenessProbe:
           exec:
             command:

Important note: I choose to remove the port lines completely, vs change to 8080 or somesuch, because of the ginkgo parallel-test thing in which two tests could want to bind to the same port at the same time.

If user does not specify hostPort in a kube.yml file but does specify
a containerPort, then the hostPort should default to the containerPort.

Fixes: containers#15942

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
@umohnani8
Copy link
Member

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Sep 27, 2022
@edsantiago
Copy link
Collaborator

/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 27, 2022
@openshift-merge-robot openshift-merge-robot merged commit dca5ead into containers:main Sep 27, 2022
@rhatdan rhatdan deleted the kube branch December 1, 2022 22:00
dcermak added a commit to dcermak/podman that referenced this pull request Dec 15, 2022
podman play kube started to expose the port of containers in k8s deployments on
the same port on the host with
containers#15946. However, that breaks once
replicas are involved, as they would then bind to the same port on the host.

With this commit, we change the default behavior so that podman will pick a
random port for the container instead of using `containerPort`, but only if no
`hostPort` is set.

This fixes: containers#16765

Signed-off-by: Dan Čermák <dcermak@suse.com>
dcermak added a commit to dcermak/podman that referenced this pull request Dec 15, 2022
podman play kube started to expose the port of containers in k8s deployments on
the same port on the host with
containers#15946. However, that breaks once
replicas are involved, as they would then bind to the same port on the host.

With this commit, we change the default behavior so that podman will pick a
random port for the container instead of using `containerPort`, but only if no
`hostPort` is set.

This fixes: containers#16765

Signed-off-by: Dan Čermák <dcermak@suse.com>
dcermak added a commit to dcermak/podman that referenced this pull request Dec 15, 2022
podman play kube started to expose the port of containers in k8s deployments on
the same port on the host with
containers#15946. However, that breaks once
replicas are involved, as they would then bind to the same port on the host.

With this commit, we change the default behavior so that podman will pick a
random port for the container instead of using `containerPort`, but only if no
`hostPort` is set.

This fixes: containers#16765

Signed-off-by: Dan Čermák <dcermak@suse.com>
dcermak added a commit to dcermak/podman that referenced this pull request Dec 16, 2022
podman play kube started to expose the port of containers in k8s deployments on
the same port on the host with
containers#15946. However, that breaks once
replicas are involved, as they would then bind to the same port on the host.

With this commit, we change the default behavior so that podman will pick a
random port for the container instead of using `containerPort`, but only if no
`hostPort` is set.

This fixes: containers#16765

Signed-off-by: Dan Čermák <dcermak@suse.com>
dcermak added a commit to dcermak/podman that referenced this pull request Dec 20, 2022
podman play kube started to expose the port of containers in k8s deployments on
the same port on the host with
containers#15946. However, that breaks once
replicas are involved, as they would then bind to the same port on the host.

With this commit, we change the default behavior so that podman will pick a
random port for the container instead of using `containerPort`, but only if no
`hostPort` is set.

This fixes: containers#16765

Signed-off-by: Dan Čermák <dcermak@suse.com>
dcermak added a commit to dcermak/podman that referenced this pull request Jan 2, 2023
podman play kube started to expose the port of containers in k8s deployments on
the same port on the host with
containers#15946. However, that breaks once
replicas are involved, as they would then bind to the same port on the host.

With this commit, we change the default behavior so that podman will pick a
random port for the container instead of using `containerPort`, but only if no
`hostPort` is set.

This fixes: containers#16765

Signed-off-by: Dan Čermák <dcermak@suse.com>
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 20, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

podman play kube only binds ports when hostPort is specified.
7 participants