Skip to content

Conversation

@thaJeztah
Copy link
Member

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

The `GET /_ping` and `HEAD /_ping` API endpoints now return a `Swarm` header,
which allows a client to detect if Swarm is enabled on the daemon, without
having to call additional endpoints.

- A picture of a cute animal (not mandatory but encouraged)

@thaJeztah
Copy link
Member Author

/cc @djs55

Copy link
Contributor

@djs55 djs55 left a 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...

@thaJeztah thaJeztah force-pushed the swarm_ping branch 9 times, most recently from b531f1b to 6e096f0 Compare February 27, 2021 01:12
@thaJeztah thaJeztah added this to the 21.xx milestone Feb 27, 2021
@thaJeztah
Copy link
Member Author

@cpuguy83 made some changes; let me know if this is closer to what you had in mind

Comment on lines 503 to 507
if s.IsActiveManager() || s.IsManager() {
state += " (manager)"
} else {
state += " (worker)"
}
Copy link
Member Author

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)

Copy link
Member

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

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

LGTM

@thaJeztah
Copy link
Member Author

I realised the client code to handle the ping response is in this repository (not in docker/cli), so I pushed a commit that handles the client side (to include it in the ping result)

@tianon @cpuguy83 PTAL if that last commit looks good to you 😅

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)",
Copy link
Member

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? 😬

Copy link
Member Author

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>
@thaJeztah
Copy link
Member Author

@tianon changed it to <status>/<role> to make it less hacky (open to better suggestions of course)

@thaJeztah
Copy link
Member Author

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")
Copy link
Member Author

Choose a reason for hiding this comment

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

This should've been:

Suggested change
res, _, err := request.Get("/_ping")
res, _, err := request.Get("/_ping", request.Host(d.Sock()))

Fixing in #43658

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants