10000 cli/command/system/runInfo: set client API defaults, and negotiated API version when available by thaJeztah · Pull Request #4507 · docker/cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

cli/command/system/runInfo: set client API defaults, and negotiated API version when available #4507

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion cli/command/system/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,14 @@ func runInfo(ctx context.Context, cmd *cobra.Command, dockerCli command.Cli, opt
var serverConnErr error
if needsServerInfo(opts.format, info) {
serverConnErr = addServerInfo(ctx, dockerCli, opts.format, &info)
if serverConnErr == nil {
// Update client API version after it was negotiated.
info.ClientInfo.APIVersion = dockerCli.CurrentVersion()
}
}

if opts.format == "" {
info.UserName = dockerCli.ConfigFile().AuthConfigs[registry.IndexServer].Username
info.ClientInfo.APIVersion = dockerCli.CurrentVersion()
return errors.Join(prettyPrintInfo(dockerCli, info), serverConnErr)
}

Expand Down
1 change: 1 addition & 0 deletions cli/command/system/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type clientVersion struct {
func newClientVersion(contextName string, dockerCli command.Cli) clientVersion {
v := clientVersion{
Version: version.Version,
APIVersion: api.DefaultVersion,
Copy link
Collaborator

Choose a reason for hiding this comment

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

If no server information is fetched:

docker info --format='{{ json .ClientInfo }}' | jq .ApiVersion
"1.44"

If server information is fetched:

docker info --format='{{ json .}}' | jq .ClientInfo.ApiVersion
"1.43"

An alternative could be to leave the ApiVersion field empty if no negotiation took place.

Hmm not sure about this one.

On one side it's weird for the version to be different depending on the format, on the other side side being empty is also not great.

I think leaving it empty if no negotiation took place would be slightly more useful:

  • It's already that way so there's no existing expectation that it's always non-empty
  • Empty value is better than misleading value as it's easier to notice
  • The CLI APIVersion that's not impacted by the server negotiation is already there in DefaultAPIVersion and docker version --format='{{ json .Client }}' | jq .ApiVersion

DefaultAPIVersion: api.DefaultVersion,
GoVersion: runtime.Version(),
GitCommit: version.GitCommit,
Expand Down
Loading
0