Skip to content

Commit

Permalink
Merge pull request #4919 from hashicorp/f-fingerprint-attribute-type
Browse files Browse the repository at this point in the history
Modify fingerprint interface to use typed attribute struct
  • Loading branch information
Preetha authored Nov 28, 2018
2 parents 8cdce8b + 22ddb4d commit be65442
Show file tree
Hide file tree
Showing 29 changed files with 376 additions and 351 deletions.
10 changes: 9 additions & 1 deletion client/fingerprint_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/hashicorp/nomad/plugins/base"
"github.com/hashicorp/nomad/plugins/drivers"
"github.com/hashicorp/nomad/plugins/shared/loader"
pstructs "github.com/hashicorp/nomad/plugins/shared/structs"
)

const (
Expand Down Expand Up @@ -321,7 +322,7 @@ func (fm *FingerprintManager) watchDriverFingerprint(fpChan <-chan *drivers.Fing
// struct and updates the Node with it
func (fm *FingerprintManager) processDriverFingerprint(fp *drivers.Fingerprint, driverName string) {
di := &structs.DriverInfo{
Attributes: fp.Attributes,
Attributes: stringify(fp.Attributes),
Detected: fp.Health != drivers.HealthStateUndetected,
Healthy: fp.Health == drivers.HealthStateHealthy,
HealthDescription: fp.HealthDescription,
Expand All @@ -331,6 +332,13 @@ func (fm *FingerprintManager) processDriverFingerprint(fp *drivers.Fingerprint,
fm.setNode(n)
}
}
func stringify(attributes map[string]*pstructs.Attribute) map[string]string {
ret := make(map[string]string, len(attributes))
for key, attribute := range attributes {
ret[key] = attribute.GoString()
}
return ret
}

// dispenseDriverFingerprint dispenses a driver plugin for the given driver name
// and requests a fingerprint channel. The channel and a context cancel function
Expand Down
12 changes: 6 additions & 6 deletions client/logmon/proto/logmon.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions drivers/docker/docklog/proto/docker_logger.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions drivers/docker/fingerprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"github.com/hashicorp/nomad/plugins/drivers"
pstructs "github.com/hashicorp/nomad/plugins/shared/structs"
)

func (d *Driver) Fingerprint(ctx context.Context) (<-chan *drivers.Fingerprint, error) {
Expand All @@ -31,7 +32,7 @@ func (d *Driver) handleFingerprint(ctx context.Context, ch chan *drivers.Fingerp

func (d *Driver) buildFingerprint() *drivers.Fingerprint {
fp := &drivers.Fingerprint{
Attributes: map[string]string{},
Attributes: map[string]*pstructs.Attribute{},
Health: drivers.HealthStateHealthy,
HealthDescription: "healthy",
}
Expand All @@ -53,14 +54,14 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint {
}
}

fp.Attributes["driver.docker"] = "1"
fp.Attributes["driver.docker.version"] = env.Get("Version")
fp.Attributes["driver.docker"] = pstructs.NewBoolAttribute(true)
fp.Attributes["driver.docker.version"] = pstructs.NewStringAttribute(env.Get("Version"))
if d.config.AllowPrivileged {
fp.Attributes["driver.docker.privileged.enabled"] = "1"
fp.Attributes["driver.docker.privileged.enabled"] = pstructs.NewBoolAttribute(true)
}

if d.config.Volumes.Enabled {
fp.Attributes["driver.docker.volumes.enabled"] = "1"
fp.Attributes["driver.docker.volumes.enabled"] = pstructs.NewBoolAttribute(true)
}

if nets, err := client.ListNetworks(); err != nil {
Expand All @@ -77,7 +78,7 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint {
}

if n.IPAM.Config[0].Gateway != "" {
fp.Attributes["driver.docker.bridge_ip"] = n.IPAM.Config[0].Gateway
fp.Attributes["driver.docker.bridge_ip"] = pstructs.NewStringAttribute(n.IPAM.Config[0].Gateway)
} else {
// Docker 17.09.0-ce dropped the Gateway IP from the bridge network
// See https://github.com/moby/moby/issues/32648
Expand Down
5 changes: 3 additions & 2 deletions drivers/exec/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/hashicorp/nomad/plugins/shared"
"github.com/hashicorp/nomad/plugins/shared/hclspec"
"github.com/hashicorp/nomad/plugins/shared/loader"
pstructs "github.com/hashicorp/nomad/plugins/shared/structs"
)

const (
Expand Down Expand Up @@ -187,7 +188,7 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint {
}

fp := &drivers.Fingerprint{
Attributes: map[string]string{},
Attributes: map[string]*pstructs.Attribute{},
Health: drivers.HealthStateHealthy,
HealthDescription: "healthy",
}
Expand All @@ -212,7 +213,7 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint {
return fp
}

fp.Attributes["driver.exec"] = "1"
fp.Attributes["driver.exec"] = pstructs.NewBoolAttribute(true)
return fp
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/exec/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestExecDriver_Fingerprint(t *testing.T) {
select {
case finger := <-fingerCh:
require.Equal(drivers.HealthStateHealthy, finger.Health)
require.Equal("1", finger.Attributes["driver.exec"])
require.True(finger.Attributes["driver.exec"].GetBool())
case <-time.After(time.Duration(testutil.TestMultiplier()*5) * time.Second):
require.Fail("timeout receiving fingerprint")
}
Expand Down
11 changes: 6 additions & 5 deletions drivers/java/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/hashicorp/nomad/plugins/shared"
"github.com/hashicorp/nomad/plugins/shared/hclspec"
"github.com/hashicorp/nomad/plugins/shared/loader"
pstructs "github.com/hashicorp/nomad/plugins/shared/structs"
)

const (
Expand Down Expand Up @@ -195,7 +196,7 @@ func (d *Driver) handleFingerprint(ctx context.Context, ch chan *drivers.Fingerp

func (d *Driver) buildFingerprint() *drivers.Fingerprint {
fp := &drivers.Fingerprint{
Attributes: map[string]string{},
Attributes: map[string]*pstructs.Attribute{},
Health: drivers.HealthStateHealthy,
HealthDescription: "healthy",
}
Expand Down Expand Up @@ -232,10 +233,10 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint {
return fp
}

fp.Attributes[driverAttr] = "1"
fp.Attributes[driverVersionAttr] = version
fp.Attributes["driver.java.runtime"] = runtime
fp.Attributes["driver.java.vm"] = vm
fp.Attributes[driverAttr] = pstructs.NewBoolAttribute(true)
fp.Attributes[driverVersionAttr] = pstructs.NewStringAttribute(version)
fp.Attributes["driver.java.runtime"] = pstructs.NewStringAttribute(runtime)
fp.Attributes["driver.java.vm"] = pstructs.NewStringAttribute(vm)

return fp
}
Expand Down
3 changes: 2 additions & 1 deletion drivers/java/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ func TestJavaDriver_Fingerprint(t *testing.T) {
select {
case fp := <-fpCh:
require.Equal(t, drivers.HealthStateHealthy, fp.Health)
require.Equal(t, "1", fp.Attributes["driver.java"])
detected, _ := fp.Attributes["driver.java"].GetBool()
require.True(t, detected)
case <-time.After(time.Duration(testutil.TestMultiplier()*5) * time.Second):
require.Fail(t, "timeout receiving fingerprint")
}
Expand Down
14 changes: 7 additions & 7 deletions drivers/lxc/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import (
"strconv"
"time"

hclog "github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/nomad/client/stats"
cstructs "github.com/hashicorp/nomad/client/structs"
"github.com/hashicorp/nomad/drivers/shared/eventer"
"github.com/hashicorp/nomad/plugins/base"
"github.com/hashicorp/nomad/plugins/drivers"
"github.com/hashicorp/nomad/plugins/shared/hclspec"
"github.com/hashicorp/nomad/plugins/shared/loader"

lxc "gopkg.in/lxc/go-lxc.v2"
pstructs "github.com/hashicorp/nomad/plugins/shared/structs"
"gopkg.in/lxc/go-lxc.v2"
)

const (
Expand Down Expand Up @@ -252,22 +252,22 @@ func (d *Driver) handleFingerprint(ctx context.Context, ch chan<- *drivers.Finge
func (d *Driver) buildFingerprint() *drivers.Fingerprint {
var health drivers.HealthState
var desc string
attrs := map[string]string{}
attrs := map[string]*pstructs.Attribute{}

lxcVersion := lxc.Version()

if d.config.Enabled && lxcVersion != "" {
health = drivers.HealthStateHealthy
desc = "ready"
attrs["driver.lxc"] = "1"
attrs["driver.lxc.version"] = lxcVersion
attrs["driver.lxc"] = pstructs.NewBoolAttribute(true)
attrs["driver.lxc.version"] = pstructs.NewStringAttribute(lxcVersion)
} else {
health = drivers.HealthStateUndetected
desc = "disabled"
}

if d.config.AllowVolumes {
attrs["driver.lxc.volumes.enabled"] = "1"
attrs["driver.lxc.volumes.enabled"] = pstructs.NewBoolAttribute(true)
}

return &drivers.Fingerprint{
Expand Down
6 changes: 3 additions & 3 deletions drivers/lxc/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func TestLXCDriver_Fingerprint(t *testing.T) {
select {
case finger := <-fingerCh:
require.Equal(drivers.HealthStateHealthy, finger.Health)
require.Equal("1", finger.Attributes["driver.lxc"])
require.NotEmpty(finger.Attributes["driver.lxc.version"])
require.True(finger.Attributes["driver.lxc"].GetBool())
require.NotEmpty(finger.Attributes["driver.lxc.version"].GetString())
case <-time.After(time.Duration(testutil.TestMultiplier()*5) * time.Second):
require.Fail("timeout receiving fingerprint")
}
Expand All @@ -62,7 +62,7 @@ func TestLXCDriver_FingerprintNotEnabled(t *testing.T) {
select {
case finger := <-fingerCh:
require.Equal(drivers.HealthStateUndetected, finger.Health)
require.Equal("", finger.Attributes["driver.lxc"])
require.Empty(finger.Attributes["driver.lxc"])
require.Empty(finger.Attributes["driver.lxc.version"])
case <-time.After(time.Duration(testutil.TestMultiplier()*5) * time.Second):
require.Fail("timeout receiving fingerprint")
Expand Down
7 changes: 4 additions & 3 deletions drivers/mock/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/hashicorp/nomad/plugins/drivers"
"github.com/hashicorp/nomad/plugins/shared/hclspec"
"github.com/hashicorp/nomad/plugins/shared/loader"
pstructs "github.com/hashicorp/nomad/plugins/shared/structs"
)

const (
Expand Down Expand Up @@ -269,18 +270,18 @@ func (d *Driver) handleFingerprint(ctx context.Context, ch chan *drivers.Fingerp
func (d *Driver) buildFingerprint() *drivers.Fingerprint {
var health drivers.HealthState
var desc string
attrs := map[string]string{}
attrs := map[string]*pstructs.Attribute{}
if !d.shutdownFingerprintTime.IsZero() && time.Now().After(d.shutdownFingerprintTime) {
health = drivers.HealthStateUndetected
desc = "disabled"
} else {
health = drivers.HealthStateHealthy
attrs["driver.mock"] = "1"
attrs["driver.mock"] = pstructs.NewBoolAttribute(true)
desc = "ready"
}

return &drivers.Fingerprint{
Attributes: map[string]string{},
Attributes: attrs,
Health: health,
HealthDescription: desc,
}
Expand Down
9 changes: 5 additions & 4 deletions drivers/qemu/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/hashicorp/nomad/plugins/shared"
"github.com/hashicorp/nomad/plugins/shared/hclspec"
"github.com/hashicorp/nomad/plugins/shared/loader"
pstructs "github.com/hashicorp/nomad/plugins/shared/structs"
)

const (
Expand Down Expand Up @@ -206,7 +207,7 @@ func (d *Driver) handleFingerprint(ctx context.Context, ch chan *drivers.Fingerp

func (d *Driver) buildFingerprint() *drivers.Fingerprint {
fingerprint := &drivers.Fingerprint{
Attributes: map[string]string{},
Attributes: map[string]*pstructs.Attribute{},
Health: drivers.HealthStateHealthy,
HealthDescription: "ready",
}
Expand Down Expand Up @@ -234,8 +235,8 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint {
return fingerprint
}
currentQemuVersion := matches[1]
fingerprint.Attributes[driverAttr] = "1"
fingerprint.Attributes[driverVersionAttr] = currentQemuVersion
fingerprint.Attributes[driverAttr] = pstructs.NewBoolAttribute(true)
fingerprint.Attributes[driverVersionAttr] = pstructs.NewStringAttribute(currentQemuVersion)
return fingerprint
}

Expand Down Expand Up @@ -610,7 +611,7 @@ func (d *Driver) handleWait(ctx context.Context, handle *taskHandle, ch chan *dr
func (d *Driver) getMonitorPath(dir string, fingerPrint *drivers.Fingerprint) (string, error) {
var longPathSupport bool
currentQemuVer := fingerPrint.Attributes[driverVersionAttr]
currentQemuSemver := semver.New(currentQemuVer)
currentQemuSemver := semver.New(currentQemuVer.GoString())
if currentQemuSemver.LessThan(*qemuVersionLongSocketPathFix) {
longPathSupport = false
d.logger.Debug("long socket paths are not available in this version of QEMU", "version", currentQemuVer)
Expand Down
Loading

0 comments on commit be65442

Please sign in to comment.