mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 10:25:42 +03:00
docker: report unhealthy in unsupported Windows (#5356)
On Windows, Nomad only supports Windows containers, so report as unhealthy otherwise.
This commit is contained in:
@@ -2,6 +2,7 @@ package docker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -158,6 +159,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()
|
||||
|
||||
27
drivers/docker/fingerprint_test.go
Normal file
27
drivers/docker/fingerprint_test.go
Normal file
@@ -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_FingerprintHealth asserts that docker reports healthy
|
||||
// whenever Docker is supported.
|
||||
//
|
||||
// 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)
|
||||
}
|
||||
Reference in New Issue
Block a user