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

fix port issues for CONTAINER_HOST #16526

Merged
merged 1 commit into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions pkg/bindings/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,12 @@ func NewConnectionWithIdentity(ctx context.Context, uri string, identity string,
var connection Connection
switch _url.Scheme {
case "ssh":
port, err := strconv.Atoi(_url.Port())
if err != nil {
return nil, err
port := 22
Copy link
Member

Choose a reason for hiding this comment

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

You could read /etc/services for this, but I think this is fine.
LGTM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hesitant since there are a bunch of different ssh related lines in there it seems but I can do this if we want

if _url.Port() != "" {
port, err = strconv.Atoi(_url.Port())
Copy link
Member

Choose a reason for hiding this comment

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

you could just do port, _ =

Copy link
Contributor Author

@cdoern cdoern Nov 15, 2022

Choose a reason for hiding this comment

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

sure, but I will leave the if since atoi returns 0 on failure

if err != nil {
return nil, err
}
}
conn, err := ssh.Dial(&ssh.ConnectionDialOptions{
Host: uri,
Expand Down
9 changes: 9 additions & 0 deletions test/e2e/system_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,15 @@ var _ = Describe("podman system connection", func() {
_, err = Start(cmd, GinkgoWriter, GinkgoWriter)
Expect(err).ToNot(HaveOccurred())

// export the container_host env var and try again
err = os.Setenv("CONTAINER_HOST", fmt.Sprintf("ssh://%s@localhost", u.Username))
Expect(err).ToNot(HaveOccurred())
defer os.Unsetenv("CONTAINER_HOST")

cmd = exec.Command(podmanTest.RemotePodmanBinary, "ps")
_, err = Start(cmd, GinkgoWriter, GinkgoWriter)
Expect(err).ToNot(HaveOccurred())

uri := url.URL{
Scheme: "ssh",
User: url.User(u.Username),
Expand Down