Skip to content

Commit

Permalink
Merge pull request #5362 from hashicorp/dani/f-fingerprint-undetected
Browse files Browse the repository at this point in the history
docker: Return undetected before first detection
  • Loading branch information
endocrimes authored Feb 25, 2019
2 parents eecae58 + 6c774e7 commit d3c7e4d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions drivers/docker/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 22 additions & 1 deletion drivers/docker/fingerprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit d3c7e4d

Please sign in to comment.