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

Support the execution of SSH commands with optional input. #1831

Merged
merged 1 commit into from
Feb 7, 2024

Conversation

gordonmessmer
Copy link
Contributor

These changes are needed to support containers/podman#21420

Supporting an input file for SSH commands can avoid the use of temporary files.

@rhatdan
Copy link
Member

rhatdan commented Jan 30, 2024

/approve
LGTM except for test failures.
@cdoern PTAL

@rhatdan
Copy link
Member

rhatdan commented Jan 31, 2024

Lint is complaining about some of your code?

@gordonmessmer
Copy link
Contributor Author

I've taken care of the lint problems, but I'm not sure how to address the CI failure. If I run "make test" on the unmodified "main" branch, I see what looks like the same failures as the tests in my branch.

@baude
Copy link
Member

baude commented Jan 31, 2024

fails for me too ... can someone take a peek at this?

pkg/ssh/ssh_test.go Outdated Show resolved Hide resolved
@rhatdan
Copy link
Member

rhatdan commented Feb 2, 2024

@baude @edsantiago PTAL

@baude
Copy link
Member

baude commented Feb 2, 2024

@gordonmessmer could you write a more verbose commit message on why we need this PR (i'm not doubting we do)? when i review a PR, I really want to have the context (bigger picture) of why this is important, etc. And normally, when things come the team, I already have that ... so when it comes outside, it just really helps. I would appreciate that. I also want reviews from @edsantiago and @Luap99 but both are out today.

@gordonmessmer
Copy link
Contributor Author

Certainly! I've updated the commit message. Please let me know if any other changes would be helpful.

pkg/ssh/ssh.go Outdated
return ExecWithInput(options, kind, nil)
}

func ExecWithInput(options *ConnectionExecOptions, kind EngineMode, input *os.File) (string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

input should be io.Reader because the lower level APIs accept an io.Reader and this is much more flexible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense to me. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(I can't tell if the CI tests are meaningful at this point. I'll manually test podman-image-scp with these changes as soon as I get a chance.)

Copy link
Member

Choose a reason for hiding this comment

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

I don't think there are any useful scp tests here.

@gordonmessmer gordonmessmer force-pushed the scp-no-mktemp branch 2 times, most recently from fa2ff70 to 8921971 Compare February 5, 2024 22:38
Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

Can you rebase this PR as well, CI is failing due a flake that is fixed in main.

pkg/ssh/ssh.go Outdated
return ExecWithInput(options, kind, nil)
}

func ExecWithInput(options *ConnectionExecOptions, kind EngineMode, input *io.Reader) (string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func ExecWithInput(options *ConnectionExecOptions, kind EngineMode, input *io.Reader) (string, error) {
func ExecWithInput(options *ConnectionExecOptions, kind EngineMode, input io.Reader) (string, error) {

io.Reader is already an interface so this should not be a pointer to the interface as it adds extra indirection for no reason.

@gordonmessmer
Copy link
Contributor Author

The PR has been rebased, and the fedora-39 test has passed. Pointers have been removed. (I'm afraid my experience with Go is still a bit limited.)

If you have suggestions on what you'd like to see in the tests, I can do some additional work in that area.

@gordonmessmer
Copy link
Contributor Author

Regarding lint errors: this is another area where my inexperience with golang is showing. I kept golangConnectionExec and nativeConnectionExec because I wasn't sure if they were part of the public interface of the library. If they're not, I expect they could be removed. If they should be kept, then I'm not sure how to address the lint error.

@rhatdan
Copy link
Member

rhatdan commented Feb 7, 2024

Functions which begin with a lower case letter are private so they can be removed.

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

openshift-ci bot commented Feb 7, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gordonmessmer, Luap99, 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

@rhatdan
Copy link
Member

rhatdan commented Feb 7, 2024

Lint is not happy.

Because the SSH exec functions do not currently support execution with
input, some users (such as the podman-image-scp) must operate in two
phases, first copying a file to the remote host, and then executing a
command with shell redirection and removing the temporary file.

This API extension allows those users to simplify their code and
avoid the use of temporary files.

Signed-off-by: Gordon Messmer <gordon.messmer@gmail.com>
@gordonmessmer
Copy link
Contributor Author

The CI result looks like it might be indicating three files with issues identified by lint, but I've installed gci and it only found whitespace issues in two files, so this push may or may not fix the lint issues.

Is there any documentation that describes running tests locally? I haven't quite figured that part out, and it seems like it'd cut down some back-and-forth. If not, then I'll just wait for CI results. :)

@rhatdan
Copy link
Member

rhatdan commented Feb 7, 2024

/lgtm
/hold

@rhatdan
Copy link
Member

rhatdan commented Feb 7, 2024

/unhold
Thanks @gordonmessmer

@openshift-merge-bot openshift-merge-bot bot merged commit ebc7496 into containers:main Feb 7, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants