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

ssh: Add flag to disable keepalive #249

Merged
merged 4 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
add tests for no-keepalive
  • Loading branch information
petersutter committed Mar 20, 2023
commit c44c05f6fce193f7f7e539c1897444e38dcfd175
1 change: 1 addition & 0 deletions pkg/cmd/ssh/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ var (

return cmd.Run()
}

// waitForSignal informs the user about their SSHOptions and keeps the
// bastion alive until gardenctl exits.
waitForSignal = func(ctx context.Context, o *SSHOptions, shootClient client.Client, bastion *operationsv1alpha1.Bastion, nodeHostname string, nodePrivateKeyFiles []string, signalChan <-chan struct{}) error {
holgerkoser marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
49 changes: 49 additions & 0 deletions pkg/cmd/ssh/ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,33 @@ var _ = Describe("SSH Command", func() {

Expect(logs).To(ContainSubstring("Bastion is ready, skipping availability check"))
})

It("should not keep alive the bastion", func() {
options := ssh.NewSSHOptions(streams)
options.NoKeepalive = true
options.KeepBastion = true
options.Interactive = false

cmd := ssh.NewCmdSSH(factory, options)

ssh.SetWaitForSignal(func(ctx context.Context, o *ssh.SSHOptions, shootClient client.Client, bastion *operationsv1alpha1.Bastion, nodeHostname string, nodePrivateKeyFiles []string, signalChan <-chan struct{}) error {
err := errors.New("this function should not be executed as of NoKeepalive = true")
Fail(err.Error())
return err
})
ssh.SetExecCommand(func(ctx context.Context, command string, args []string, o *ssh.SSHOptions) error {
err := errors.New("this function should not be executed as of NoKeepalive = true")
Fail(err.Error())
return err
})

// simulate an external controller processing the bastion and proving a successful status
go waitForBastionThenSetBastionReady(ctx, gardenClient, bastionName, *testProject.Spec.Namespace, bastionHostname, bastionIP)

Expect(cmd.RunE(cmd, nil)).To(Succeed())

Expect(logs).To(ContainSubstring("Bastion host became available."))
})
})

Describe("ValidArgsFunction", func() {
Expand Down Expand Up @@ -598,6 +625,28 @@ var _ = Describe("SSH Options", func() {
Expect(o.Validate()).NotTo(Succeed())
})

Context("no-keepalive", func() {
It("should require non-interactive mode", func() {
o := ssh.NewSSHOptions(streams)
o.NoKeepalive = true
o.KeepBastion = true

o.Interactive = true

Expect(o.Validate()).NotTo(Succeed())
})

It("should require keep bastion", func() {
o := ssh.NewSSHOptions(streams)
o.NoKeepalive = true
o.Interactive = false

o.KeepBastion = false

Expect(o.Validate()).NotTo(Succeed())
})
})

It("should require a public SSH key file", func() {
o := ssh.NewSSHOptions(streams)
o.CIDRs = []string{"8.8.8.8/32"}
Expand Down