diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 7f97f2aae..3d03f065f 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -27,9 +27,13 @@ import ( "container/heap" "math" + hcodec "github.com/hashicorp/go-msgpack/codec" + multierror "github.com/hashicorp/go-multierror" + + psstructs "github.com/hashicorp/nomad/plugins/shared/structs" + "github.com/gorhill/cronexpr" "github.com/hashicorp/consul/api" - multierror "github.com/hashicorp/go-multierror" "github.com/hashicorp/go-version" "github.com/hashicorp/nomad/acl" "github.com/hashicorp/nomad/helper" @@ -38,8 +42,6 @@ import ( "github.com/hashicorp/nomad/lib/kheap" "github.com/mitchellh/copystructure" "github.com/ugorji/go/codec" - - hcodec "github.com/hashicorp/go-msgpack/codec" ) var ( @@ -2388,7 +2390,7 @@ type NodeDeviceResource struct { Type string Name string Instances []*NodeDevice - Attributes map[string]string + Attributes map[string]*psstructs.Attribute } func (n *NodeDeviceResource) ID() *DeviceIdTuple { @@ -2420,7 +2422,7 @@ func (n *NodeDeviceResource) Copy() *NodeDeviceResource { } // Copy the Attributes - nn.Attributes = helper.CopyMapStringString(nn.Attributes) + nn.Attributes = psstructs.CopyMapStringAttribute(nn.Attributes) return &nn } diff --git a/plugins/shared/structs/attribute.go b/plugins/shared/structs/attribute.go index a426bc422..1d88db4ec 100644 --- a/plugins/shared/structs/attribute.go +++ b/plugins/shared/structs/attribute.go @@ -72,6 +72,27 @@ type Attribute struct { Unit string } +func (a *Attribute) Copy() *Attribute { + ca := &Attribute{ + Unit: a.Unit, + } + + if a.Float != nil { + ca.Float = helper.Float64ToPtr(*a.Float) + } + if a.Int != nil { + ca.Int = helper.Int64ToPtr(*a.Int) + } + if a.Bool != nil { + ca.Bool = helper.BoolToPtr(*a.Bool) + } + if a.String != nil { + ca.String = helper.StringToPtr(*a.String) + } + + return ca +} + // GoString returns a string representation of the attribute func (a *Attribute) GoString() string { if a == nil { diff --git a/plugins/shared/structs/util.go b/plugins/shared/structs/util.go index 5f84fc4ad..240335571 100644 --- a/plugins/shared/structs/util.go +++ b/plugins/shared/structs/util.go @@ -88,3 +88,16 @@ func Pow(a, b int64) int64 { } return p } + +// CopyMapStringAttribute copies a map of string to Attribute +func CopyMapStringAttribute(in map[string]*Attribute) map[string]*Attribute { + if in == nil { + return nil + } + + out := make(map[string]*Attribute, len(in)) + for k, v := range in { + out[k] = v.Copy() + } + return out +}