Skip to content
Merged
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
21 changes: 18 additions & 3 deletions cmd/cli/desktop/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/containerd/errdefs"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/connhelper"
"github.com/docker/cli/cli/context/docker"
"github.com/docker/docker/api/types/container"
clientpkg "github.com/docker/docker/client"
Expand Down Expand Up @@ -83,11 +84,25 @@ func DockerClientForContext(cli *command.DockerCli, name string) (*clientpkg.Cli
if err != nil {
return nil, fmt.Errorf("unable to determine context endpoint: %w", err)
}
return clientpkg.NewClientWithOpts(

opts := []clientpkg.Opt{
clientpkg.FromEnv,
clientpkg.WithHost(endpoint.Host),
clientpkg.WithAPIVersionNegotiation(),
)
clientpkg.WithHost(endpoint.Host),
}

helper, err := connhelper.GetConnectionHelper(endpoint.Host)
if err != nil {
return nil, fmt.Errorf("unable to get SSH connection helper: %w", err)
}
if helper != nil {
opts = append(opts,
clientpkg.WithHost(helper.Host),
clientpkg.WithDialContext(helper.Dialer),
)
}
Comment on lines +88 to +103
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The clientpkg.WithHost option is being set unconditionally with endpoint.Host and then potentially overridden if an SSH connection helper is found. This is redundant and can be confusing. It's cleaner to determine the correct host first and then set the WithHost option only once, which is a common pattern in docker/cli.

Suggested change
opts := []clientpkg.Opt{
clientpkg.FromEnv,
clientpkg.WithHost(endpoint.Host),
clientpkg.WithAPIVersionNegotiation(),
)
clientpkg.WithHost(endpoint.Host),
}
helper, err := connhelper.GetConnectionHelper(endpoint.Host)
if err != nil {
return nil, fmt.Errorf("unable to get SSH connection helper: %w", err)
}
if helper != nil {
opts = append(opts,
clientpkg.WithHost(helper.Host),
clientpkg.WithDialContext(helper.Dialer),
)
}
opts := []clientpkg.Opt{
clientpkg.FromEnv,
clientpkg.WithAPIVersionNegotiation(),
}
helper, err := connhelper.GetConnectionHelper(endpoint.Host)
if err != nil {
return nil, fmt.Errorf("unable to get SSH connection helper: %w", err)
}
if helper != nil {
opts = append(opts,
clientpkg.WithHost(helper.Host),
clientpkg.WithDialContext(helper.Dialer),
)
} else {
opts = append(opts, clientpkg.WithHost(endpoint.Host))
}


return clientpkg.NewClientWithOpts(opts...)
}

// ModelRunnerContext encodes the operational context of a Model CLI command and
Expand Down
Loading