Always include Ports within inspect response #3311
Closed
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.
Resolves #3310
New behavior will always initialize a
NetworkSettings
containing initializedPortMap
for the inspect response.NetworkSettings
will include aPorts
with empty struct.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 aPorts
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 returnnil
.Solution
To resolve this issue, the
NetworkSettings
andPortMap
are initialized at the beginning of the method to ensure that at least "Empty-value" structs are always included within theinspect
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 thejson:",omitempty"
decorator for theNetworkSettings
struct.Additional Tasks
This bug is also present within
v1.7.6
and the change can be easily reconciled with the released version.Release/1.7
branch.