-
Notifications
You must be signed in to change notification settings - Fork 18.9k
API: add "Swarm" header to _ping endpoint #42064
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
Conversation
|
/cc @djs55 |
djs55
left a comment
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.
Nice, thanks! I'd like to use this from the Docker Desktop diagnostics code. Currently we call a swarm endpoint which logs an error if swarm is not enabled, leading users to think there has been some kind of swarm error...
b531f1b to
6e096f0
Compare
|
@cpuguy83 made some changes; let me know if this is closer to what you had in mind |
| if s.IsActiveManager() || s.IsManager() { | ||
| state += " (manager)" | ||
| } else { | ||
| state += " (worker)" | ||
| } |
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.
Slightly thinking if we should keep manager/worker separate from node state (as other status/role combinations would be possible)
cpuguy83
left a comment
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
client/ping.go
Outdated
| parts := strings.SplitN(si, " ", 2) | ||
| ping.SwarmStatus = &swarm.Status{ | ||
| NodeState: swarm.LocalNodeState(parts[0]), | ||
| ControlAvailable: len(parts) == 2 && parts[1] == "(manager)", |
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.
This seems a little bit fiddly -- we're essentially parsing what's effectively a human-readable string back into separate parts? 😬
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.
Yes, agreed. I've been going back-and-forth on what the best approach would be; we could make the format itself more "parseable" (<status>/<role>) or two separate headers (I wasn't sure about the separate headers, because we won't be able to set the role until the status is also available (IIRC).
This adds an additional "Swarm" header to the _ping endpoint response, which allows a client to detect if Swarm is enabled on the daemon, without having to call additional endpoints. This change is not versioned in the API, and will be returned irregardless of the API version that is used. Clients should fall back to using other endpoints to get this information if the header is not present. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
|
@tianon changed it to |
|
Thanks, everyone for reviewing; let's get this one in 👍 |
| ctx := context.TODO() | ||
|
|
||
| t.Run("before swarm init", func(t *testing.T) { | ||
| res, _, err := request.Get("/_ping") |
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.
This should've been:
| res, _, err := request.Get("/_ping") | |
| res, _, err := request.Get("/_ping", request.Host(d.Sock())) |
Fixing in #43658
depends on #42063
This adds an additional "Swarm" header to the _ping endpoint response, which allows a client to detect if Swarm is enabled on the daemon, without having to call additional endpoints.
This change is not versioned in the API, and will be returned irregardless of the API version that is used. Clients should fall back to using other endpoints to get this information if the header is not present.
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)