open-nomad/jobspec
Derek Strickland 80b6f27efd
api: remove mapstructure tags fromPort struct (#12916)
This PR solves a defect in the deserialization of api.Port structs when returning structs from theEventStream.

Previously, the api.Port struct's fields were decorated with both mapstructure and hcl tags to support the network.port stanza's use of the keyword static when posting a static port value. This works fine when posting a job and when retrieving any struct that has an embedded api.Port instance as long as the value is deserialized using JSON decoding. The EventStream, however, uses mapstructure to decode event payloads in the api package. mapstructure expects an underlying field named static which does not exist. The result was that the Port.Value field would always be set to 0.

Upon further inspection, a few things became apparent.

The struct already has hcl tags that support the indirection during job submission.
Serialization/deserialization with both the json and hcl packages produce the desired result.
The use of of the mapstructure tags provided no value as the Port struct contains only fields with primitive types.
This PR:

Removes the mapstructure tags from the api.Port structs
Updates the job parsing logic to use hcl instead of mapstructure when decoding Port instances.
Closes #11044

Co-authored-by: DerekStrickland <dstrickland@hashicorp.com>
Co-authored-by: Piotr Kazmierczak <470696+pkazmierczak@users.noreply.github.com>
2022-11-08 11:26:28 +01:00
..
test-fixtures api: remove mapstructure tags fromPort struct (#12916) 2022-11-08 11:26:28 +01:00
helper.go template: use pointer values for gid and uid (#14203) 2022-08-22 16:25:49 -04:00
helper_test.go template: use pointer values for gid and uid (#14203) 2022-08-22 16:25:49 -04:00
parse.go
parse_group.go
parse_job.go
parse_multiregion.go
parse_network.go api: remove mapstructure tags fromPort struct (#12916) 2022-11-08 11:26:28 +01:00
parse_service.go
parse_task.go template: error on missing key (#15141) 2022-11-04 13:23:01 -04:00
parse_test.go api: remove mapstructure tags fromPort struct (#12916) 2022-11-08 11:26:28 +01:00
utils.go
utils_test.go