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

Check for nil values when parsing HCL strings #25294

Merged
merged 3 commits into from
Mar 6, 2025

Conversation

Juanadelacuesta
Copy link
Member

@Juanadelacuesta Juanadelacuesta commented Mar 5, 2025

Nomad panics when parsing a job specification which contains a kill_timeout that is null.
This is normally caught with a validation error, but if the null is provided via a ternary expression false ? "5s" : null Nomad panics instead.

It fixes 25292

I couldn't find any other places where not checking the nil value could lead to a panic.

Description

Testing & Reproduction steps

Links

Contributor Checklist

  • Changelog Entry If this PR changes user-facing behavior, please generate and add a
    changelog entry using the make cl command.
  • Testing Please add tests to cover any new functionality or to demonstrate bug fixes and
    ensure regressions will be caught.
  • Documentation If the change impacts user-facing functionality such as the CLI, API, UI,
    and job configuration, please update the Nomad website documentation to reflect this. Refer to
    the website README for docs guidelines. Please also consider whether the
    change requires notes within the upgrade guide.

Reviewer Checklist

  • Backport Labels Please add the correct backport labels as described by the internal
    backporting document.
  • Commit Type Ensure the correct merge method is selected which should be "squash and merge"
    in the majority of situations. The main exceptions are long-lived feature branches or merges where
    history should be preserved.
  • Enterprise PRs If this is an enterprise only PR, please add any required changelog entry
    within the public repository.

Sorry, something went wrong.

…tion if present
@Juanadelacuesta Juanadelacuesta changed the title fix: when parsing hcl durations, check for nil values and fail valida… Check for nil values when parsing HCL strings Mar 5, 2025
@Juanadelacuesta Juanadelacuesta added backport/ent/1.7.x+ent Changes are backported to 1.7.x+ent backport/ent/1.8.x+ent Changes are backported to 1.8.x+ent backport/1.9.x backport to 1.9.x release line labels Mar 5, 2025
Copy link
Member

@tgross tgross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Tested with both the job plan command and the Parse API:

$ nomad job plan /tmp/example.nomad.hcl
Error getting job struct: Error parsing job file from /tmp/example.nomad.hcl:
example.nomad.hcl:11,22-27: Unsuitable value; Unsuitable duration value: nil

$ curl \
    --request POST \
    --data @payload.json \
    http://localhost:4646/v1/jobs/parse

Failed to parse job: input.hcl:11,22-27: Unsuitable value; Unsuitable duration value: nil%

@Juanadelacuesta Juanadelacuesta merged commit 69c2ed5 into main Mar 6, 2025
31 checks passed
@Juanadelacuesta Juanadelacuesta deleted the b-gh-25292-duration branch March 6, 2025 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/ent/1.7.x+ent Changes are backported to 1.7.x+ent backport/ent/1.8.x+ent Changes are backported to 1.8.x+ent backport/1.9.x backport to 1.9.x release line
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nomad panics parsing a HCL file with a null duration in a ternary expression
2 participants