Skip to content

fix: inspect should return one array rather than a stream of array #3961

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

Merged
merged 2 commits into from
Apr 15, 2025

Conversation

weiyuhang2011
Copy link
Contributor

Description

This PR fixes an issue where nerdctl inspect <container1> <image1> return a stream of array rather than one array.

Steps to reproduce the issue

current

> nerdctl inspect container1 image1
[
    {
       <container1-info>
    }
]
[
    {
       <image1-info>
    }
]

fixed

> nerdctl inspect container1 image1
[
    {
       <container1-info>
    },
    {
       <image1-info>
    }
]

Fix: #3006

@AkihiroSuda AkihiroSuda added this to the v2.0.4 milestone Mar 3, 2025
@AkihiroSuda
Copy link
Member

Thanks, can we have a test?

@weiyuhang2011
Copy link
Contributor Author

Thanks, can we have a test?

Sure, i will add a test.

@AkihiroSuda AkihiroSuda modified the milestones: v2.0.4, v2.x.x Mar 18, 2025
@manugupt1
Copy link
Contributor

@weiyuhang2011 Ping! Did you find time to write tests? Thank you!

@weiyuhang2011
Copy link
Contributor Author

@weiyuhang2011 Ping! Did you find time to write tests? Thank you!

Indeed, it's been delayed for quite a while... I've prepared an initial draft and will strive to complete it this week.

@weiyuhang2011 weiyuhang2011 force-pushed the fix-inspect branch 2 times, most recently from 3ce4a1a to 36c24b5 Compare April 12, 2025 12:52
@manugupt1 manugupt1 requested a review from a team April 13, 2025 21:13
@manugupt1 manugupt1 modified the milestones: v2.x.x, v2.0.5 Apr 13, 2025
@apostasie
Copy link
Contributor

I do personally like that we would be moving presentation concerns into ./cmd/nerdctl instead of having them in ./pkg/cmd/nerdctl.
I think it is just better for people who want to consume nerdctl as a library - as presentation should be left as a concern to the final cli. Generally speaking, I would like to see any Fprintf gone from the "library" part. Right now, ./pkg/cmd is an unfortunate mix of data processing and display.

That being said, this is personal opinion, and I am not sure if this was discussed before and/or if there was agreement on this.

}

// Display
if len(entries) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i think we can keep it, but remove the one in cmd/nerdctl/inspect/inspect.go

}

// Display
if len(entries) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same

@apostasie
Copy link
Contributor

Two main comments:

  • interface{} -> any
  • do we need to check on len(entries) > 0?

Plus a nit inside test.

Otherwise LGTM.

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

Signed-off-by: Yuhang Wei <weiyuhang2011@gmail.com>
`nerdctl inspect <container> <image>` should return a single JSON array
containing both the container and image inspect results. This unit test
parses the output and compares it with the results of separate `inspect`
commands to ensure correctness.

Signed-off-by: Yuhang Wei <weiyuhang2011@gmail.com>
@weiyuhang2011
Copy link
Contributor Author

It seems like the CI is failing on some tests not relevant to this PR?

Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

Thanks

Next time please consider squashing the commits

@AkihiroSuda AkihiroSuda merged commit fa64898 into containerd:main Apr 15, 2025
30 checks passed
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.

nerdctl inspect should not return a stream of json array, but a single array
5 participants