diff --git a/.gitignore b/.gitignore index 86c932ad7..ee886f92b 100644 --- a/.gitignore +++ b/.gitignore @@ -48,6 +48,8 @@ example.nomad nomad_linux_amd64 nomad_darwin_amd64 TODO.md +*.generated.go + .terraform *.tfstate* diff --git a/GNUmakefile b/GNUmakefile index 118645cc2..2f09d5948 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -13,10 +13,10 @@ GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*") all: test -dev: format +dev: format generate @NOMAD_DEV=1 sh -c "'$(PWD)/scripts/build.sh'" -bin: +bin: generate @sh -c "'$(PWD)/scripts/build.sh'" release: @@ -26,7 +26,7 @@ cov: gocov test ./... | gocov-html > /tmp/coverage.html open /tmp/coverage.html -test: +test: generate @sh -c "'$(PWD)/scripts/test.sh'" @$(MAKE) vet @@ -37,6 +37,10 @@ format: @echo "--> Running go fmt" @go fmt $(PACKAGES) +generate: + @echo "--> Running go generate" + @go generate $(PACKAGES) + vet: @go tool vet 2>/dev/null ; if [ $$? -eq 3 ]; then \ go get golang.org/x/tools/cmd/vet; \ diff --git a/nomad/core_sched_test.go b/nomad/core_sched_test.go index 7ef97a510..249b071f9 100644 --- a/nomad/core_sched_test.go +++ b/nomad/core_sched_test.go @@ -407,4 +407,3 @@ func TestCoreScheduler_JobGC_Force(t *testing.T) { } } } - diff --git a/nomad/fsm.go b/nomad/fsm.go index 7e9a57f3f..74449d17c 100644 --- a/nomad/fsm.go +++ b/nomad/fsm.go @@ -7,10 +7,10 @@ import ( "time" "github.com/armon/go-metrics" - "github.com/hashicorp/go-msgpack/codec" "github.com/hashicorp/nomad/nomad/state" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/raft" + "github.com/ugorji/go/codec" ) const ( diff --git a/nomad/rpc.go b/nomad/rpc.go index e52e258f0..a25566f11 100644 --- a/nomad/rpc.go +++ b/nomad/rpc.go @@ -55,13 +55,13 @@ const ( // NewClientCodec returns a new rpc.ClientCodec to be used to make RPC calls to // the Nomad Server. func NewClientCodec(conn io.ReadWriteCloser) rpc.ClientCodec { - return msgpackrpc.NewCodecFromHandle(true, true, conn, structs.MsgpackHandle) + return msgpackrpc.NewCodecFromHandle(true, true, conn, structs.HashiMsgpackHandle) } // NewServerCodec returns a new rpc.ServerCodec to be used by the Nomad Server // to handle rpcs. func NewServerCodec(conn io.ReadWriteCloser) rpc.ServerCodec { - return msgpackrpc.NewCodecFromHandle(true, true, conn, structs.MsgpackHandle) + return msgpackrpc.NewCodecFromHandle(true, true, conn, structs.HashiMsgpackHandle) } // listen is used to listen for incoming RPC connections diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index c79878383..1e19f6973 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -13,11 +13,13 @@ import ( "time" "github.com/gorhill/cronexpr" - "github.com/hashicorp/go-msgpack/codec" "github.com/hashicorp/go-multierror" "github.com/hashicorp/go-version" "github.com/hashicorp/nomad/helper/args" "github.com/mitchellh/copystructure" + "github.com/ugorji/go/codec" + + hcodec "github.com/hashicorp/go-msgpack/codec" ) var ( @@ -2501,6 +2503,16 @@ var MsgpackHandle = func() *codec.MsgpackHandle { return h }() +var HashiMsgpackHandle = func() *hcodec.MsgpackHandle { + h := &hcodec.MsgpackHandle{RawToString: true} + + // Sets the default type for decoding a map into a nil interface{}. + // This is necessary in particular because we store the driver configs as a + // nil interface{}. + h.MapType = reflect.TypeOf(map[string]interface{}(nil)) + return h +}() + // Decode is used to decode a MsgPack encoded object func Decode(buf []byte, out interface{}) error { return codec.NewDecoder(bytes.NewReader(buf), MsgpackHandle).Decode(out) diff --git a/nomad/structs/structs_codegen.go b/nomad/structs/structs_codegen.go new file mode 100644 index 000000000..0ed7c3dc5 --- /dev/null +++ b/nomad/structs/structs_codegen.go @@ -0,0 +1,3 @@ +package structs + +//go:generate codecgen -o structs.generated.go structs.go diff --git a/nomad/timetable.go b/nomad/timetable.go index 36076ce4a..faa97f6f7 100644 --- a/nomad/timetable.go +++ b/nomad/timetable.go @@ -5,7 +5,7 @@ import ( "sync" "time" - "github.com/hashicorp/go-msgpack/codec" + "github.com/ugorji/go/codec" ) // TimeTable is used to associate a Raft index with a timestamp. diff --git a/nomad/timetable_test.go b/nomad/timetable_test.go index a76446a13..4bc879ed7 100644 --- a/nomad/timetable_test.go +++ b/nomad/timetable_test.go @@ -6,8 +6,8 @@ import ( "testing" "time" - "github.com/hashicorp/go-msgpack/codec" "github.com/hashicorp/nomad/nomad/structs" + "github.com/ugorji/go/codec" ) func TestTimeTable(t *testing.T) {