Skip to content

cli/trust: TagTrusted: lazily request APIClient - #5905

Closed
thaJeztah wants to merge 1 commit into
docker:masterfrom
thaJeztah:test_failures
Closed

cli/trust: TagTrusted: lazily request APIClient#5905
thaJeztah wants to merge 1 commit into
docker:masterfrom
thaJeztah:test_failures

Conversation

@thaJeztah

@thaJeztahthaJeztah commented Mar 8, 2025

Copy link
Copy Markdown
Member

Seeing various test-failures that could be a regression, related to

cli/trust: TagTrusted: remove, and inline code

Commit e37d814 moved the image.TagTrusted
function to the trust package, but changed the signature slightly to accept
an API client, instead of requiring the command.Cli. However, this could
result in situations where the Client obtained from the CLI was not correctly
initialized, resulting in failures in our e2e test;

=== FAIL: e2e/global TestPromptExitCode/plugin_upgrade (9.14s)
cli_test.go:203: assertion failed: Command: docker plugin push registry:5000/plugin-content-trust-upgrade:next
ExitCode: 1
Error: exit status 1
Stdout: The push refers to repository [registry:5000/plugin-content-trust-upgrade]
24ec5b45d59b: Preparing
6a594992d358: Preparing
224414d1b129: Preparing
24ec5b45d59b: Preparing
6a594992d358: Preparing
224414d1b129: Preparing
Stderr: error pushing plugin: failed to do request: Head "https://registry:5000/v2/plugin-content-trust-upgrade/blobs/sha256:6a594992d358facbbc4ab134bbbba77cb91e0adee6ff0d6103403ff94a9b796c": http: server gave HTTP response to HTTPS client
Failures:
ExitCode was 1 expected 0
Expected no error

This patch changes the signature to accept an "APIClientProvider" so that
the Client is obtained the moment when used.

We should look what exactly causes this situation, and if we can make
sure that requesting the Client() will always produce the client with
the expected configuration.

While looking at the code, I also noticed that Client.ImageTag already
parses and normalizes tags given, so we don't need to convert them to
their "familiar" form, other than for printing the message;

https://github.com/moby/moby/blob/b4bdf12daec84caaf809a639f923f7370d4926ad/client/image_tag.go#L11-L37

With that taken into account, trust.TrustedPush has no real value, other
than printing an informational message, so removing the function and
inlining it in the locations where it's used.

⚠️ WARNING: looks like the test is still flaky after this change, so it
may just be a bad test, or tests affecting each-other (same port, but
different config?). That said; these changes may still be ok to
include.

- What I did

- How I did it

- How to verify it

- Human readable description for the release notes

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

@codecov-commenter

codecov-commenter commented Mar 8, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 0% with 13 lines in your changes missing coverage. Please review.

Project coverage is 59.27%. Comparing base (2eec746) to head (1e32cb2).

Additional details and impacted files
@@ Coverage Diff @@## master #5905 +/- ##
==========================================
+ Coverage 59.26% 59.27% +0.01% 
==========================================
Files 357 358 +1 Lines 29771 29771 ==========================================
+ Hits 17645 17648 +3 + Misses 11153 11150 -3 
Partials 973 973 
🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines 244 to 246
if taggedRef, ok := namedRef.(reference.NamedTagged); ok && trustedRef != nil {
return trust.TagTrusted(ctx, dockerCli.Client(), dockerCli.Err(), trustedRef, taggedRef)
return image.TagTrusted(ctx, dockerCli, trustedRef, taggedRef)
}

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Looks like it passes with this revert; wondering if it's because the .Client() would be called as part of the TagTrusted, but now we're calling it early 🤔 (possibly before things related to trust were initialised?)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

☝️ So doesn't look like the cause, and very likely just a flaky test in general.

@thaJeztah

Copy link
Copy Markdown
MemberAuthor

This looks unrelated; some other issue with GitHub?

#2 ERROR: failed to fetch remote https://github.com/docker/cli.git: git stderr:
error: RPC failed; HTTP 504 curl 22 The requested URL returned error: 504
fatal: expected flush after ref listing
: exit status 128
------
> [internal] load git source https://github.com/docker/cli.git#refs/pull/5905/merge:
0.198 b20aa460db47688497ecfde3433650ab17957c4e	refs/pull/5905/merge
600.1 error: RPC failed; HTTP 504 curl 22 The requested URL returned error: 504
600.1 fatal: expected flush after ref listing
------
ERROR: failed to solve: failed to read dockerfile: failed to fetch remote https://github.com/docker/cli.git: git stderr:
error: RPC failed; HTTP 504 curl 22 The requested URL returned error: 504
fatal: expected flush after ref listing
: exit status 128

@thaJeztah

Copy link
Copy Markdown
MemberAuthor

