Skip to content

Commit

Permalink
structs: fix compatibility between api and nomad/structs proxy defini…
Browse files Browse the repository at this point in the history
…tions

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.
  • Loading branch information
shoenig committed Apr 13, 2020
1 parent dc11226 commit eef81c3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions contributing/checklist-jobspec.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
9 changes: 6 additions & 3 deletions nomad/structs/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit eef81c3

Please sign in to comment.