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

nomad uses off-release hcl2 version #9918

Open
notnoop opened this issue Jan 29, 2021 · 0 comments
Open

nomad uses off-release hcl2 version #9918

notnoop opened this issue Jan 29, 2021 · 0 comments

Comments

@notnoop
Copy link
Contributor

notnoop commented Jan 29, 2021

Nomad uses an off-release hcl2 library: https://github.com/hashicorp/hcl/tree/hcl2-nomad-teaks . It branches off the main hcl2 branch, with few PRs applied: hashicorp/hcl#414, hashicorp/hcl#413, hashicorp/hcl#413 .

Context and Why

The changes primary target the gohcl, a helper package that evaluates and decodes hcl AST tree into Nomad. The library is well suited for small simple structures, and other HashiCorp use it in very limited way. However, for the complicated config structures, other HashiCorp products use different approaches: Packer uses a custom code generation framework using the hcldec library (see https://github.com/hashicorp/packer/tree/v1.6.6/hcl2template ). Terraform uses a hierarchical approach: terraform decodes the structure manually, but uses gohcl for evaluating the fine-grain attribute expressions (see https://github.com/hashicorp/terraform/blob/v0.14.5/configs/module_call.go ).

Nomad opted to push as much parsing logic into gohcl and rely on hcl: field attributes, rather than maintain hand-rolled or code generated decoders. Also, we opted to reuse the API public struct, api.Job, for target parsing: to eliminate the overhead to maintain two different projects of the config file, we frequently had with the jobspec parser; the downside is the complexity of compatibility maintenance (don't want to change the api struct fields) and avoiding inserting hclv2 dependency into the nomad api package.

The PRs above fills the gap that Nomad needs to address their needs. Understandably, these are Nomad specific requirements and don't represent the common case of gohcl users. However, I believe it's still cheaper to maintain this small fork with relatively small diff than roll a custom full decoder like other projects have gone.

Next Steps

We should aim to get these PRs across the line and merged upstream, taking the hcl2 maintainers feedback and making them useful for others. Alternatively, we should re-examine our approach so that we implement the logic outside the hcl2 library: we can maintain our own gohcl package and/or adopt Terraform/Packer approaches of reserving gohcl to small structs. Also, we can add a new job struct meant for parsing with upstream gohcl library. then convert it to api.Job.

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

No branches or pull requests

3 participants