Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix image inspect exit code on image not found error #3792

Merged
merged 1 commit into from
Dec 29, 2024

Conversation

austinvazquez
Copy link
Member

Issue

Fixes regression inadvertently introduced with #3017 for image inspect command exit code when image does not exist.

Description

This change updates the image inspect utility function to serialize an array of encountered errors. This aligns with the behavior of nerdctl inspect.

Testing

Adds simple test case for image inspect on images that do not exist.
Required updates to test cases which assumed exit code 0 for image inspects on images that do not exist.

Copy link
Member

@djdongjin djdongjin left a comment

Choose a reason for hiding this comment

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

The fix LGTM, but I'm not sure why we need the errors unwrap.

cmd/nerdctl/image/image_inspect.go Outdated Show resolved Hide resolved
@AkihiroSuda
Copy link
Member

What is "dnf" here?
Doesn't seem related to Fedora's dnf

@austinvazquez austinvazquez changed the title Fix image inspect error on dnf Fix image inspect exit code on image not found error Dec 28, 2024
@austinvazquez
Copy link
Member Author

@AkihiroSuda, oops sorry about that. I had shorthanded "did not find" not meaning to confuse dnf package manager. Lastest commit should have more clear wording.

Copy link
Member

@djdongjin djdongjin left a comment

Choose a reason for hiding this comment

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

Left some minor comments

pkg/cmd/image/inspect.go Outdated Show resolved Hide resolved
var entries []interface{}

snapshotter := containerdutil.SnapshotService(client, options.GOptions.Snapshotter)
// We have to query per provided identifier, as we need to post-process results for the case name + digest
for _, identifier := range identifiers {
candidateImageList, requestedName, requestedTag, err := inspectIdentifier(ctx, client, identifier)
if err != nil {
log.G(ctx).WithError(err).WithField("identifier", identifier).Error("failure calling inspect")
errs = append(errs, fmt.Sprintf("invalid reference format: %s", identifier))
Copy link
Member

Choose a reason for hiding this comment

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

Is invalid reference format the only possible error here? Or we should return the (wrapped) original error? e.g., something like fmt.Errorf("invalid reference %s: %w", identifier, err)

Copy link
Member Author

Choose a reason for hiding this comment

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

It looks like other errors from inspectIdentifier are errors returned from containerd image service. i.e. https://github.com/austinvazquez/nerdctl/blob/58fb7731a84ac3f260d971f8822aee8329bf1bbf/pkg/cmd/image/inspect.go#L62

So wrapping is useful in that case, but no in the case the error is invalid reference format. Perhaps it is best to revert back to log statement? I originally brought this in as error to align more with Docker behavior, but maybe it isn't worth losing the information here when error talking to containerd.

austin@nimbus:~/workspace/nerdctl$ mysudo nerdctl image inspect ∞∞∞∞∞∞∞∞∞∞ dne:latest
FATA[0000] 2 errors:
invalid reference format: ∞∞∞∞∞∞∞∞∞∞: invalid reference format
no such image: dne:latest 
austin@nimbus:~/workspace/nerdctl$ 

Copy link
Member

@djdongjin djdongjin Dec 28, 2024

Choose a reason for hiding this comment

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

How about let's do fmt.Errorf("%w: %s", err, identifier) 🤔?

The output will be something like:

FATA[0000] 3 errors:
invalid reference format: ∞∞∞∞∞∞∞∞∞∞
no such image: dne:latest 
containerd image service failed: containerd_err: dne:latest2

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the suggestion btw; that solution was way simpler.

This change fixes image inspect command to error when image is not
found.

Signed-off-by: Austin Vazquez <macedonv@amazon.com>
Copy link
Member

@djdongjin djdongjin left a comment

Choose a reason for hiding this comment

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

LGTM on CI green, thanks

@djdongjin djdongjin added this to the v2.0.3 milestone Dec 29, 2024
@djdongjin djdongjin merged commit f917e5c into containerd:main Dec 29, 2024
30 checks passed
@austinvazquez austinvazquez deleted the fix-inspect-err-dnf branch December 29, 2024 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants