Skip to content

Commit

Permalink
docker: report unhealthy in unsupported Windows
Browse files Browse the repository at this point in the history
On Windows, Nomad only supports Windows containers, so report as
unhealthy otherwise.
  • Loading branch information
Mahmood Ali committed Feb 24, 2019
1 parent fb06c8e commit 3d281c1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
14 changes: 14 additions & 0 deletions drivers/docker/fingerprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package docker

import (
"context"
"runtime"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -137,6 +138,19 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint {

fp.Attributes["driver.docker.runtimes"] = pstructs.NewStringAttribute(
strings.Join(runtimeNames, ","))
fp.Attributes["driver.docker.os_type"] = pstructs.NewStringAttribute(dockerInfo.OSType)

if runtime.GOOS == "windows" && dockerInfo.OSType == "linux" {
if d.fingerprintSuccessful() {
d.logger.Warn("detected Linux docker containers on Windows; only Windows containers are supported")
}

d.setFingerprintFailure()
return &drivers.Fingerprint{
Health: drivers.HealthStateUnhealthy,
HealthDescription: "Docker is configured with Linux containers; only Windows containers are supported",
}
}
}

d.setFingerprintSuccess()
Expand Down
27 changes: 27 additions & 0 deletions drivers/docker/fingerprint_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package docker

import (
"testing"

"github.com/hashicorp/nomad/client/testutil"
"github.com/hashicorp/nomad/helper/testlog"
"github.com/hashicorp/nomad/plugins/drivers"
tu "github.com/hashicorp/nomad/testutil"
"github.com/stretchr/testify/require"
)

// TestDockerDriver_FingersprintHealth asserts that docker reports healthy
// whenever Docker is supported. In particular.
//
// In Linux CI and AppVeyor Windows environment, it should be enabled.
func TestDockerDriver_FingerprintHealth(t *testing.T) {
if !tu.IsCI() {
t.Parallel()
}
testutil.DockerCompatible(t)

d := NewDockerDriver(testlog.HCLogger(t)).(*Driver)

fp := d.buildFingerprint()
require.Equal(t, drivers.HealthStateHealthy, fp.Health)
}

0 comments on commit 3d281c1

Please sign in to comment.