-
Notifications
You must be signed in to change notification settings - Fork 69
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
Handle ${workspace.file_path}
references in source-linked deployments
#2046
Conversation
I moved source-linked deployment preset handler in separate mutator and now it runs before variable resolution step One caveat is that this mutator uses development mode setting but it runs before |
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
@@ -41,6 +41,10 @@ func Initialize() bundle.Mutator { | |||
mutator.PopulateCurrentUser(), | |||
mutator.LoadGitDetails(), | |||
|
|||
// This mutator needs to be run before variable interpolation and defining default workspace paths | |||
// because it affects how workspace variables are resolved. | |||
mutator.ApplySourceLinkedDeploymentPreset(), |
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 moved all source-linked initialization logic to separate mutator which will is running before workspace paths is defined and variables are resolved
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.
This is concerning -- it decentralizes how we deal with mode: development
and I'd like to keep that in one place. I understand why you need to do this here, and we can merge the PR to unblock the issue in the workspace, but we should revert to the original place.
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.
@pietern what do you think would be the best approach here?
We have several constraint that are not super compatible
- we need to enable/disable source-linked before variable resolution phase (to properly compute file_path)
- source-linked deployment needs to be enabled in dev mode
- dev mode validation relies on workspace paths, which may include variables (see findNonUserPath)
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.
Instead of intercepting interpolation of ${workspace.file_path}
we could perform a modification pass after variable resolution where we replace instances of the value of this variable. Would that work?
cc @denik
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.
Let's keep on hold until @denik starts work on variable resolution v2 to see what would be the better approach
b.Config.Presets.SourceLinkedDeployment = &enabled | ||
} | ||
|
||
if b.Config.Workspace.FilePath != "" && config.IsExplicitlyEnabled(b.Config.Presets.SourceLinkedDeployment) { |
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 warning for cases when workspace.file_path
is defined by user but deploy is running in source-linked mode
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.
Please include a comment saying that this mutator runs before these fields are defaulted. I was puzzled by this but then found it is run before the mutators that populate its default value.
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.
) | ||
|
||
disabled := false | ||
b.Config.Presets.SourceLinkedDeployment = &disabled |
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.
SInce you're mutating the config here, you'd have to call b.Config.Mutate
and do all the mutation inside the callback there
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.
Thanks, I will update it! Could you elaborate what is the difference between this mutation and normal assignment to struct. Seems that it works good in both cases but I may miss some context
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 with Pieter that it's better to skip dynamic assignment here in favor of simplicity, but I can update it in another PR if it doesn't feel right
…ked-deployment-file-path
${workspace.file_path}
references in source-linked deployments
|
||
if config.IsExplicitlyEnabled((b.Config.Presets.SourceLinkedDeployment)) { | ||
if !isDatabricksWorkspace { | ||
path := dyn.NewPath(dyn.Key("targets"), dyn.Key(target), dyn.Key("presets"), dyn.Key("source_linked_deployment")) |
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.
This won't work -- the targets
field is cleared after selecting it.
But because the target is merged into the main configuration, you can use presets.source_linked_deployment
directly and it will return the original location.
b.Config.Presets.SourceLinkedDeployment = &enabled | ||
} | ||
|
||
if b.Config.Workspace.FilePath != "" && config.IsExplicitlyEnabled(b.Config.Presets.SourceLinkedDeployment) { |
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.
Please include a comment saying that this mutator runs before these fields are defaulted. I was puzzled by this but then found it is run before the mutators that populate its default value.
diags = diags.Append( | ||
diag.Diagnostic{ | ||
Severity: diag.Warning, | ||
Summary: "workspace.file_path setting will be ignored in source-linked deployment mode", |
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.
This warning should have a Detail
section explaining the issue further.
} | ||
|
||
if b.Config.Workspace.FilePath != "" && config.IsExplicitlyEnabled(b.Config.Presets.SourceLinkedDeployment) { | ||
path := dyn.NewPath(dyn.Key("targets"), dyn.Key(target), dyn.Key("workspace"), dyn.Key("file_path")) |
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.
Same issue as above w.r.t. the path not existing.
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.
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.
Ah, I was confused by the path including targets.<target>
.
This call site and the one above index it with path[2:]
.
It looks like it is not used in full, so the first two elements can be removed from the assignment.
@@ -41,6 +41,10 @@ func Initialize() bundle.Mutator { | |||
mutator.PopulateCurrentUser(), | |||
mutator.LoadGitDetails(), | |||
|
|||
// This mutator needs to be run before variable interpolation and defining default workspace paths | |||
// because it affects how workspace variables are resolved. | |||
mutator.ApplySourceLinkedDeploymentPreset(), |
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.
This is concerning -- it decentralizes how we deal with mode: development
and I'd like to keep that in one place. I understand why you need to do this here, and we can merge the PR to unblock the issue in the workspace, but we should revert to the original place.
@@ -54,5 +54,8 @@ func (m *compute) Apply(_ context.Context, b *bundle.Bundle) diag.Diagnostics { | |||
|
|||
// Set file upload destination of the bundle in metadata | |||
b.Metadata.Config.Workspace.FilePath = b.Config.Workspace.FilePath | |||
if config.IsExplicitlyEnabled(b.Config.Presets.SourceLinkedDeployment) { |
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.
Missing comment why this is done.
Bundles: * Fix finding Python within virtualenv on Windows ([#2034](#2034)). * Include missing field descriptions in JSON schema ([#2045](#2045)). * Add validation for volume referenced from `artifact_path` ([#2050](#2050)). * Handle `${workspace.file_path}` references in source-linked deployments ([#2046](#2046)). * Set the write bit for files written during template initialization ([#2068](#2068)).
Bundles: * Fix finding Python within virtualenv on Windows ([#2034](#2034)). * Include missing field descriptions in JSON schema ([#2045](#2045)). * Add validation for volume referenced from `artifact_path` ([#2050](#2050)). * Handle `${workspace.file_path}` references in source-linked deployments ([#2046](#2046)). * Set the write bit for files written during template initialization ([#2068](#2068)).
func lookup(v dyn.Value, path dyn.Path, b *bundle.Bundle) (dyn.Value, error) { | ||
if config.IsExplicitlyEnabled(b.Config.Presets.SourceLinkedDeployment) { | ||
if path.String() == "workspace.file_path" { | ||
return dyn.V(b.SyncRootPath), nil |
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 could not we just set bundle.workspace.file_path to b.SyncRootPath and let it be resolved naturally?
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 explained it here, tldr: overriding file path is nice but with new changes there is a risk to affect source files accidentally
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.
but we can revisit that
…th specified (#2119) ## Changes Resolves remaining comments from here #2046 [This](#2046 (comment)) and [this](#2046 (comment)) are on hold until Pieter's response ## Tests <!-- How is this tested? -->
Changes
workspace.file_path
during variable resolution phase in source-linked deployment to address cases like this https://github.com/databricks/bundle-examples/blob/main/default_python/resources/default_python_pipeline.yml#L13workspace.file_path
inmetadata.json
workspace.file_path
is explicitly set but deploy is running in source-linked modeTests
Unit test