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 - completion with machine objects #347

Merged
merged 16 commits into from
Jan 10, 2024
Prev Previous commit
Next Next commit
PR feedback
  • Loading branch information
petersutter committed Jan 9, 2024
commit 7211b3d9eeb2754f62625a54c07f0a3e28ba2e5a
8 changes: 1 addition & 7 deletions pkg/cmd/ssh/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -821,15 +821,9 @@ func cleanup(ctx context.Context, o *SSHOptions, gardenClient client.Client, bas
}
}

func getNodeNamesFromMachinesOrNodes(f util.Factory) ([]string, error) {
ctx := f.Context()
func getNodeNamesFromMachinesOrNodes(ctx context.Context, manager target.Manager) ([]string, error) {
logger := klog.FromContext(ctx)

manager, err := f.Manager()
if err != nil {
return nil, err
}

currentTarget, err := manager.CurrentTarget()
if err != nil {
return nil, err
Expand Down
8 changes: 7 additions & 1 deletion pkg/cmd/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ gardenctl ssh --keep-bastion --bastion-name cli-xxxxxxxx --public-key-file /path
return nil, cobra.ShellCompDirectiveNoFileComp
}

nodeNames, err := getNodeNamesFromMachinesOrNodes(f)
manager, err := f.Manager()
if err != nil {
logger.Error(err, "could not get manager from factory")
return nil, cobra.ShellCompDirectiveNoFileComp
}

nodeNames, err := getNodeNamesFromMachinesOrNodes(ctx, manager)
if err != nil {
logger.Error(err, "could not get node names from shoot")
return nil, cobra.ShellCompDirectiveNoFileComp
Expand Down
10 changes: 5 additions & 5 deletions pkg/cmd/ssh/ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,13 +682,13 @@ var _ = Describe("SSH Command", func() {

factory.ManagerImpl = manager
manager.EXPECT().CurrentTarget().Return(currentTarget, nil)
manager.EXPECT().GardenClient(currentTarget.GardenName()).Return(client, nil).AnyTimes()
manager.EXPECT().GardenClient(currentTarget.GardenName()).Return(client, nil)

client.EXPECT().FindShoot(ctx, currentTarget.AsListOption()).Return(testShoot, nil)
})

It("should return all names based on machine objects", func() {
manager.EXPECT().SeedClient(ctx, gomock.Any()).Return(seedClient, nil).AnyTimes()
manager.EXPECT().SeedClient(ctx, gomock.Any()).Return(seedClient, nil)

options := ssh.NewSSHOptions(streams)
cmd := ssh.NewCmdSSH(factory, options)
Expand All @@ -701,8 +701,8 @@ var _ = Describe("SSH Command", func() {

It("should return all names based on node objects", func() {
errForbidden := &apierrors.StatusError{ErrStatus: metav1.Status{Reason: metav1.StatusReasonForbidden}}
manager.EXPECT().SeedClient(gomock.Any(), gomock.Any()).Return(nil, errForbidden).AnyTimes()
manager.EXPECT().ShootClient(gomock.Any(), gomock.Any()).Return(shootClient, nil).AnyTimes()
manager.EXPECT().SeedClient(gomock.Any(), gomock.Any()).Return(nil, errForbidden)
manager.EXPECT().ShootClient(gomock.Any(), gomock.Any()).Return(shootClient, nil)
petersutter marked this conversation as resolved.
Show resolved Hide resolved

options := ssh.NewSSHOptions(streams)
cmd := ssh.NewCmdSSH(factory, options)
Expand All @@ -714,7 +714,7 @@ var _ = Describe("SSH Command", func() {
})

It("should find nodes based on their prefix from machine objects", func() {
manager.EXPECT().SeedClient(ctx, gomock.Any()).Return(seedClient, nil).AnyTimes()
manager.EXPECT().SeedClient(ctx, gomock.Any()).Return(seedClient, nil)

options := ssh.NewSSHOptions(streams)
cmd := ssh.NewCmdSSH(factory, options)
Expand Down