Yup, looks like that may be it

@thaJeztah
thaJeztahforce-pushed the test_failures branch 3 times, most recently from 94615bb to 39caa02CompareMarch 8, 2025 14:22
@thaJeztahthaJeztah changed the title [DNM] testing possible regressioncli/trust: TagTrusted: lazily request APIClient to fix regressionMar 8, 2025
@thaJeztahthaJeztah added this to the 28.0.2 milestone Mar 8, 2025
@thaJeztah
thaJeztah marked this pull request as ready for review March 8, 2025 14:23
@thaJeztah

Copy link
Copy Markdown
MemberAuthor

Ugh; looks like it's still happening, so need to dig deeper, or it was just something that was flaky before?

 Stderr: error pushing plugin: failed to do request: Head "https://registry:5000/v2/plugin-content-trust/blobs/sha256:f8208ac0663752e1e4fa3ccbc2e4640e2d87b6de7c2a0df4482e1420607bb1b3": http: server gave HTTP response to HTTPS client

@thaJeztah
thaJeztah marked this pull request as draft March 8, 2025 14:38
@thaJeztah

Copy link
Copy Markdown
MemberAuthor

OK, so looks like it's really just some flaky test. I think these changes still make sense to include, but not sure what's causing those tests to be flaky, other than multiple tests affecting each other possibly.

@thaJeztahthaJeztah changed the title cli/trust: TagTrusted: lazily request APIClient to fix regressioncli/trust: TagTrusted: lazily request APIClientMar 8, 2025
@thaJeztahthaJeztah added kind/refactor PR's that refactor, or clean-up code and removed kind/bugfix PR's that fix bugs labels Mar 8, 2025
@thaJeztah
thaJeztah marked this pull request as ready for review March 8, 2025 15:24
Commit e37d814 moved the image.TagTrusted
function to the trust package, but changed the signature slightly to accept
an API client, instead of requiring the command.Cli. However, this could
result in situations where the Client obtained from the CLI was not correctly
initialized, resulting in failures in our e2e test;
=== FAIL: e2e/global TestPromptExitCode/plugin_upgrade (9.14s)
cli_test.go:203: assertion failed:
Command: docker plugin push registry:5000/plugin-content-trust-upgrade:next
ExitCode: 1
Error: exit status 1
Stdout: The push refers to repository [registry:5000/plugin-content-trust-upgrade]
24ec5b45d59b: Preparing
6a594992d358: Preparing
224414d1b129: Preparing
24ec5b45d59b: Preparing
6a594992d358: Preparing
224414d1b129: Preparing
Stderr: error pushing plugin: failed to do request: Head "https://registry:5000/v2/plugin-content-trust-upgrade/blobs/sha256:6a594992d358facbbc4ab134bbbba77cb91e0adee6ff0d6103403ff94a9b796c": http: server gave HTTP response to HTTPS client
Failures:
ExitCode was 1 expected 0
Expected no error
This patch changes the signature to accept an "APIClientProvider" so that
the Client is obtained the moment when used.
We should look what exactly causes this situation, and if we can make
sure that requesting the `Client()` will always produce the client with
the expected configuration.
While looking at the code, I also noticed that Client.ImageTag already
parses and normalizes tags given, so we don't need to convert them to
their "familiar" form, other than for printing the message;
https://github.com/moby/moby/blob/b4bdf12daec84caaf809a639f923f7370d4926ad/client/image_tag.go#L11-L37
With that taken into account, trust.TrustedPush has no real value, other
than printing an informational message, so removing the function and
inlining it in the locations where it's used.
WARNING: looks like the test is still flaky after this change, so it
may just be a bad test, or tests affecting each-other (same port, but
different config?). That said; these changes may still be ok to
include.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

@vvolandvvoland left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think it actually makes it that much lazier?

Looks like it only moves it after the
_, _ = fmt.Fprintf(out, "Tagging %s as %s\n", trustedFamiliarRef, familiarRef).

It also duplicates the TagTrusted in two other places.

@vvolandvvoland modified the milestones: 28.0.2, 28.0.3Mar 19, 2025
@vvolandvvoland modified the milestones: 28.0.4, 28.0.5Mar 25, 2025
@thaJeztahthaJeztah modified the milestones: 28.1.1, 28.1.2Apr 23, 2025
@thaJeztahthaJeztah modified the milestones: 28.1.2, 28.2.0May 15, 2025

@BenehikoBenehiko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

oh wait, yeah i see there are merge conflicts and needs some adjustments.

@thaJeztah
thaJeztah deleted the test_failures branch January 13, 2026 14:46
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/trustkind/refactorPR's that refactor, or clean-up codestatus/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@thaJeztah@codecov-commenter@vvoland@Benehiko