-
Notifications
You must be signed in to change notification settings - Fork 54
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
[f-nested-deps] Remove requirement to have root pack name in overrides #426
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
35bcd73
Store root pack in the parser v2 config
angrycub 211ea17
Update test fixtures
angrycub 2924670
Update tests
angrycub 9abacbb
Add tests for NewParserV2
angrycub 0affa93
Update generate varfile output
angrycub 6862db5
Incorporate review feedback
angrycub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
deps_test_1.job_name = "A" | ||
deps_test_1.child1.job_name = "A.1" | ||
deps_test_1.child1.gc.job_name = "A.1.a" | ||
deps_test_1.child2.job_name = "A.2" | ||
deps_test_1.child2.gc.job_name = "A.2.a" | ||
job_name = "A" | ||
child1.job_name = "A.1" | ||
child1.gc.job_name = "A.1.a" | ||
child2.job_name = "A.2" | ||
child2.gc.job_name = "A.2.a" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
simple_raw_exec.job_name = "sre" | ||
job_name = "sre" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
simple_raw_exec.env = { | ||
env = { | ||
"NOMAD_TOKEN" = "some awesome token" | ||
"NOMAD_ADDR" = "http://127.0.0.1:4646" | ||
} | ||
|
||
simple_raw_exec.job_name = "sre" | ||
job_name = "sre" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
variable_test_pack.input = "varfile" | ||
input = "varfile" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,13 +13,15 @@ import ( | |
"github.com/hashicorp/nomad-pack/sdk/pack/variables" | ||
) | ||
|
||
func DecodeVariableOverrides(files []*pack.File) DecodeResult { | ||
// TODO: this is only used in a test - remove? | ||
func DecodeVariableOverrides(root *pack.Pack, files []*pack.File) DecodeResult { | ||
decodeResult := DecodeResult{} | ||
for _, file := range files { | ||
fileDecodeResult := DecodeResult{ | ||
Overrides: make(variables.Overrides), | ||
} | ||
fileDecodeResult.HCLFiles, fileDecodeResult.Diags = Decode(file.Name, file.Content, nil, &fileDecodeResult.Overrides) | ||
|
||
fileDecodeResult.HCLFiles, fileDecodeResult.Diags = Decode(root, file.Name, file.Content, nil, &fileDecodeResult.Overrides) | ||
decodeResult.Merge(fileDecodeResult) | ||
} | ||
return decodeResult | ||
|
@@ -117,8 +119,8 @@ func (d *DecodeResult) Merge(in DecodeResult) { | |
|
||
// Decode parses, decodes, and evaluates expressions in the given HCL source | ||
// code, in a single step. | ||
func Decode(filename string, src []byte, ctx *hcl.EvalContext, target *variables.Overrides) (map[string]*hcl.File, hcl.Diagnostics) { | ||
fm, diags := decode(filename, src, ctx, target) | ||
func Decode(root *pack.Pack, filename string, src []byte, ctx *hcl.EvalContext, target *variables.Overrides) (map[string]*hcl.File, hcl.Diagnostics) { | ||
fm, diags := decode(root, filename, src, ctx, target) | ||
var fd = fixableDiags(diags) | ||
|
||
fm.Fixup() // the hcl.File that we will return to the diagnostic printer will have our modifications | ||
|
@@ -129,7 +131,7 @@ func Decode(filename string, src []byte, ctx *hcl.EvalContext, target *variables | |
|
||
// Decode parses, decodes, and evaluates expressions in the given HCL source | ||
// code, in a single step. | ||
func decode(filename string, src []byte, ctx *hcl.EvalContext, target *variables.Overrides) (diagFileMap, hcl.Diagnostics) { | ||
func decode(root *pack.Pack, filename string, src []byte, ctx *hcl.EvalContext, target *variables.Overrides) (diagFileMap, hcl.Diagnostics) { | ||
var file *hcl.File | ||
var diags hcl.Diagnostics | ||
|
||
|
@@ -204,6 +206,8 @@ func decode(filename string, src []byte, ctx *hcl.EvalContext, target *variables | |
steps = strings.Split(k.AsString(), ".") | ||
|
||
case 1: | ||
// NOTE: traversalToName is recursive | ||
|
||
// In the HCL case, we have to read the traversal to get the path parts. | ||
steps = traversalToName(keyVars[0]) | ||
|
||
|
@@ -217,9 +221,30 @@ func decode(filename string, src []byte, ctx *hcl.EvalContext, target *variables | |
oRange := hcl.RangeBetween(kv.Key.Range(), kv.Value.Range()) | ||
fixupRange(&oRange) | ||
|
||
var path pack.ID | ||
var name variables.ID | ||
|
||
// NOTE: This implementation assumes a single element variable value, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that's fine for now but maybe make an issue so that we could revisit later? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created issue #435 to capture this |
||
// which specifically breaks setting a sub-element value. The more | ||
// correct way is to perform the traversal based on the provided root | ||
// pack | ||
|
||
if len(steps) < 2 { | ||
name = variables.ID(steps[len(steps)-1]) | ||
path = root.ID() | ||
} else { | ||
name = variables.ID(steps[len(steps)-1]) | ||
path = pack.ID(strings.Join( | ||
append( | ||
[]string{root.ID().String()}, | ||
steps[0:len(steps)-1]..., | ||
), | ||
".")) | ||
} | ||
|
||
val := variables.Override{ | ||
Name: variables.ID(steps[len(steps)-1]), | ||
Path: pack.ID(strings.Join(steps[0:len(steps)-1], ".")), | ||
Name: name, | ||
Path: path, | ||
Value: value, | ||
Type: value.Type(), | ||
Range: oRange, | ||
|
@@ -228,6 +253,7 @@ func decode(filename string, src []byte, ctx *hcl.EvalContext, target *variables | |
} | ||
|
||
if len(vals) > 0 { | ||
// What is this doing? | ||
(*target)[pack.ID(filename)] = vals | ||
} | ||
return fm, diags | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Remove.
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.
Moved into the test package