From 6c774e7b46e48179cbe0c84929a956751cadc66a Mon Sep 17 00:00:00 2001 From: Danielle Tomlinson Date: Mon, 25 Feb 2019 11:02:42 +0100 Subject: [PATCH] docker: Return undetected before first detection This commit causes the docker driver to return undetected before it first establishes a connection to the docker daemon. This fixes a bug where hosts without docker installed would return as unhealthy, rather than undetected. --- drivers/docker/driver.go | 5 +++++ drivers/docker/fingerprint.go | 23 ++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/drivers/docker/driver.go b/drivers/docker/driver.go index e38bf5898ae..cbbf5d91bee 100644 --- a/drivers/docker/driver.go +++ b/drivers/docker/driver.go @@ -99,6 +99,11 @@ type Driver struct { // whether it has been successful fingerprintSuccess *bool fingerprintLock sync.RWMutex + + // A boolean to know if the docker driver has ever been correctly detected + // for use during fingerprinting. + detected bool + detectedLock sync.RWMutex } // NewDockerDriver returns a docker implementation of a driver plugin diff --git a/drivers/docker/fingerprint.go b/drivers/docker/fingerprint.go index f086bd0bb55..10a7306c658 100644 --- a/drivers/docker/fingerprint.go +++ b/drivers/docker/fingerprint.go @@ -17,6 +17,20 @@ func (d *Driver) Fingerprint(ctx context.Context) (<-chan *drivers.Fingerprint, return ch, nil } +func (d *Driver) previouslyDetected() bool { + d.detectedLock.RLock() + defer d.detectedLock.RUnlock() + + return d.detected +} + +func (d *Driver) setDetected(detected bool) { + d.detectedLock.Lock() + defer d.detectedLock.Unlock() + + d.detected = detected +} + // setFingerprintSuccess marks the driver as having fingerprinted successfully func (d *Driver) setFingerprintSuccess() { d.fingerprintLock.Lock() @@ -79,12 +93,19 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint { d.logger.Debug("could not connect to docker daemon", "endpoint", client.Endpoint(), "error", err) } d.setFingerprintFailure() + + result := drivers.HealthStateUndetected + if d.previouslyDetected() { + result = drivers.HealthStateUnhealthy + } + return &drivers.Fingerprint{ - Health: drivers.HealthStateUnhealthy, + Health: result, HealthDescription: "Failed to connect to docker daemon", } } + d.setDetected(true) fp.Attributes["driver.docker"] = pstructs.NewBoolAttribute(true) fp.Attributes["driver.docker.version"] = pstructs.NewStringAttribute(env.Get("Version")) if d.config.AllowPrivileged {