cli/command/system/newClientVersion: initialize with default API version

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 <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-08-22 10:02:51 +02:00
parent 223d71a837
commit c2f3e171b5
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
1 changed files with 10 additions and 7 deletions

View File

@ -16,6 +16,7 @@ import (
flagsHelper "github.com/docker/cli/cli/flags" flagsHelper "github.com/docker/cli/cli/flags"
"github.com/docker/cli/cli/version" "github.com/docker/cli/cli/version"
"github.com/docker/cli/templates" "github.com/docker/cli/templates"
"github.com/docker/docker/api"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -89,13 +90,15 @@ type clientVersion struct {
// information. // information.
func newClientVersion(contextName string, dockerCli command.Cli) clientVersion { func newClientVersion(contextName string, dockerCli command.Cli) clientVersion {
v := clientVersion{ v := clientVersion{
Version: version.Version, Version: version.Version,
GoVersion: runtime.Version(), APIVersion: api.DefaultVersion,
GitCommit: version.GitCommit, DefaultAPIVersion: api.DefaultVersion,
BuildTime: reformatDate(version.BuildTime), GoVersion: runtime.Version(),
Os: runtime.GOOS, GitCommit: version.GitCommit,
Arch: arch(), BuildTime: reformatDate(version.BuildTime),
Context: contextName, Os: runtime.GOOS,
Arch: arch(),
Context: contextName,
} }
if version.PlatformName != "" { if version.PlatformName != "" {
v.Platform = &platformInfo{Name: version.PlatformName} v.Platform = &platformInfo{Name: version.PlatformName}