Skip to content

Commit eef81c3

Browse files
committed
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.
1 parent dc11226 commit eef81c3

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

contributing/checklist-jobspec.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* [ ] Add structs/fields to `nomad/structs` package
1616
* Validation happens in this package and must be implemented
1717
* Implement other methods and tests from `api/` package
18+
* Note that analogous struct field names should match with `api/` package
1819
* [ ] Add conversion between `api/` and `nomad/structs` in `command/agent/job_endpoint.go`
1920
* [ ] Add check for job diff in `nomad/structs/diff.go`
2021
* Note that fields must be listed in alphabetical order in `FieldDiff` slices in `nomad/structs/diff_test.go`

nomad/structs/services.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,9 @@ type ConsulProxy struct {
889889

890890
// Expose configures the consul proxy.expose stanza to "open up" endpoints
891891
// used by task-group level service checks using HTTP or gRPC protocols.
892-
Expose *ConsulExposeConfig
892+
//
893+
// Use json tag to match with field name in api/
894+
Expose *ConsulExposeConfig `json:"ExposeConfig"`
893895

894896
// Config is a proxy configuration. It is opaque to Nomad and passed
895897
// directly to Consul.
@@ -905,7 +907,7 @@ func (p *ConsulProxy) Copy() *ConsulProxy {
905907
newP := &ConsulProxy{
906908
LocalServiceAddress: p.LocalServiceAddress,
907909
LocalServicePort: p.LocalServicePort,
908-
Expose: p.Expose,
910+
Expose: p.Expose.Copy(),
909911
}
910912

911913
if n := len(p.Upstreams); n > 0 {
@@ -1009,7 +1011,8 @@ func (u *ConsulUpstream) Equals(o *ConsulUpstream) bool {
10091011

10101012
// ExposeConfig represents a Consul Connect expose jobspec stanza.
10111013
type ConsulExposeConfig struct {
1012-
Paths []ConsulExposePath
1014+
// Use json tag to match with field name in api/
1015+
Paths []ConsulExposePath `json:"Path"`
10131016
}
10141017

10151018
type ConsulExposePath struct {

0 commit comments

Comments
 (0)