fix(image-import): report import failures instead of printing success - #1694
Open
TheSaifZaman wants to merge 2 commits into
Open
fix(image-import): report import failures instead of printing success#1694TheSaifZaman wants to merge 2 commits into
TheSaifZaman wants to merge 2 commits into
Conversation
`k3d image import` logged per-node import failures and tarball copy failures, but discarded them: `importWithToolsNode` always returned nil, so the caller went on to print "Successfully imported image(s)" and exit with code 0. Automation had no way to detect a failed import. Two paths were losing errors: - the per-node `ctr image import` goroutines ran in a bare WaitGroup and only logged their error. They now run in an errgroup that returns it. - a failed `CopyToNode` for an image tarball logged and `continue`d. It now records the error and still continues with the remaining tarballs. Errors are collected and returned only after the tarball and tools node cleanup has run, so a failed import does not leave resources behind. Per-node failures are still logged individually so that all of them stay visible, not just the first one returned. Fixes k3d-io#1484
The stdin branch of `ImageImportIntoClusterMulti` wrapped the result of
`loadImageFromStream` unconditionally, so `k3d image import -` returned
an error on every invocation, including successful ones:
failed to load image to cluster from stdin: %!v(<nil>)
Only return an error when one actually occurred, and log the same
success message as the other import paths. The cause is now wrapped with
%w so that callers can unwrap it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
k3d image importprintsSuccessfully imported image(s)and exits0even when the import failed on every node. This PR makes the failures surface, and fixes a related bug on the stdin path found while writing the tests.Fixes #1484
Why
importWithToolsNodelogged its errors but always returnednil, soImageImportIntoClusterMultifell through to the success message. Two paths were losing errors:ctr image importcalls ran in a baresync.WaitGroupgoroutine whose error was only passed tol.Log().Errorf. Nothing propagated it.CopyToNodelogged andcontinued, so a tarball that never reached the tools node was silently skipped. If it was the only tarball, the import loop then had nothing to do and still reported success.This matters most in CI/automation, where the reported exit code is the only signal. Two users on the issue describe hitting it intermittently (roughly 1 run in 10) and working around it with
--mode=direct.Changes
Commit 1 —
fix(image-import): report failures instead of printing successerrgroup.Groupinstead of async.WaitGroup, so a failure is returnedCommit 2 —
fix(image-import): don't report failure when reading from stdin succeedsThe stdin branch wrapped its result unconditionally:
so
k3d image import -returned an error on every run, including successful ones — literallyfailed to load image to cluster from stdin: %!v(<nil>). It's the mirror image of the bug above and sits three lines away, so I fixed it here; happy to split it into its own PR if you'd rather keep this focused.Tests
New
pkg/client/tools_import_test.gocovering all three behaviours, each confirmed to fail against the unfixed code first:Test_importWithToolsNode_returnsErrorWhenImportIntoNodeFailsTest_importWithToolsNode_returnsErrorWhenTarballCopyFailsTest_ImageImportIntoClusterMulti_succeedsWhenReadingImageFromStdinThey use a
fakeToolsRuntimethat embedsruntimes.Runtimeand overrides only the five methods this path touches, following the existingFakeRuntimeImageGetterpattern intools_test.go. Any unexpected runtime call panics rather than silently passing.go test ./...passes;gofmtandgo vetare clean on both files. I wasn't able to rungolangci-lintlocally, so please let CI be the judge there.Note for reviewers
While writing the stdin test I hit a pre-existing issue that is not addressed here:
loadImageFromStreamnever closes its pipe writers, so a consumer that reads to EOF blocks forever. It doesn't deadlock in production only because the realExecInNodeWithStdinreturns when the exec exits. The fake reads a single chunk to work around it (see the comment there). Worth a separate issue if you agree it's a problem.