-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[deps] Update HCL2 to 2.17.0+tweaks #18122
Conversation
Our internal tooling has started using this 2.17.0 hcl branch because the older hcl2 branch has some bugs that have been fixed since then. Once we did that,
The following repo contains a fully reproducible example https://github.com/ghthor/nomad-bug-reports/tree/main/nomad-hcl-2.17.0-branch-pr-18122 |
Okay. That is another case where we hacked in support for old HCL shapes. Will research it and see what is missing. If you switch to the |
It looks like there are some failing test cases between this branch and main, interested why CI is not running
I'm wondering if it would be worthwhile to keep the changes required in the hcl2 fork to a minimum and perform some preprocessing of the HCL using the hclwrite package before we pass it into diff --git a/jobspec2/parse.go b/jobspec2/parse.go
index 4b91ba76f7..bd2b44664b 100644
--- a/jobspec2/parse.go
+++ b/jobspec2/parse.go
@@ -14,6 +14,7 @@ import (
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/hclsyntax"
+ "github.com/hashicorp/hcl/v2/hclwrite"
hcljson "github.com/hashicorp/hcl/v2/json"
"github.com/hashicorp/nomad/api"
)
@@ -161,9 +162,37 @@ func parseHCLOrJSON(src []byte, filename string) (*hcl.File, hcl.Diagnostics) {
return hcljson.Parse(src, filename)
}
+ src, diags := convertOldHCLFormats(src, filename)
+ if diags != nil {
+ return nil, diags
+ }
+
return hclsyntax.ParseConfig(src, filename, hcl.Pos{Line: 1, Column: 1})
}
+func convertOldHCLFormats(src []byte, filename string) ([]byte, hcl.Diagnostics) {
+ var diags hcl.Diagnostics
+
+ f, diags := hclwrite.ParseConfig(src, filename, hcl.InitialPos)
+ if diags != nil {
+ return src, diags
+ }
+
+ // TODO: preprocess old HCL shapes
+
+ var b bytes.Buffer
+ _, err := f.WriteTo(&b)
+ if err != nil {
+ return src, append(diags, &hcl.Diagnostic{
+ Severity: hcl.DiagError,
+ Summary: "failed write to buffer",
+ Detail: "failed to write hclwrite.File into a bytes.Buffer",
+ })
+ }
+
+ return b.Bytes(), nil
+}
+
func isJSON(src []byte) bool {
for _, c := range src {
if c == ' ' {
We should add some test cases for these alternative |
e1f60de
to
3a65b70
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
I've left suggestions to update from testify
to shoenig/test
assertions (we should be gradually migrating over because testify has correctness issues that can't be fixed backwards compatibly).
transition to must from require on new test Co-authored-by: Tim Gross <tgross@hashicorp.com>
more test updates Co-authored-by: Tim Gross <tgross@hashicorp.com>
Superseded #22439 |
In hashicorp/hcl#620, I created an updated version of the Nomad-tweaked HCL2 code for HCL v2.17.0. We leverage this version's
Extra
attribute of anhcl.Diagnostic
in nomad-pack.