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

backfill region from hcl for jobUpdate and jobPlan #5664

Merged
merged 1 commit into from
Jun 13, 2019

Conversation

jazzyfresh
Copy link
Contributor

@jazzyfresh jazzyfresh commented May 8, 2019

Overview

This pull request is about region precedence in a job (http args > hcl job config > defaults). This feature adds a check in the jobPlan & jobUpdate http endpoints: it checks the hcl arg for region if none is provided in the region arg, and otherwise defaults to a "global" region.

Implementation

  • In the command agent server, in the jobPlan & jobUpdate endpoints, we now backfill the region from the job hcl, if it is not already present in the http request as a separate parameter.
  • I fixed a bug where we were persisting stale Job data to the Nomad internal datastore
  • I fixed a bunch of tests that broke because they were using invalid region values (these tests passed because previous behavior ignored job hcl region and defaulted to "global", but my fix now picks up the invalid region value and the server rejects the job; so I fixed these tests to use the default region value "global").
    • I changed several tests back because they were depending on special values of region (TLS tests are looking for a Nomad server name with "regionFoo" because of hard-coded certificate test data)

Behavior

Existing behavior:

  • When a user submits a job via the CLI, the CLI tool parses the job hcl for a region, and then adds that to the http request as a region parameter separate from the job hcl parameter.
  • The UI submits a job via HTTP (bypassing the CLI parsing), which passes the region value inside the job hcl arg

New behavior:

  • This feature adds a check in the jobPlan & jobUpdate http endpoints: it checks the hcl arg for region if none is provided in the region arg, and otherwise defaults to a "global" region.
  • This feature preserves existing behavior for backwards compatibility.
region present in http arg region present in job hcl result
yes yes http region takes precedence
yes no http region takes precedence
no yes hcl takes precedence
no no default to global

This is ready for review

@hashicorp-cla
Copy link

hashicorp-cla commented May 8, 2019

CLA assistant check
All committers have signed the CLA.

@preetapan preetapan requested a review from endocrimes May 8, 2019 21:35
Copy link
Contributor

@notnoop notnoop left a comment

Choose a reason for hiding this comment

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

q q about job Region being nil - but code lgtm otherwise.

command/agent/job_endpoint.go Outdated Show resolved Hide resolved
command/agent/job_endpoint_test.go Outdated Show resolved Hide resolved
command/agent/job_endpoint.go Outdated Show resolved Hide resolved
command/agent/job_endpoint.go Outdated Show resolved Hide resolved
command/agent/job_endpoint.go Outdated Show resolved Hide resolved
command/agent/job_endpoint_test.go Outdated Show resolved Hide resolved
@endocrimes
Copy link
Contributor

We'll also need to update the command/util_test.go helpers to default to the global region, which may involve also updating some other tests. The Config Region being ignored resulted in a few accidentally passing tests where job registration happens 😞

Copy link
Contributor

@endocrimes endocrimes left a comment

Choose a reason for hiding this comment

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

This is looking really good! - All that's left is updating the jobPlan code then it lgtm!

command/agent/job_endpoint.go Outdated Show resolved Hide resolved
command/agent/job_endpoint_test.go Outdated Show resolved Hide resolved
@jazzyfresh
Copy link
Contributor Author

@endocrimes I made the suggested changes. I am just holding off on merging to make sure all the travis tests pass.

@jazzyfresh
Copy link
Contributor Author

I forgot I also have to update the jobPlanRegion test. I am giving it parameterized test cases like jobUpdateRegion, but let me know if that is overkill

@jazzyfresh
Copy link
Contributor Author

jazzyfresh commented Jun 11, 2019

It looks like one more TLS bug fix is necessary. Now it's failing for the right reasons (there is no path to the "regionFoo" region) https://travis-ci.org/hashicorp/nomad/jobs/544292291#L620

UPDATE: not all TLS tests require "regionFoo", some had originally used "global"

Copy link
Contributor

@preetapan preetapan left a comment

Choose a reason for hiding this comment

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

Looks ready to merge to me, but @endocrimes should give it the final thumbs up

Copy link
Contributor

@endocrimes endocrimes left a comment

Choose a reason for hiding this comment

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

celebratory dog

This is great - thanks for getting all of the tests updated! 🎉

- updated region in job metadata that gets persisted to nomad datastore
- fixed many unrelated unit tests that used an invalid region value
(they previously passed because hcl wasn't getting picked up and
the job would default to global region)
@jazzyfresh jazzyfresh merged commit ce55bf5 into master Jun 13, 2019
@endocrimes endocrimes deleted the f-http-hcl-region branch June 13, 2019 19:34
@github-actions
Copy link

github-actions bot commented Feb 8, 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 Feb 8, 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.

5 participants