-
Notifications
You must be signed in to change notification settings - Fork 146
Config sync migrate to resource yml #4677
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
Draft
ilyakuz-db
wants to merge
3
commits into
main
Choose a base branch
from
config-sync-migrate-to-resource-yml
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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,177 +1,26 @@ | ||
| package configsync | ||
|
|
||
| import ( | ||
| "reflect" | ||
| "strings" | ||
| ) | ||
| import "github.com/databricks/cli/libs/structs/structpath" | ||
|
|
||
| type ( | ||
| skipAlways struct{} | ||
| skipIfZeroOrNil struct{} | ||
| skipIfEmptyOrDefault struct { | ||
| defaults map[string]any | ||
| } | ||
| ) | ||
|
|
||
| var ( | ||
| alwaysSkip = skipAlways{} | ||
| zeroOrNil = skipIfZeroOrNil{} | ||
| emptyEmailNotifications = skipIfEmptyOrDefault{defaults: map[string]any{"no_alert_for_skipped_runs": false}} | ||
| ) | ||
|
|
||
| // serverSideDefaults contains all hardcoded server-side defaults. | ||
| // This is a temporary solution until the bundle plan issue is resolved. | ||
| // Fields mapped to alwaysSkip are always considered defaults regardless of value. | ||
| // Other fields are compared using reflect.DeepEqual. | ||
| var serverSideDefaults = map[string]any{ | ||
| // Job-level fields | ||
| "resources.jobs.*.timeout_seconds": zeroOrNil, | ||
| "resources.jobs.*.email_notifications": emptyEmailNotifications, | ||
| "resources.jobs.*.webhook_notifications": map[string]any{}, | ||
| "resources.jobs.*.edit_mode": alwaysSkip, // set by CLI | ||
| "resources.jobs.*.performance_target": "PERFORMANCE_OPTIMIZED", | ||
|
|
||
| // Task-level fields | ||
| "resources.jobs.*.tasks[*].run_if": "ALL_SUCCESS", | ||
| "resources.jobs.*.tasks[*].disabled": false, | ||
| "resources.jobs.*.tasks[*].timeout_seconds": zeroOrNil, | ||
| "resources.jobs.*.tasks[*].notebook_task.source": "WORKSPACE", | ||
| "resources.jobs.*.tasks[*].email_notifications": emptyEmailNotifications, | ||
| "resources.jobs.*.tasks[*].webhook_notifications": map[string]any{}, | ||
| "resources.jobs.*.tasks[*].pipeline_task.full_refresh": false, | ||
|
|
||
| "resources.jobs.*.tasks[*].for_each_task.task.run_if": "ALL_SUCCESS", | ||
| "resources.jobs.*.tasks[*].for_each_task.task.disabled": false, | ||
| "resources.jobs.*.tasks[*].for_each_task.task.timeout_seconds": zeroOrNil, | ||
| "resources.jobs.*.tasks[*].for_each_task.task.notebook_task.source": "WORKSPACE", | ||
| "resources.jobs.*.tasks[*].for_each_task.task.email_notifications": emptyEmailNotifications, | ||
| "resources.jobs.*.tasks[*].for_each_task.task.webhook_notifications": map[string]any{}, | ||
|
|
||
| // Cluster fields (tasks) | ||
| "resources.jobs.*.tasks[*].new_cluster.aws_attributes": alwaysSkip, | ||
| "resources.jobs.*.tasks[*].new_cluster.azure_attributes": alwaysSkip, | ||
| "resources.jobs.*.tasks[*].new_cluster.gcp_attributes": alwaysSkip, | ||
| "resources.jobs.*.tasks[*].new_cluster.data_security_mode": "SINGLE_USER", // TODO this field is computed on some workspaces in integration tests, check why and if we can skip it | ||
| "resources.jobs.*.tasks[*].new_cluster.enable_elastic_disk": alwaysSkip, // deprecated field | ||
| "resources.jobs.*.tasks[*].new_cluster.single_user_name": alwaysSkip, | ||
|
|
||
| // Cluster fields (job_clusters) | ||
| "resources.jobs.*.job_clusters[*].new_cluster.aws_attributes": alwaysSkip, | ||
| "resources.jobs.*.job_clusters[*].new_cluster.azure_attributes": alwaysSkip, | ||
| "resources.jobs.*.job_clusters[*].new_cluster.gcp_attributes": alwaysSkip, | ||
| "resources.jobs.*.job_clusters[*].new_cluster.data_security_mode": "SINGLE_USER", // TODO this field is computed on some workspaces in integration tests, check why and if we can skip it | ||
| "resources.jobs.*.job_clusters[*].new_cluster.enable_elastic_disk": alwaysSkip, // deprecated field | ||
| "resources.jobs.*.job_clusters[*].new_cluster.single_user_name": alwaysSkip, | ||
|
|
||
| // Standalone cluster fields | ||
| "resources.clusters.*.aws_attributes": alwaysSkip, | ||
| "resources.clusters.*.azure_attributes": alwaysSkip, | ||
| "resources.clusters.*.gcp_attributes": alwaysSkip, | ||
| "resources.clusters.*.data_security_mode": "SINGLE_USER", | ||
| "resources.clusters.*.driver_node_type_id": alwaysSkip, | ||
| "resources.clusters.*.enable_elastic_disk": alwaysSkip, | ||
| "resources.clusters.*.single_user_name": alwaysSkip, | ||
|
|
||
| // Experiment fields | ||
| "resources.experiments.*.artifact_location": alwaysSkip, | ||
|
|
||
| // Registered model fields | ||
| "resources.registered_models.*.full_name": alwaysSkip, | ||
| "resources.registered_models.*.metastore_id": alwaysSkip, | ||
| "resources.registered_models.*.owner": alwaysSkip, | ||
| "resources.registered_models.*.storage_location": alwaysSkip, | ||
|
|
||
| // Volume fields | ||
| "resources.volumes.*.storage_location": alwaysSkip, | ||
|
|
||
| // SQL warehouse fields | ||
| "resources.sql_warehouses.*.creator_name": alwaysSkip, | ||
| "resources.sql_warehouses.*.min_num_clusters": int64(1), | ||
| "resources.sql_warehouses.*.warehouse_type": "CLASSIC", | ||
|
|
||
| // Terraform defaults | ||
| "resources.jobs.*.run_as": alwaysSkip, | ||
|
|
||
| // Pipeline fields | ||
| "resources.pipelines.*.storage": alwaysSkip, | ||
| "resources.pipelines.*.continuous": false, | ||
| } | ||
|
|
||
| func shouldSkipField(path string, value any) bool { | ||
| for pattern, expected := range serverSideDefaults { | ||
| if matchPattern(pattern, path) { | ||
| if _, ok := expected.(skipAlways); ok { | ||
| return true | ||
| } | ||
| if _, ok := expected.(skipIfZeroOrNil); ok { | ||
| return value == nil || value == int64(0) | ||
| } | ||
| if marker, ok := expected.(skipIfEmptyOrDefault); ok { | ||
| m, ok := value.(map[string]any) | ||
| if !ok { | ||
| return false | ||
| } | ||
| if len(m) == 0 { | ||
| return true | ||
| } | ||
| return reflect.DeepEqual(m, marker.defaults) | ||
| } | ||
| return reflect.DeepEqual(value, expected) | ||
| } | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| func matchPattern(pattern, path string) bool { | ||
| patternParts := strings.Split(pattern, ".") | ||
| pathParts := strings.Split(path, ".") | ||
| return matchParts(patternParts, pathParts) | ||
| } | ||
|
|
||
| func matchParts(patternParts, pathParts []string) bool { | ||
| if len(patternParts) == 0 && len(pathParts) == 0 { | ||
| return true | ||
| } | ||
| if len(patternParts) == 0 || len(pathParts) == 0 { | ||
| return false | ||
| } | ||
|
|
||
| patternPart := patternParts[0] | ||
| pathPart := pathParts[0] | ||
|
|
||
| if patternPart == "*" { | ||
| return matchParts(patternParts[1:], pathParts[1:]) | ||
| } | ||
|
|
||
| if strings.Contains(patternPart, "[*]") { | ||
| prefix := strings.Split(patternPart, "[*]")[0] | ||
|
|
||
| if strings.HasPrefix(pathPart, prefix) && strings.Contains(pathPart, "[") { | ||
| return matchParts(patternParts[1:], pathParts[1:]) | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| if patternPart == pathPart { | ||
| return matchParts(patternParts[1:], pathParts[1:]) | ||
| } | ||
|
|
||
| return false | ||
| type resetRule struct { | ||
| field *structpath.PatternNode | ||
| value any | ||
| } | ||
|
|
||
| // resetValues contains all values that should be used to reset CLI-defaulted fields. | ||
| // If CLI-defaulted field is changed on remote and should be disabled (e.g. queueing disabled -> remote field is nil) | ||
| // we can't define it in the config as "null" because CLI default will be applied again. | ||
| var resetValues = map[string]any{ | ||
| "resources.jobs.*.queue": map[string]any{ | ||
| "enabled": false, | ||
| // resetValues defines values that should replace CLI-defaulted fields. | ||
| // If a CLI-defaulted field is changed on remote and should be disabled | ||
| // (e.g. queueing disabled → remote field is nil), we can't define it | ||
| // in the config as "null" because the CLI default will be applied again. | ||
| var resetValues = map[string][]resetRule{ | ||
|
Contributor
Author
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. Should we include this logic in resources.yml? |
||
| "jobs": { | ||
| {field: structpath.MustParsePattern("queue"), value: map[string]any{"enabled": false}}, | ||
| }, | ||
| } | ||
|
|
||
| func resetValueIfNeeded(path string, value any) any { | ||
| for pattern, expected := range resetValues { | ||
| if matchPattern(pattern, path) { | ||
| return expected | ||
| func resetValueIfNeeded(resourceType string, path *structpath.PathNode, value any) any { | ||
| for _, rule := range resetValues[resourceType] { | ||
| if path.HasPatternPrefix(rule.field) { | ||
| return rule.value | ||
| } | ||
| } | ||
| return value | ||
|
|
||
This file contains hidden or 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.
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.
This is expected, logic was incorrect previously - this case was skipped completely