Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport of api: remove mapstructure tags fromPort struct into release/1.3.x #15184

Conversation

hc-github-team-nomad-core
Copy link
Contributor

Backport

This PR is auto-generated from #12916 to be assessed for backporting due to the inclusion of the label backport/1.3.x.

WARNING automatic cherry-pick of commits failed. Commits will require human attention.

The below text is copied from the body of the original PR.


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

@hc-github-team-nomad-core hc-github-team-nomad-core force-pushed the backport/b-event-stream-dynamic-ports/informally-musical-marmot branch 2 times, most recently from 0c0e850 to 5bdfa67 Compare November 8, 2022 10:27
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>
@pkazmierczak pkazmierczak force-pushed the backport/b-event-stream-dynamic-ports/informally-musical-marmot branch from 5bdfa67 to 294e103 Compare November 8, 2022 11:41
@pkazmierczak pkazmierczak merged commit 875efd9 into release/1.3.x Nov 8, 2022
@pkazmierczak pkazmierczak deleted the backport/b-event-stream-dynamic-ports/informally-musical-marmot branch November 8, 2022 14:44
@github-actions
Copy link

github-actions bot commented Mar 9, 2023

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants