Repository navigation
Make parent_id_fields imply provided_id_fields #7938
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ import ( | |
| "io/fs" | ||
| "path" | ||
| "reflect" | ||
| "slices" | ||
| "strings" | ||
| "sync" | ||
|
|
||
|
|
@@ -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. | ||
|
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. [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)." 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. [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 { | ||
|
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. [nice to have] |
||
| 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 { | ||
|
|
@@ -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 | ||
|
|
@@ -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. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 { | ||
|
|
@@ -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 { | ||
|
|
@@ -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() { | ||
|
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. [nice to have] 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. [nice to have] |
||
| fields = append(fields, rule.Field.String()) | ||
| } | ||
| assert.ElementsMatch(t, []string{"catalog_name", "schema_name"}, fields) | ||
| } | ||
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.
[nice to have] For secrets,
catalog_name/schema_nameare listed only underparent_id_fields, so this line now matches them beforesecrets.generated.yml'srecreate_on_changes(spec:immutable) at line 596. A remote-only difference that recreated on base is now skipped, and a local change reportsparentinstead ofspec:immutable. No secrets golden or unit test covers either case. Can you add an acceptance test that shows the plan for a localschema_namechange (recreate) and a remote-only case difference (skip)?