Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Exit code: [KILLED]
"changes": {
"schema_name": {
"action": "recreate",
"reason": "id_field",
"reason": "parent",
"old": "test-schema-[UNIQUE_NAME]",
"new": "test-schema-renamed-[UNIQUE_NAME]"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Resources: 2 created, 0 changed, 0 deleted, 0 unchanged
"changes": {
"schema_name": {
"action": "recreate",
"reason": "id_field",
"reason": "parent",
"old": "test-schema-[UNIQUE_NAME]",
"new": "test-schema-renamed-[UNIQUE_NAME]"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged
"changes": {
"schema_name": {
"action": "recreate",
"reason": "id_field",
"reason": "parent",
"old": "test-schema1-[UNIQUE_NAME]",
"new": "test-schema2-[UNIQUE_NAME]",
"remote": "test-schema1-[UNIQUE_NAME]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Resources: 2 created, 0 changed, 0 deleted, 0 unchanged
},
"schema_name": {
"action": "skip",
"reason": "id_field"
"reason": "parent"
},
"storage_location": {
"action": "skip",
Expand Down
4 changes: 2 additions & 2 deletions bundle/direct/bundle_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ func classifyIDField(cfg *dresources.ResourceLifecycleConfig, path *structpath.P
return deployplan.Undefined, "", false
}
localChange := !structdiff.IsEqual(ch.Old, ch.New)
if reason, ok := findMatchingRule(path, cfg.ProvidedIDFields); ok {
if reason, ok := findMatchingRule(path, cfg.ProvidedIDRules()); ok {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nice to have] For secrets, catalog_name/schema_name are listed only under parent_id_fields, so this line now matches them before secrets.generated.yml's recreate_on_changes (spec:immutable) at line 596. A remote-only difference that recreated on base is now skipped, and a local change reports parent instead of spec:immutable. No secrets golden or unit test covers either case. Can you add an acceptance test that shows the plan for a local schema_name change (recreate) and a remote-only case difference (skip)?

if localChange {
return deployplan.Recreate, reason, true
}
Expand Down Expand Up @@ -1066,7 +1066,7 @@ func hasUnresolvedIDField(adapter *dresources.Adapter, sv *structvar.StructVar)
return true
}
for _, cfg := range []*dresources.ResourceLifecycleConfig{adapter.ResourceConfig(), adapter.GeneratedResourceConfig()} {
if _, ok := findMatchingRule(path, cfg.ProvidedIDFields); ok {
if _, ok := findMatchingRule(path, cfg.ProvidedIDRules()); ok {
return true
}
if _, ok := findMatchingRule(path, cfg.UpdatableIDFields); ok {
Expand Down
2 changes: 1 addition & 1 deletion bundle/direct/dresources/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ func (a *Adapter) FieldTriggersRecreate(path *structpath.PathNode) bool {
return true
}
}
for _, p := range a.resourceConfig.ProvidedIDFields {
for _, p := range a.resourceConfig.ProvidedIDRules() {
if path.HasPatternPrefix(p.Field) {
return true
}
Expand Down
20 changes: 14 additions & 6 deletions bundle/direct/dresources/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/fs"
"path"
"reflect"
"slices"
"strings"
"sync"

Expand Down Expand Up @@ -51,6 +52,11 @@ func (b *BackendDefaultRule) UnmarshalYAML(unmarshal func(any) error) error {
return nil
}

// ProvidedIDRules returns the provided ID fields, the parent ID fields among them.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] "the parent ID fields among them" reads like a filter that returns only the parent ones. How about: "ProvidedIDRules returns ProvidedIDFields followed by ParentIDFields: every field whose local change recreates the resource and whose remote-only difference is skipped (see classifyIDField)."

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] "the provided ID fields, the parent ID fields among them" can be read as returning only the parent fields. Suggest: "ProvidedIDRules returns ProvidedIDFields followed by ParentIDFields; a parent ID field is a provided ID field too and is not listed again under provided_id_fields."

func (c *ResourceLifecycleConfig) ProvidedIDRules() []FieldRule {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nice to have] secrets.yml lists catalog_name/schema_name only under parent_id_fields. At base, classifyIDField didn't match them, so they fell through to the generated recreate_on_changes (spec:immutable). A remote-only difference, such as config Main against a UC-lowercased remote main, recreated the secret. Now it is skipped, and a local change recreates with reason parent. reconcileIDFields in bundle/migrate/build_state.go also starts reconciling these fields for secrets. No golden under acceptance/bundle/resources/secrets changed. Can you add an acceptance case that plans a case-only remote difference on catalog_name (expect skip) and a real catalog_name change (expect recreate/parent)?

return append(slices.Clone(c.ProvidedIDFields), c.ParentIDFields...)
}

// IsBackendDefault reports whether remote, the remote value at path, matches any of
// the backend-default rules (and the rule's allowed values, if specified).
func (c *ResourceLifecycleConfig) IsBackendDefault(path *structpath.PathNode, remote any) bool {
Expand Down Expand Up @@ -119,7 +125,8 @@ type ResourceLifecycleConfig struct {
// these config fields directly. So a remote-only difference on them can only be
// the backend normalizing what we sent: the resource was found at its ID, and a
// real out-of-band rename would change the ID and 404 (handled as resource-gone).
// A local change recreates (delete + create).
// A local change recreates (delete + create). ParentIDFields are provided ID fields
// too; read both through ProvidedIDRules.
ProvidedIDFields []FieldRule `yaml:"provided_id_fields,omitempty"`

// UpdatableIDFields: like ProvidedIDFields these compose the resource's
Expand All @@ -130,11 +137,12 @@ type ResourceLifecycleConfig struct {
UpdatableIDFields []FieldRule `yaml:"updatable_id_fields,omitempty"`

// ParentIDFields: the ID fields that name the resource's parent (a volume's catalog_name and
// schema_name). The backend moves the resource along with a renamed parent, so a change to one
// of these that only follows the parent's rename re-keys the resource instead of recreating it
// at its old ID (see followsParentRename and addParentMoves). Any other field, such as a name
// that references the parent's name, is the resource's own and never follows it. Requires
// IDFromState.
// schema_name). They are provided ID fields too, so they are not listed again under
// provided_id_fields (see ProvidedIDRules). The backend moves the resource along with a
// renamed parent, so a change to one of these that only follows the parent's rename re-keys
// the resource instead of recreating it at its old ID (see followsParentRename and
// addParentMoves). Any other field, such as a name that references the parent's name, is the
// resource's own and never follows it. Requires IDFromState.
ParentIDFields []FieldRule `yaml:"parent_id_fields,omitempty"`

// NormalizeSlash: string field patterns the UC API strips trailing slashes from.
Expand Down
13 changes: 12 additions & 1 deletion bundle/direct/dresources/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ func TestResourcesYMLNoRedundantMissingInRemote(t *testing.T) {
// before recreate_on_changes in the ladder and short-circuits, so a field listed
// in more than one would have all but the first entry silently dead — and the
// categories disagree (e.g. provided_id_fields skips a remote-only diff that
// recreate_on_changes would recreate).
// recreate_on_changes would recreate). parent_id_fields counts as one: a parent ID
// field is a provided ID field too, so listing it under provided_id_fields as well
// only repeats it.
func TestResourcesYMLActionCategoriesExclusive(t *testing.T) {
cfg := MustLoadConfig()
for resourceType, rc := range cfg.Resources {
Expand All @@ -178,6 +180,7 @@ func TestResourcesYMLActionCategoriesExclusive(t *testing.T) {
{"recreate_on_changes", rc.RecreateOnChanges},
{"provided_id_fields", rc.ProvidedIDFields},
{"updatable_id_fields", rc.UpdatableIDFields},
{"parent_id_fields", rc.ParentIDFields},
}
firstCat := map[string]string{}
for _, c := range actionCats {
Expand Down Expand Up @@ -224,3 +227,11 @@ func joinPattern(prefix *structpath.PatternNode, field string) string {
}
return prefix.String() + "." + field
}

func TestProvidedIDRulesIncludeParentIDFields(t *testing.T) {
var fields []string
for _, rule := range GetResourceConfig("volumes").ProvidedIDRules() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nice to have] volumes has no provided_id_fields left, so this test would still pass if ProvidedIDRules returned only ParentIDFields. Can it use registered_models (name plus catalog_name/schema_name) so both halves of the merge are checked?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nice to have] volumes no longer has any provided_id_fields, so ProvidedIDRules() returns only ParentIDFields. An implementation that ignored ProvidedIDFields entirely would still pass. Can you use registered_models instead? It has name plus both parent fields, so the test checks the union the helper exists to build.

fields = append(fields, rule.Field.String())
}
assert.ElementsMatch(t, []string{"catalog_name", "schema_name"}, fields)
}
4 changes: 0 additions & 4 deletions bundle/direct/dresources/configs/registered_models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ provided_id_fields:
# to match TF implementation.
- field: name
reason: terraform_compat
- field: catalog_name
reason: id_field
- field: schema_name
reason: id_field
parent_id_fields:
- field: catalog_name
reason: parent
Expand Down
3 changes: 0 additions & 3 deletions bundle/direct/dresources/configs/schemas.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
provided_id_fields:
- field: catalog_name
reason: id_field
parent_id_fields:
- field: catalog_name
reason: parent
Expand Down
5 changes: 0 additions & 5 deletions bundle/direct/dresources/configs/volumes.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
provided_id_fields:
- field: catalog_name
reason: id_field
- field: schema_name
reason: id_field
parent_id_fields:
- field: catalog_name
reason: parent
Expand Down
2 changes: 1 addition & 1 deletion bundle/migrate/build_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func reconcileIDFields(ctx context.Context, adapter *dresources.Adapter, group,
rules []dresources.FieldRule
action string
}{
{cfg.ProvidedIDFields, "recreated"},
{cfg.ProvidedIDRules(), "recreated"},
{cfg.UpdatableIDFields, "renamed"},
} {
for _, rule := range kind.rules {
Expand Down
Loading