Skip to content

Commit

Permalink
cli/command/system/newClientVersion: initialize with default API version
Browse files Browse the repository at this point in the history
Set the APIVersion and DefaultAPIVersion fields to the default version,
as that's the version the client assumes without making a API connection
to do version negotiation.

One change worth mentioning is that this means that the API version will
differ, depending on the format:

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.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
  • Loading branch information
thaJeztah committed Aug 22, 2023
1 parent e1c30df commit 7fc2305
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions cli/command/system/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
flagsHelper "github.com/docker/cli/cli/flags"
"github.com/docker/cli/cli/version"
"github.com/docker/cli/templates"
"github.com/docker/docker/api"
"github.com/docker/docker/api/types"
"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -89,13 +90,15 @@ type clientVersion struct {
// information.
func newClientVersion(contextName string, dockerCli command.Cli) clientVersion {
v := clientVersion{
Version: version.Version,
GoVersion: runtime.Version(),
GitCommit: version.GitCommit,
BuildTime: reformatDate(version.BuildTime),
Os: runtime.GOOS,
Arch: arch(),
Context: contextName,
Version: version.Version,
APIVersion: api.DefaultVersion,
DefaultAPIVersion: api.DefaultVersion,
GoVersion: runtime.Version(),
GitCommit: version.GitCommit,
BuildTime: reformatDate(version.BuildTime),
Os: runtime.GOOS,
Arch: arch(),
Context: contextName,
}
if version.PlatformName != "" {
v.Platform = &platformInfo{Name: version.PlatformName}
Expand Down

0 comments on commit 7fc2305

Please sign in to comment.