From eef81c3b4f400a3a01705b410f3440c51b7cd12e Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Fri, 10 Apr 2020 17:44:19 -0600 Subject: [PATCH] structs: fix compatibility between api and nomad/structs proxy definitions The field names within the structs representing the Connect proxy definition were not the same (nomad/structs/ vs api/), causing the values to be lost in translation for the 'nomad job inspect' command. Since the field names already shipped in v0.11.0 we cannot simply fix the names. Instead, use the json struct tag on the structs/ structs to remap the name to match the publicly expose api/ package on json encoding. This means existing jobs from v0.11.0 will continue to work, and the JSON API for job submission will remain backwards compatible. --- contributing/checklist-jobspec.md | 1 + nomad/structs/services.go | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/contributing/checklist-jobspec.md b/contributing/checklist-jobspec.md index 83db385f850e..5d6215124b4d 100644 --- a/contributing/checklist-jobspec.md +++ b/contributing/checklist-jobspec.md @@ -15,6 +15,7 @@ * [ ] Add structs/fields to `nomad/structs` package * Validation happens in this package and must be implemented * Implement other methods and tests from `api/` package + * Note that analogous struct field names should match with `api/` package * [ ] Add conversion between `api/` and `nomad/structs` in `command/agent/job_endpoint.go` * [ ] Add check for job diff in `nomad/structs/diff.go` * Note that fields must be listed in alphabetical order in `FieldDiff` slices in `nomad/structs/diff_test.go` diff --git a/nomad/structs/services.go b/nomad/structs/services.go index d12bb697f986..578b1dd22e3e 100644 --- a/nomad/structs/services.go +++ b/nomad/structs/services.go @@ -889,7 +889,9 @@ type ConsulProxy struct { // Expose configures the consul proxy.expose stanza to "open up" endpoints // used by task-group level service checks using HTTP or gRPC protocols. - Expose *ConsulExposeConfig + // + // Use json tag to match with field name in api/ + Expose *ConsulExposeConfig `json:"ExposeConfig"` // Config is a proxy configuration. It is opaque to Nomad and passed // directly to Consul. @@ -905,7 +907,7 @@ func (p *ConsulProxy) Copy() *ConsulProxy { newP := &ConsulProxy{ LocalServiceAddress: p.LocalServiceAddress, LocalServicePort: p.LocalServicePort, - Expose: p.Expose, + Expose: p.Expose.Copy(), } if n := len(p.Upstreams); n > 0 { @@ -1009,7 +1011,8 @@ func (u *ConsulUpstream) Equals(o *ConsulUpstream) bool { // ExposeConfig represents a Consul Connect expose jobspec stanza. type ConsulExposeConfig struct { - Paths []ConsulExposePath + // Use json tag to match with field name in api/ + Paths []ConsulExposePath `json:"Path"` } type ConsulExposePath struct {