-
Notifications
You must be signed in to change notification settings - Fork 16
add customprecompare to normalize policy #75
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 |
|---|---|---|
| @@ -1,13 +1,13 @@ | ||
| ack_generate_info: | ||
| build_date: "2025-03-27T16:10:01Z" | ||
| build_hash: 980cb1e4734f673d16101cf55206b84ca639ec01 | ||
| build_date: "2025-04-29T03:41:47Z" | ||
| build_hash: ab8fa0bbefe77c9682f53251412fd8d1002ba30f | ||
| go_version: go1.24.1 | ||
| version: v0.44.0 | ||
| version: v0.44.0-3-gab8fa0b | ||
| api_directory_checksum: 2627dc306e3a83c86c04050c6c4336451459e728 | ||
| api_version: v1alpha1 | ||
| aws_sdk_go_version: v1.32.6 | ||
| generator_config_info: | ||
| file_checksum: 662a51e8e4a1225d04aa0121d55827e0a9a054af | ||
| file_checksum: b332aeda9a33b58316273296754ee470b9568b59 | ||
| original_file_name: generator.yaml | ||
| last_modification: | ||
| reason: API generation |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,13 +14,18 @@ | |
| package queue | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
| "reflect" | ||
|
|
||
| ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1" | ||
| ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare" | ||
| ackrtlog "github.com/aws-controllers-k8s/runtime/pkg/runtime/log" | ||
| svcsdk "github.com/aws/aws-sdk-go-v2/service/sqs" | ||
| "github.com/aws/aws-sdk-go/aws/arn" | ||
| policy "github.com/micahhausler/aws-iam-policy/policy" | ||
| ) | ||
|
|
||
| // syncTags examines the Tags in the supplied Queue and calls the | ||
|
|
@@ -143,3 +148,73 @@ func (rm *resourceManager) getQueueNameFromARN(tmpARN ackv1alpha1.AWSResourceNam | |
| } | ||
| return queueARN.Resource, nil | ||
| } | ||
|
|
||
| // customPreCompare is the entry point for custom comparison logic | ||
| func customPreCompare( | ||
| delta *ackcompare.Delta, | ||
| a *resource, | ||
| b *resource, | ||
| ) { | ||
| comparePolicy(delta, a, b) | ||
| compareRedrivePolicy(delta, a, b) | ||
| } | ||
|
|
||
| // comparePolicy compares the Policy fields of two resources by unmarshalling | ||
| // them into policy.Policy structs and using reflect.DeepEqual. | ||
| func comparePolicy( | ||
| delta *ackcompare.Delta, | ||
| a *resource, | ||
| b *resource, | ||
| ) { | ||
| if a.ko.Spec.Policy == b.ko.Spec.Policy { | ||
| // both are nil or equal | ||
| return | ||
| } | ||
| if a.ko.Spec.Policy == nil || b.ko.Spec.Policy == nil { | ||
| // one is nil and the other is not | ||
| delta.Add("Spec.Policy", a.ko.Spec.Policy, b.ko.Spec.Policy) | ||
| return | ||
| } | ||
| var policyA policy.Policy | ||
| decoderA := json.NewDecoder(bytes.NewBufferString(*a.ko.Spec.Policy)) | ||
| decoderA.DisallowUnknownFields() | ||
| errA := decoderA.Decode(&policyA) | ||
|
|
||
| var policyB policy.Policy | ||
| decoderB := json.NewDecoder(bytes.NewBufferString(*b.ko.Spec.Policy)) | ||
| decoderB.DisallowUnknownFields() | ||
| errB := decoderB.Decode(&policyB) | ||
|
|
||
| if errA != nil || errB != nil || !reflect.DeepEqual(policyA, policyB) { | ||
|
Member
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 this be
Member
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. Depends do we want a diff if the unmarshal fails? I think it might be better for it to show up.. |
||
| delta.Add("Spec.Policy", a.ko.Spec.Policy, b.ko.Spec.Policy) | ||
| } | ||
| } | ||
|
|
||
| // compareRedrivePolicy compares the RedrivePolicy fields of two resources by | ||
| // unmarshalling them into interface{} and using reflect.DeepEqual. | ||
| // since RedrivePolicy is a JSON string, we need to unmarshal it | ||
| // into an interface{} and then compare the two interface{}s. | ||
| func compareRedrivePolicy( | ||
| delta *ackcompare.Delta, | ||
| a *resource, | ||
| b *resource, | ||
| ) { | ||
| if a.ko.Spec.RedrivePolicy == b.ko.Spec.RedrivePolicy { | ||
| // both are nil or equal | ||
| return | ||
| } | ||
| if a.ko.Spec.RedrivePolicy == nil || b.ko.Spec.RedrivePolicy == nil { | ||
| // one is nil and the other is not | ||
| delta.Add("Spec.RedrivePolicy", a.ko.Spec.RedrivePolicy, b.ko.Spec.RedrivePolicy) | ||
| return | ||
| } | ||
| var redriveA interface{} | ||
| errA := json.Unmarshal([]byte(*a.ko.Spec.RedrivePolicy), &redriveA) | ||
|
|
||
| var redriveB interface{} | ||
| errB := json.Unmarshal([]byte(*b.ko.Spec.RedrivePolicy), &redriveB) | ||
|
|
||
| if errA != nil || errB != nil || !reflect.DeepEqual(redriveA, redriveB) { | ||
michaelhtm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| delta.Add("Spec.RedrivePolicy", a.ko.Spec.RedrivePolicy, b.ko.Spec.RedrivePolicy) | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.