summaryrefslogtreecommitdiff
path: root/api/server
diff options
context:
space:
mode:
authorSebastiaan van Stijn <github@gone.nl>2021-02-23 18:21:37 +0100
committerSebastiaan van Stijn <github@gone.nl>2022-03-25 23:54:14 +0100
commitadf4bf772d6316d6e166542b44b52536472745b5 (patch)
treef4b53f10206a73572292f043912daffaeefcd73a /api/server
parent0729fbd343eb45a16e47d93cf1bd431c16743dda (diff)
downloaddocker-adf4bf772d6316d6e166542b44b52536472745b5.tar.gz
API: add "Swarm" header to _ping endpoint
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>
Diffstat (limited to 'api/server')
-rw-r--r--api/server/router/system/backend.go5
-rw-r--r--api/server/router/system/system_routes.go13
2 files changed, 18 insertions, 0 deletions
diff --git a/api/server/router/system/backend.go b/api/server/router/system/backend.go
index 1d704348c4..940bd4050e 100644
--- a/api/server/router/system/backend.go
+++ b/api/server/router/system/backend.go
@@ -38,3 +38,8 @@ type Backend interface {
type ClusterBackend interface {
Info() swarm.Info
}
+
+// StatusProvider provides methods to get the swarm status of the current node.
+type StatusProvider interface {
+ Status() string
+}
diff --git a/api/server/router/system/system_routes.go b/api/server/router/system/system_routes.go
index 44f80dba5f..d95b5fc13f 100644
--- a/api/server/router/system/system_routes.go
+++ b/api/server/router/system/system_routes.go
@@ -13,6 +13,7 @@ import (
"github.com/docker/docker/api/types/events"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/registry"
+ "github.com/docker/docker/api/types/swarm"
timetypes "github.com/docker/docker/api/types/time"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/pkg/ioutils"
@@ -34,6 +35,9 @@ func (s *systemRouter) pingHandler(ctx context.Context, w http.ResponseWriter, r
if bv := builderVersion; bv != "" {
w.Header().Set("Builder-Version", string(bv))
}
+
+ w.Header().Set("Swarm", s.swarmStatus())
+
if r.Method == http.MethodHead {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
w.Header().Set("Content-Length", "0")
@@ -43,6 +47,15 @@ func (s *systemRouter) pingHandler(ctx context.Context, w http.ResponseWriter, r
return err
}
+func (s *systemRouter) swarmStatus() string {
+ if s.cluster != nil {
+ if p, ok := s.cluster.(StatusProvider); ok {
+ return p.Status()
+ }
+ }
+ return string(swarm.LocalNodeStateInactive)
+}
+
func (s *systemRouter) getInfo(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
info := s.backend.SystemInfo()