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

replace worker template by a more flexible approach #82

Merged
merged 12 commits into from
Oct 26, 2021

Conversation

j3t
Copy link
Member

@j3t j3t commented Jul 27, 2021

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

I have created different plugin configuration based on v0.7.4 and added tests for them (see NomadCloudConfigurationTest). Afterwards, I have replaced the worker template by a more flexible approach and added a migration path for older configurations.

@j3t j3t force-pushed the feature-81-more-flexible-worker-template branch from 03fd9fa to e8c2f8b Compare July 28, 2021 10:08
Copy link
Member Author

@j3t j3t left a comment

Choose a reason for hiding this comment

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

added tests for previous migrations

Request.Builder builder = new Request.Builder()
.url(this.nomadApi + "/v1/job/" + workerName + "?region=" + template.getRegion());
.url(this.nomadApi + "/v1/jobs");
Copy link
Member Author

Choose a reason for hiding this comment

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

Since region and workerName are part of the job file already, we don't have to define them here explicitly.

@j3t j3t force-pushed the feature-81-more-flexible-worker-template branch 2 times, most recently from 8e94acd to e0d8cad Compare September 6, 2021 11:45
@mikedld
Copy link

mikedld commented Oct 18, 2021

Anything more to work on here @j3t? I'd love to try and add another worker driver support but would hate to interfere with whatever is happening here.

@multani
Copy link

multani commented Oct 18, 2021

@mikedld It's only waiting for my review but I didn't have time to get into this PR and test it yet :'(

@j3t
Copy link
Member Author

j3t commented Oct 19, 2021

Anything more to work on here @j3t? I'd love to try and add another worker driver support but would hate to interfere with whatever is happening here.

Hi @mikedld, it would be really nice if you could test the current state and give use feedback.You can find the build artifacts here https://ci.jenkins.io/blue/organizations/jenkins/Plugins%2Fnomad-plugin/detail/PR-82/10/artifacts. You just have to download the hpi file and then you can install it manually via Manage Jenkins -> Manage Plugins -> Advanced -> Upload Plugin.

Copy link

@multani multani left a comment

Choose a reason for hiding this comment

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

@j3t I (finally!) took a bit of time to have a look at your pull request.

Generally speaking: it's quite cool 🎉

