Skip to content

Conversation

@thaJeztah
Copy link
Member

cli/command/system/runInfo: set negotiated API version when available

The current logic was ignoring (e.g.) --format=json formats, and was
only setting the negotiated API version if no format was specified.

While we do want to avoid calling the API if possible, we do already
check if the given template requires a server connection, so let's
move updating the API version to that block.

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.

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@codecov-commenter
Copy link

codecov-commenter commented Nov 23, 2023

Codecov Report

Attention: Patch coverage is 20.00000% with 4 lines in your changes missing coverage. Please review.

Project coverage is 59.05%. Comparing base (fc99fe2) to head (c0482fd).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4507      +/-   ##
==========================================
- Coverage   59.05%   59.05%   -0.01%     
==========================================
  Files         357      357              
  Lines       29843    29846       +3     
==========================================
+ Hits        17624    17625       +1     
- Misses      11241    11243       +2     
  Partials      978      978              
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

vvoland
vvoland previously approved these changes Nov 24, 2023
Arch: arch(),
Context: contextName,
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

@thaJeztah thaJeztah modified the milestones: 25.0.0, 26.0.0 Jan 19, 2024
@vvoland vvoland modified the milestones: 26.0.0, 27.0.0 Mar 14, 2024
@vvoland vvoland modified the milestones: 27.0.0, 28.0.0 Jun 20, 2024
@thaJeztah thaJeztah modified the milestones: 28.0.0, 28.0.5 Mar 31, 2025
The current logic was ignoring (e.g.) `--format=json` formats, and was
only setting the negotiated API version if no format was specified.

While we do want to avoid calling the API if possible, we do already
check if the given template requires a server connection, so let's
move updating the API version to that block.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
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>
@thaJeztah thaJeztah modified the milestones: 28.1.1, 28.1.2 Apr 23, 2025
@thaJeztah thaJeztah modified the milestones: 28.1.2, 28.2.0, 29.0.0 May 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants