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

Library based ssh #1209

Merged
merged 8 commits into from
Jul 16, 2024
Merged

Library based ssh #1209

merged 8 commits into from
Jul 16, 2024

Conversation

aerosouund
Copy link
Member

What this PR does / why we need it:
Replaces ssh.sh in run.go with golang library based ssh that goes directly to the node rather than the node container as a middle man

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Special notes for your reviewer:

Checklist

Release note:

Use library based ssh in run.go

@kubevirt-bot kubevirt-bot added the dco-signoff: yes Indicates the PR's author has DCO signed all their commits. label Jun 25, 2024
@kubevirt-bot
Copy link
Contributor

Hi @aerosouund. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@aerosouund
Copy link
Member Author

@aerosouund aerosouund force-pushed the library-based-ssh branch 2 times, most recently from c99528b to b5ea285 Compare June 25, 2024 16:52
if err != nil {
return "", fmt.Errorf("Error creating forwarded ssh connection: %s", err)
}
jumpHost := ssh.NewClient(ncc, chans, reqs)
Copy link
Member

@acardace acardace Jun 27, 2024

Choose a reason for hiding this comment

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

In general I'd prefer if you moved all this init and config part into a separate function that gets executed once per SSHClient instantiation, I'd expect that you establish the SSH connection once and keep it alive for the lifetime of the SSHClient struct.

In practice I'd have modify the interface to have a Command() function, this way you'd establish the connection once when you instantiate the ssh client and then Command() would just sent commands using the open ssh session and a Close() function that closes the socket. This way you have 1 socket per connection instead of 1 per command.

That said, this is an optimization, take it a as follow-up work.

Copy link
Member Author

Choose a reason for hiding this comment

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

Acknowledged. i think its a good idea as well
we can implement it in a follow up PR

@@ -0,0 +1,29 @@
package utils
Copy link
Member

Choose a reason for hiding this comment

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

dbfa492 commit message. The part about using struct and what it takes seems redundant. A more interesting part would be to see why we need this package. Something general/summary as below:

Example:

Introduce SSH package

The package provides simple interface for SSH to specific node and implementation of this interface.
The implementation is based on std ssh package and we use the SSH port exposed on master node. 
Jump is used to SSH to other nodes.