I had a look if we could have native Nomad jobs (HCL) instead of JSON as it would be easier to write in the text area, and it would provide native support for interpolating the secret/token variables if it was supporting HCL2 but:

  • The only HCL capable Java library I found was https://github.com/bertramdev/hcl4j and it doesn't support HCL2 for the time being.
  • Migrating from the original configuration to HCL may be more challenging (in the past, I found it difficult to serialize arbitrary structure to HCL, I don't it has changed since)

Anyway:

I think it would be useful to add loggers from the migrations are executed, I would say:

  • At the very least when a worker template is migrated
  • Possibly when the whole migration is executed

Otherwise, from what I have tested, this is working great and I don't see any problem merging this soon 👍

@j3t j3t force-pushed the feature-81-more-flexible-worker-template branch from e0d8cad to 2a8fa1b Compare October 20, 2021 07:55
@j3t j3t force-pushed the feature-81-more-flexible-worker-template branch from 7952cb1 to 1a610a0 Compare October 20, 2021 08:42
@j3t
Copy link
Member Author

j3t commented Oct 20, 2021

Thanks! I have incorporated the feedback.

What is about the SpotBugs findings (UUF_UNUSED_FIELD)? I don't know how this could be solved? Is there a way to ignore them?

@j3t
Copy link
Member Author

j3t commented Oct 20, 2021

I had a look if we could have native Nomad jobs (HCL) instead of JSON as it would be easier to write in the text area, and it would provide native support for interpolating the secret/token variables if it was supporting HCL2 but:

  • The only HCL capable Java library I found was https://github.com/bertramdev/hcl4j and it doesn't support HCL2 for the time being.
  • Migrating from the original configuration to HCL may be more challenging (in the past, I found it difficult to serialize arbitrary structure to HCL, I don't it has changed since)

In general I would like to have that but as far as I know, the Nomad REST API only supports JSON. This means we have to transform HCL2 to JSON, right? There is a discussion and also some libraries available (see hashicorp/hcl#294).

Co-authored-by: Jonathan Ballet <jon@multani.info>
@j3t
Copy link
Member Author

j3t commented Oct 20, 2021

Maybe we can use the Nomad API to transform HCL to JSON (see https://www.nomadproject.io/api-docs/jobs#parse-job).

@multani
Copy link

multani commented Oct 21, 2021

I had a look if we could have native Nomad jobs (HCL) instead of JSON as it would be easier to write in the text area, and it would provide native support for interpolating the secret/token variables if it was supporting HCL2 but:

  • The only HCL capable Java library I found was https://github.com/bertramdev/hcl4j and it doesn't support HCL2 for the time being.
  • Migrating from the original configuration to HCL may be more challenging (in the past, I found it difficult to serialize arbitrary structure to HCL, I don't it has changed since)

In general I would like to have that but as far as I know, the Nomad REST API only supports JSON. This means we have to transform HCL2 to JSON, right? There is a discussion and also some libraries available (see hashicorp/hcl#294).

Maybe we can use the Nomad API to transform HCL to JSON (see https://www.nomadproject.io/api-docs/jobs#parse-job).

The API only takes JSON yes, but if it could be transformed once before submitting the job, that would be really nice!
I forgot about the /parse API, maybe that could be useful? It's available since Nomad 0.8.2 which is more than 3 years old, so I think it would be fine to support.

Also (I forgot yesterday), in any case, it would be nice if the UI could provide some basic validation of the input: at the moment, writing in a non-valid JSON "succeeds" silently when the form is submitted :)

@j3t
Copy link
Member Author

j3t commented Oct 21, 2021

I forgot about the /parse API, maybe that could be useful? It's available since Nomad 0.8.2 which is more than 3 years old, so I think it would be fine to support.

Do we really need the HCL support in the first place? I mean, we could add it later as an alternative as well.

@j3t
Copy link
Member Author

j3t commented Oct 21, 2021

Also (I forgot yesterday), in any case, it would be nice if the UI could provide some basic validation of the input: at the moment, writing in a non-valid JSON "succeeds" silently when the form is submitted :)

We could use the Nomad API for that as well (see https://www.nomadproject.io/api-docs/validate#validate-job), but I prefer a validation button for that instead of a silent validation when the form is submitted.

@multani
Copy link

multani commented Oct 22, 2021

I forgot about the /parse API, maybe that could be useful? It's available since Nomad 0.8.2 which is more than 3 years old, so I think it would be fine to support.

Do we really need the HCL support in the first place? I mean, we could add it later as an alternative as well.

If there's a good UX / migration path for supporting HCL later, it's fine by me 👍 (I don't really see how to nicely support both right now though).

Also (I forgot yesterday), in any case, it would be nice if the UI could provide some basic validation of the input: at the moment, writing in a non-valid JSON "succeeds" silently when the form is submitted :)

We could use the Nomad API for that as well (see https://www.nomadproject.io/api-docs/validate#validate-job), but I prefer a validation button for that instead of a silent validation when the form is submitted.

The validation button would be fine, yes 👍

Actually, I haven't tried to save the buggy JSON and see what the plugin would do in that case; but the earlier and clearer the error message we can get, the better it would be IMO.

From experience, when cloud workers provisioning fails for any reason (the Nomad plugin or any other plugin providing dynamic workers), it's always a PITA to debug / figure out in Jenkins.

@j3t
Copy link
Member Author

j3t commented Oct 22, 2021

I have added a validation button. Below you can find an example where the datacenter is missing:
Screenshot 2021-10-22 at 13 53 39

@j3t j3t force-pushed the feature-81-more-flexible-worker-template branch from 4415e57 to a983949 Compare October 22, 2021 12:15
@j3t
Copy link
Member Author

j3t commented Oct 22, 2021

With the /job/plan api it looks even better
Screenshot 2021-10-22 at 14 14 48
:

@j3t j3t force-pushed the feature-81-more-flexible-worker-template branch from a983949 to 2540039 Compare October 22, 2021 12:24
@j3t
Copy link
Member Author

j3t commented Oct 22, 2021

If there's a good UX / migration path for supporting HCL later, it's fine by me 👍 (I don't really see how to nicely support both right now though).

We could just allow both formats. No migration necessary at all.

@j3t j3t marked this pull request as ready for review October 25, 2021 12:48
@multani
Copy link

multani commented Oct 25, 2021

With the /job/plan api it looks even better Screenshot 2021-10-22 at 14 14 48 :

Yes, that's great!

If there's a good UX / migration path for supporting HCL later, it's fine by me +1 (I don't really see how to nicely support both right now though).

We could just allow both formats. No migration necessary at all.

OK, well let's start with this initial approach and think how to add (or not) HCL after that.

Copy link

@multani multani left a comment

Choose a reason for hiding this comment

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

Tested with the latest changes and looks good to me!

@multani multani merged commit 42015f0 into jenkinsci:master Oct 26, 2021
@multani
Copy link

multani commented Oct 26, 2021

@j3t Thanks a lot for this refactoring: this is a huge PR and I think it will help to support more Nomad features/changes in the future, this is really cool 🚀
I'll make a new pre-release with this change: hopefully it all works correctly and we can make a proper release :)

@multani
Copy link

multani commented Oct 27, 2021

I directly released a new version in https://github.com/jenkinsci/nomad-plugin/releases/tag/v0.9.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants