feat: add CompareResourceForPreDelete and DeltaForPreDelete support#686
feat: add CompareResourceForPreDelete and DeltaForPreDelete support#686sapphirew wants to merge 2 commits intoaws-controllers-k8s:mainfrom
Conversation
michaelhtm
left a comment
There was a problem hiding this comment.
Thanks @sapphirew
left one comment below
| // CompareResourceForPreDelete returns the Go code that traverses a set of two | ||
| // Resources, adding differences between the two Resources to an | ||
| // `ackcompare.Delta`. Unlike CompareResource, this function does NOT skip | ||
| // fields where compareConfig.IsIgnored is true. This is used for pre-delete | ||
| // sync to ensure fields like DeletionProtectionEnabled are included in the | ||
| // delta comparison. |
There was a problem hiding this comment.
should we make this delta comparison opt-in? Only compute delta on specific fields defined in generator.yaml?
In dsql example, we could just compare DeletionProtection field only
There was a problem hiding this comment.
good call, that would provide fine-control on specific fields for a controller.
The current delta comparison can be enabled by a flag like this instead:
resources:
Cluster:
pre_delete_sync:
compare_all: true
…Delete support Add pre-delete delta comparison support to the code generator. Controllers can opt specific fields into pre-delete comparison via compare.pre_delete_include: true in generator.yaml, so that fields like DeletionProtectionEnabled are synced before deletion even when they use compare.is_ignored for normal reconciliation. Config changes: - Add PreDeleteInclude bool to CompareFieldConfig (field.go) - Add PreDeleteSyncConfig with CompareAll to ResourceConfig (resource.go) Code generation: - Add CompareResourceForPreDelete function that emits comparison code only for opted-in fields (or all fields when compare_all is true) - Register GoCodeCompareForPreDelete template function (controller.go) - Add newResourceDeltaForPreDelete in delta.go.tpl - Add DeltaForPreDelete method on resourceDescriptor in descriptor.go.tpl Tests: - Four tests covering no-opt-in (empty), explicit opt-in, compare_all, and empty-without-opt-in scenarios - Two new S3 test fixture generator YAMLs
028a963 to
b3f5d67
Compare
|
/test s3-controller-test |
|
/test lambda-controller-test |
|
/retest |
2 similar comments
|
/retest |
|
/retest |
Add FifoThroughputScope to generator.yaml with is_attribute: true and regenerate controller code. Fix the custom update hook in hooks.go by adding FIFOThroughputScope to settableAttributeNames and the newSetAttributesRequestPayload switch statement. Add e2e test coverage: create assertions for FifoThroughputScope and an update test verifying changes via SetTopicAttributes. ArchivePolicy support is deferred until the pre-delete-sync feature lands (aws-controllers-k8s/code-generator#686), since SNS rejects DeleteTopic on topics with an active ArchivePolicy and the controller cannot sync spec updates after a deletion timestamp is set. Closes: aws-controllers-k8s/community#2840
Add FifoThroughputScope to generator.yaml with is_attribute: true and regenerate controller code. Fix the custom update hook in hooks.go by adding FIFOThroughputScope to settableAttributeNames and the newSetAttributesRequestPayload switch statement. Add e2e test coverage: create assertions for FifoThroughputScope and an update test verifying changes via SetTopicAttributes. ArchivePolicy support is deferred until the pre-delete-sync feature lands (aws-controllers-k8s/code-generator#686), since SNS rejects DeleteTopic on topics with an active ArchivePolicy and the controller cannot sync spec updates after a deletion timestamp is set. Closes: aws-controllers-k8s/community#2840
Add FifoThroughputScope to generator.yaml with is_attribute: true and regenerate controller code. Fix the custom update hook in hooks.go by adding FIFOThroughputScope to settableAttributeNames and the newSetAttributesRequestPayload switch statement. Add e2e test coverage: create assertions for FifoThroughputScope and an update test verifying changes via SetTopicAttributes. ArchivePolicy support is deferred until the pre-delete-sync feature lands (aws-controllers-k8s/code-generator#686), since SNS rejects DeleteTopic on topics with an active ArchivePolicy and the controller cannot sync spec updates after a deletion timestamp is set. Closes: aws-controllers-k8s/community#2840
Add FifoThroughputScope to generator.yaml with is_attribute: true and regenerate controller code. Fix the custom update hook in hooks.go by adding FIFOThroughputScope to settableAttributeNames and the newSetAttributesRequestPayload switch statement. Add e2e test coverage: create assertions for FifoThroughputScope and an update test verifying changes via SetTopicAttributes. ArchivePolicy support is deferred until the pre-delete-sync feature lands (aws-controllers-k8s/code-generator#686), since SNS rejects DeleteTopic on topics with an active ArchivePolicy and the controller cannot sync spec updates after a deletion timestamp is set. Closes: aws-controllers-k8s/community#2840
|
/retest |
knottnt
left a comment
There was a problem hiding this comment.
@sapphirew left a few comments. Also, it would be helpful to see a WIP PR showing off these changes applied to a service controller. It makes it a bit easier to understand how the generated code will actually work.
9cdfa78 to
24ebf8b
Compare
dce77f2 to
67890b7
Compare
| expected := ` | ||
| if ackcompare.HasNilDifference(a.ko.Spec.ACL, b.ko.Spec.ACL) { | ||
| delta.Add("Spec.ACL", a.ko.Spec.ACL, b.ko.Spec.ACL) | ||
| } else if a.ko.Spec.ACL != nil && b.ko.Spec.ACL != nil { | ||
| if *a.ko.Spec.ACL != *b.ko.Spec.ACL { | ||
| delta.Add("Spec.ACL", a.ko.Spec.ACL, b.ko.Spec.ACL) | ||
| } | ||
| } |
There was a problem hiding this comment.
can we add test cases for nested fields?
| // The generated code is a series of simple field assignments for each field | ||
| // that has `compare.pre_delete_include: true` (or all fields when | ||
| // `pre_delete_sync.compare_all: true`). | ||
| func MergeResourceForPreDelete( |
There was a problem hiding this comment.
can we add a unit test for this one?
Update DeltaForPreDelete to return both a delta and a merged resource. The merged resource is a deep copy of observed (b) with only the pre-delete sync configured fields overwritten from desired (a). This ensures rm.Update only changes the fields that DeltaForPreDelete detected as different while all other fields retain their current AWS values. Refactor comparison logic: - Extract compareResourceFields shared function with fieldFilter callback to eliminate duplicated comparison code between CompareResource and CompareResourceForPreDelete - Extract sortedSpecFieldNames helper to deduplicate sorted field iteration across CompareResource, CompareResourceForPreDelete, and MergeResourceForPreDelete - Add MergeResourceForPreDelete and GoCodeMergeForPreDelete template function for generating field assignments - Simplify descriptor.go.tpl DeltaForPreDelete by removing redundant nil check
67890b7 to
0d67d28
Compare
|
/test lambda-controller-test |
|
/retest |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: knottnt, sapphirew The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Add pre-delete delta comparison support to the code generator. Controllers can opt specific fields into pre-delete comparison via
compare.pre_delete_include: truein generator.yaml, so that fields likeDeletionProtectionEnabledare synced before deletion even when they usecompare.is_ignoredfor normal reconciliation.Config changes:
PreDeleteIncludebool toCompareFieldConfig(field.go)PreDeleteSyncConfigwithCompareAll to ResourceConfig(resource.go)Code generation:
CompareResourceForPreDeletefunction that emits comparison codeonly for opted-in fields (or all fields when compare_all is true)
GoCodeCompareForPreDeletetemplate function (controller.go)newResourceDeltaForPreDeletein delta.go.tplDeltaForPreDeletemethod onresourceDescriptorin descriptor.go.tplTests:
and empty-without-opt-in scenarios
runtime changes: aws-controllers-k8s/runtime#234
Issue #, if available:
Description of changes:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.