Skip to content
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

docker: Return undetected before first detection #5362

Merged
merged 1 commit into from
Feb 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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