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

Always include Ports within inspect response #3311

Closed
wants to merge 0 commits into from

Conversation

chews93319
Copy link
Contributor

@chews93319 chews93319 commented Aug 14, 2024

Resolves #3310

New behavior will always initialize a NetworkSettings containing initialized PortMap for the inspect response.

  • If published ports are available, then values will be included in the response.
  • If there are no published ports, then NetworkSettings will include a Ports with empty struct.
  • If the container had been stopped/Exited, then NetworkSettings will be an initialized struct will all entities mapping to "Zero-value" values.

Background

Research related to Scenario 1:
According to dockercompat line189 and the logical evaluation of Port Annotations, the Ports are not assigned within the response when values are present within the Annotations.
Therefore, containers without published ports yield an NetworkSettings structure without a Ports key-value pair.

Research related to Scenario 2:
According to dockercompat line401, the native.NetNS of a stopped/exited container is a null pointer, which would return nil.

Solution

To resolve this issue, the NetworkSettings and PortMap are initialized at the beginning of the method to ensure that at least "Empty-value" structs are always included within the inspect response.
When "Port Annotations" are available, the new logic will add the key-value pairs into the initialized PortMap of the response.

Since Ports should not be omitted, this change also removes the json:",omitempty" decorator for the NetworkSettings struct.

Additional Tasks

This bug is also present within v1.7.6 and the change can be easily reconciled with the released version.

  • Please consider this PR for Back Porting into Release/1.7 branch.

@apostasie
Copy link
Contributor

@chews93319 Nice!

Two things:

  • CI failures are unrelated - canary is bust for now - and the other is network related.
  • maybe we could have a test or two?

@chews93319
Copy link
Contributor Author

@apostasie Thanks for taking a look.

I actually need to iterate on my PR implementation for another use-case (Refer to my updated Issue 3310 Description ), so I will also try to introduce a test against the method networkSettingsFromNative.
Interestingly, there were no tests against the method before, so it will be a good step to introduce something new.

@apostasie
Copy link
Contributor

@apostasie Thanks for taking a look.

I actually need to iterate on my PR implementation for another use-case (Refer to my updated Issue 3310 Description ), so I will also try to introduce a test against the method networkSettingsFromNative. Interestingly, there were no tests against the method before, so it will be a good step to introduce something new.

That's very welcome. Inspect needs a lot of love...

There is a bunch of additional issues with it.
If you see anything low-hanging fruit in these while patching that code region:

CI Canary failure got fixed (rebase should bring in the fix).

I am not a maintainer here - but lmk if I can help you with anything.

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 response responds to DevContainers with null values
2 participants