@@ -3,7 +3,6 @@ package cmd
import (
"bufio"
"bytes"
"errors"
Copy link
Member

Choose a reason for hiding this comment

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

Please adjust commit messages to something like https://www.conventionalcommits.org/en/v1.0.0/

@aerosouund aerosouund force-pushed the library-based-ssh branch 3 times, most recently from cb7fecc to 8a3bd30 Compare July 4, 2024 10:29
Signed-off-by: aerosouund <[email protected]>
@aerosouund aerosouund force-pushed the library-based-ssh branch from 8a3bd30 to 101007b Compare July 4, 2024 12:10
Copy link
Member

@xpivarc xpivarc left a comment

Choose a reason for hiding this comment

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

Few more questions/comment but looks good to me


if !success {
return fmt.Errorf("provisioning node %s failed", nodeName)
if x+1 == 1 {
Copy link
Member

Choose a reason for hiding this comment

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

This is change of logic, you should preserve the logic and change this in next commit. I think this is fine nevertheless, @brianmcarey wdyt?

}

// move the scripts to the same location they were in in the nodecontainer to enable command abstraction
for _, cmd := range []string{"sudo mkdir /scripts", "sudo cp -r /home/vagrant/scripts/* /scripts"} {
Copy link
Member

Choose a reason for hiding this comment

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

Why can't we do this in previous command?

Copy link
Member Author

Choose a reason for hiding this comment

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

you mean sudo mkdir /scripts && sudo cp -r /home/vagrant/scripts/* /scripts ?

Copy link
Member

Choose a reason for hiding this comment

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

I mean the previous command (scp) -r /scripts [email protected]%d:/home/vagrant/scripts moves the scripts to the VM and here we move them within the VM. Why can't we set the location right with the scp?

Copy link
Member Author

@aerosouund aerosouund Jul 8, 2024

Choose a reason for hiding this comment

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

@xpivarc
Because editing the root directory requires sudo privileges and the root user does not have an ssh key so you cant scp as him

Copy link
Member

Choose a reason for hiding this comment

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

Ah make sense, I'll have one more pass

@aerosouund aerosouund force-pushed the library-based-ssh branch from 101007b to 4db5c1f Compare July 5, 2024 08:33
@xpivarc
Copy link
Member

xpivarc commented Jul 8, 2024

@dhiller @brianmcarey Can you help me merge this one (missing approver right on this repo :) )

@aerosouund aerosouund force-pushed the library-based-ssh branch from 4db5c1f to f1cf73c Compare July 9, 2024 13:27
@brianmcarey
Copy link
Member

/cc

Keep ssh in a single place by leveraging the adapter and passing it as a param for functions that did docker exec themselves; prepareDeviceForAssignment and prepareEtcdDataMount.
Replace the logic for checking if there's a special provision script for a node to running the script for node01 at index 1

Signed-off-by: aerosouund <[email protected]>
The config package introduces holder structs that contain the params for a node and the k8s optional deployments on a kubevirt provider. To pass this config directly to other methods without having to pass every parameter to the functions that run the node or k8s options

Signed-off-by: aerosouund <[email protected]>
Package the logic of node launching and configuring its linux system into provisionNode and running the optional k8s deployments into provisionK8sOptions.
Both functions take as a parameter an ssh client and a struct that represents a holder to their config from the config package

Signed-off-by: aerosouund <[email protected]>
Introduce a testing package based on mock that tests the provisionNode and provisionK8sOptions methods and include the logic to run this package in the main test suite of the cmd package

Signed-off-by: aerosouund <[email protected]>
Use an implementation based on ssh'ing directly to nodes rather than through their node container.
Move the scripts directory on the node during provisioning and remove it after finishing

Signed-off-by: aerosouund <[email protected]>
@dhiller
Copy link
Contributor

dhiller commented Jul 15, 2024

/test check-provision-k8s-1.28

@dhiller
Copy link
Contributor

dhiller commented Jul 15, 2024

/test check-provision-k8s-1.30

Copy link
Contributor

@dhiller dhiller left a comment

Choose a reason for hiding this comment

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

Thank you for this work @aerosouund !

/approve

@dhiller
Copy link
Contributor

dhiller commented Jul 15, 2024

/lgtm

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Jul 15, 2024
@brianmcarey
Copy link
Member

/test ?

@kubevirt-bot
Copy link
Contributor

@brianmcarey: The following commands are available to trigger required jobs:

  • /test check-provision-alpine-with-test-tooling
  • /test check-provision-centos-base
  • /test check-provision-k8s-1.28
  • /test check-provision-k8s-1.29
  • /test check-provision-k8s-1.30
  • /test check-provision-manager
  • /test check-up-kind-ovn
  • /test check-up-kind-sriov

The following commands are available to trigger optional jobs:

  • /test check-gocli
  • /test check-up-kind-1.27-vgpu
  • /test check-up-kind-1.30-vgpu

Use /test all to run the following jobs that were automatically triggered:

  • check-provision-alpine-with-test-tooling
  • check-provision-k8s-1.28
  • check-provision-k8s-1.29
  • check-provision-k8s-1.30
  • check-provision-manager
  • check-up-kind-1.27-vgpu
  • check-up-kind-1.30-vgpu
  • check-up-kind-sriov

In response to this:

/test ?

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@brianmcarey
Copy link
Member

/test check-gocli
/test check-provision-centos-base

@kubevirt-bot
Copy link
Contributor

kubevirt-bot commented Jul 15, 2024

@aerosouund: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
check-up-kind-1.27-vgpu 1c993f7 link false /test check-up-kind-1.27-vgpu

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Copy link
Member

@brianmcarey brianmcarey left a comment

Choose a reason for hiding this comment

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

/approve

thanks @aerosouund !

@kubevirt-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: brianmcarey, dhiller

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:
  • OWNERS [brianmcarey,dhiller]

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

@kubevirt-bot kubevirt-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 16, 2024
@brianmcarey
Copy link
Member

/override check-provision-alpine-with-test-tooling

Not related to these changes.

@kubevirt-bot
Copy link
Contributor

@brianmcarey: Overrode contexts on behalf of brianmcarey: check-provision-alpine-with-test-tooling

In response to this:

/override check-provision-alpine-with-test-tooling

Not related to these changes.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@kubevirt-bot kubevirt-bot merged commit aa7d876 into kubevirt:main Jul 16, 2024
11 of 12 checks passed
kubevirt-bot added a commit to kubevirt-bot/kubevirt that referenced this pull request Jul 17, 2024
[a087e7e Automatic bump of CentOS Stream to latest](kubevirt/kubevirtci#1219)
[83e15cc alpine,image: Use full image name for qemu-user-static image](kubevirt/kubevirtci#1218)
[aa7d876 Library based ssh](kubevirt/kubevirtci#1209)
[c43f010 fix missing whitespace](kubevirt/kubevirtci#1216)
[9bb50bf enable vm-image-builder for s390x.](kubevirt/kubevirtci#1207)

```release-note
NONE
```

Signed-off-by: kubevirt-bot <[email protected]>
cmds := []string{
fmt.Sprintf("mkdir -p %s", etcdDataDir),
fmt.Sprintf("test -d %s", etcdDataDir),
fmt.Sprintf("mount -t tmpfs -o size=%s tmpfs %s", mountSize, etcdDataDir),
Copy link
Member

Choose a reason for hiding this comment

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

@aerosouund This needs to run with sudo, see failure in kubevirt/kubevirt#12310

kubevirt-bot added a commit to kubevirt-bot/kubevirt that referenced this pull request Jul 18, 2024
[f3a5054 fix: Run etcd commads with sudo](kubevirt/kubevirtci#1223)
[a087e7e Automatic bump of CentOS Stream to latest](kubevirt/kubevirtci#1219)
[83e15cc alpine,image: Use full image name for qemu-user-static image](kubevirt/kubevirtci#1218)
[aa7d876 Library based ssh](kubevirt/kubevirtci#1209)
[c43f010 fix missing whitespace](kubevirt/kubevirtci#1216)
[9bb50bf enable vm-image-builder for s390x.](kubevirt/kubevirtci#1207)

```release-note
NONE
```

Signed-off-by: kubevirt-bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. lgtm Indicates that a PR is ready to be merged. size/XXL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants