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
Inspect output on service without labels is an empty map instead of null, fixes #24631 #30967
Inspect output on service without labels is an empty map instead of null, fixes #24631 #30967
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🐯
@@ -17,7 +17,7 @@ type Meta struct { | |||
// Annotations represents how to describe an object. | |||
type Annotations struct { | |||
Name string `json:",omitempty"` | |||
Labels map[string]string `json:",omitempty"` | |||
Labels map[string]string `json:"Labels"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the omitempty
here is related to #24631. I don't think there's any harm in continuing to omit the Labels
field when it's empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the review. I removed the omitempty because my tests show 'null' as output with omitempty left as is, while including all other changes of the PR. (I think the empty labels map is lost in marshalling/unmarshaling due to omitempty. The test steps are listed in the PR description). I did not find any client-side code that makes changes to the retrieved object, so avoided adding such code (e.g. in client/service_inspect.go). Is fixing the nil labels map on the client-side the preferred approach? (in that case, I can update the PR accordingly)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for confirming that this makes a difference.
I honestly don't know the right solution. It doesn't feel intuitively right to me to force the field to be marshalled in all cases so that the client avoids outputting null
for a specific query. My sense is that it would be better for the client to make sure the map is initialized after unmarshalling, but I'm not sure how we handle these cases in general. I'll step back and let other maintainers offer opinions.
This should not just be done for |
…s is empty object {} Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
90f27a1
to
1b347cf
Compare
@aaronlehmann Thank you for the review. I have updated the PR to include all object types using Annotations. |
I think we had not-nil slices and maps all around the place already. |
Added code to output an empty map, instead of null, by the inspect command for labels of a service that has no labels. Fixes #24631 (also changes 'null' output to an empty object for other types with labels: secret, node, task, network, swarm)
Signed-off-by: Arash Deshmeh adeshmeh@ca.ibm.com
- What I did
The output of inspect command for labels of a service that has no labels is currently 'null', which is inconsistent with other objects, e.g. inspect output for labels of containers without labels is an empty object: {}. This PR fixes this inconsistency by changing the output to '{}' when the service has no labels.
- How I did it
Added code which replaces nil labels maps on service objects with an empty map, when retrieved by the daemon.
- How to verify it
Create a service:
$ docker service create --name nolabels nginx:alpine
Run inspect on the service, with Labels specified in format string.
Without this PR:
$ docker service inspect --format '{{ json .Spec.Labels }}' nolabels
null
With this PR included:
$ docker service inspect --format '{{ json .Spec.Labels }}' nolabels
{}
- Description for the changelog
The inspect command outputs an empty json object, i.e. {}, instead of null, for labels of a service that has no labels
- A picture of a cute animal (not mandatory but encouraged)