-
Notifications
You must be signed in to change notification settings - Fork 121
direct: Resolve ${resources.group.key.id} and order deployment accordingly #3390
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
Conversation
|
1e71956 to
92897e8
Compare
## Changes Improve error message when converting typed struct to dynamic. ## Why Currently different functions share the message body, so you don't know which field failed to convert. Real example when working on #3390 test acceptance/bundle/deploy/jobs/double-underscore-keys triggers this error condition: Before this change "bundle deploy" fails with: ``` Warn: unable to convert typed configuration to dynamic configuration: unhandled type: string Error: exit error: unhandled type: string ``` After: ``` Warn: unable to convert typed configuration to dynamic configuration: cannot convert int field to dynamic type "string": src=4611686018427387911 ref="4611686018427387911" Error: exit error: cannot convert int field to dynamic type "string": src=4611686018427387911 ref="4611686018427387911" ``` ## Tests Manually, by applying this commit on #3390
92897e8 to
671ac12
Compare
bundle/terranova/graph.go
Outdated
| return errors.New("internal error: no db entry") | ||
| } | ||
|
|
||
| bundle.ApplyFuncContext(ctx, b, func(ctx context.Context, b *bundle.Bundle) { |
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.
Why does it need to be inside ApplyFuncContext call and not just Config.Mutate?
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.
ApplyFuncContext ensures that dynamic configuration is copied back to typed one.
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.
Discussed offline. At this moment, we never read typed configuration, so we can postpone this conversion and save some time there. Removed ApplyFunContext - all tests still pass.
bundle/terranova/graph.go
Outdated
| if err != nil { | ||
| return root, err | ||
| } | ||
| root, diags := convert.Normalize(b.Config, root) |
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.
Why do we need to normalise here?
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.
Added this comment in the code:
+ // Following resolve_variable_references.go, normalize after variable substitution.
+ // This fixes the following case: ${resources.jobs.foo.id} is replaced by string "12345"
+ // This string corresponds to job_id integer field. Normalization converts "12345" to 12345.
+ // Without normalization there will be an error when converting dynamic value to typed.
root, diags := convert.Normalize(b.Config, root)
| } | ||
|
|
||
| func (g *Graph[N]) AddDirectedEdge(from, to N, label string) error { | ||
| if from == to { |
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.
Don't we want to avoid self loops?
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.
We want to, but we already have diagnostics for loops. I've added new tests with both regular and self loops.
Co-authored-by: Pieter Noordhuis <pieter.noordhuis@databricks.com>
fef7ba0 to
52f4575
Compare
| return | ||
| } | ||
| if actionType == deployplan.ActionTypeUnset { | ||
| return |
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.
Is this no longer an internal error?
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.
it should be. restored.
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.
I got that wrong. This comment explains what should happen 6c3356a
|
|
||
| // Extract unresolved references from a given node only. | ||
| // We need to do it here because we're constantly resolving references, so that's where we have latest version. | ||
| myReferences, err := extractReferences(b.Config.Value(), node) |
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.
IIRC this referred to a commented out log line.
| } | ||
|
|
||
| func validateRef(root dyn.Value, ref string) (string, string, error) { | ||
| items := strings.Split(ref, ".") |
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.
It now uses a mix of split and dyn.NewPath below. Easier to only use dyn.Path.
Changes
The "${resources...id}" references are now substituted by direct deployment backend. They are used to build DAG both during planning and apply.
Tests
New test that check jobs update, pipeline recreation and reference going into integer field.
All existing tests that were disabled due to lack of
${resources}support are enabled.