Skip to content

Commit 9097fad

Browse files
committed
add customprecompare for Policy and RedrivePolicy
1 parent 3461f9d commit 9097fad

File tree

7 files changed

+69
-4
lines changed

7 files changed

+69
-4
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
ack_generate_info:
2-
build_date: "2025-03-27T16:10:01Z"
3-
build_hash: 980cb1e4734f673d16101cf55206b84ca639ec01
2+
build_date: "2025-04-28T00:49:00Z"
3+
build_hash: ab8fa0bbefe77c9682f53251412fd8d1002ba30f
44
go_version: go1.24.1
5-
version: v0.44.0
5+
version: v0.44.0-3-gab8fa0b
66
api_directory_checksum: 2627dc306e3a83c86c04050c6c4336451459e728
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.32.6
99
generator_config_info:
10-
file_checksum: 662a51e8e4a1225d04aa0121d55827e0a9a054af
10+
file_checksum: a8b042553864c5ad7aadf35fac713c5fbc3087fd
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation

apis/v1alpha1/generator.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ resources:
1212
values:
1313
- All
1414
hooks:
15+
delta_pre_compare:
16+
code: customPreCompare(delta, a, b)
1517
sdk_get_attributes_pre_set_output:
1618
template_path: hooks/queue/sdk_get_attributes_pre_set_output.go.tpl
1719
sdk_get_attributes_post_set_output:

generator.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ resources:
1212
values:
1313
- All
1414
hooks:
15+
delta_pre_compare:
16+
code: customPreCompare(delta, a, b)
1517
sdk_get_attributes_pre_set_output:
1618
template_path: hooks/queue/sdk_get_attributes_pre_set_output.go.tpl
1719
sdk_get_attributes_post_set_output:

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ require (
1313
github.com/aws/aws-sdk-go-v2/service/sqs v1.37.10
1414
github.com/aws/smithy-go v1.22.2
1515
github.com/go-logr/logr v1.4.2
16+
github.com/micahhausler/aws-iam-policy v0.4.2
1617
github.com/spf13/pflag v1.0.5
1718
k8s.io/api v0.32.1
1819
k8s.io/apimachinery v0.32.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0
113113
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
114114
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
115115
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
116+
github.com/micahhausler/aws-iam-policy v0.4.2 h1:HF7bERLnpqEmffV9/wTT4jZ7TbSNVk0JbpXo1Cj3up0=
117+
github.com/micahhausler/aws-iam-policy v0.4.2/go.mod h1:Ojgst9ZFn+VEEJpqtuw/LxVGqEf2+hwWBlkYWvF/XWM=
116118
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
117119
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
118120
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=

pkg/resource/queue/delta.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/resource/queue/hooks.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,18 @@
1414
package queue
1515

1616
import (
17+
"bytes"
1718
"context"
19+
"encoding/json"
1820
"fmt"
21+
"reflect"
1922

2023
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
24+
ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare"
2125
ackrtlog "github.com/aws-controllers-k8s/runtime/pkg/runtime/log"
2226
svcsdk "github.com/aws/aws-sdk-go-v2/service/sqs"
2327
"github.com/aws/aws-sdk-go/aws/arn"
28+
policy "github.com/micahhausler/aws-iam-policy/policy"
2429
)
2530

2631
// syncTags examines the Tags in the supplied Queue and calls the
@@ -143,3 +148,55 @@ func (rm *resourceManager) getQueueNameFromARN(tmpARN ackv1alpha1.AWSResourceNam
143148
}
144149
return queueARN.Resource, nil
145150
}
151+
152+
// customPreCompare is the entry point for custom comparison logic
153+
func customPreCompare(
154+
delta *ackcompare.Delta,
155+
a *resource,
156+
b *resource,
157+
) {
158+
comparePolicy(delta, a, b)
159+
compareRedrivePolicy(delta, a, b)
160+
}
161+
162+
// comparePolicy compares the Policy fields of two resources by unmarshalling
163+
// them into policy.Policy structs and using reflect.DeepEqual.
164+
func comparePolicy(
165+
delta *ackcompare.Delta,
166+
a *resource,
167+
b *resource,
168+
) {
169+
var policyA policy.Policy
170+
decoderA := json.NewDecoder(bytes.NewBufferString(*a.ko.Spec.Policy))
171+
decoderA.DisallowUnknownFields()
172+
errA := decoderA.Decode(&policyA)
173+
174+
var policyB policy.Policy
175+
decoderB := json.NewDecoder(bytes.NewBufferString(*b.ko.Spec.Policy))
176+
decoderB.DisallowUnknownFields()
177+
errB := decoderB.Decode(&policyB)
178+
179+
if errA != nil || errB != nil || !reflect.DeepEqual(policyA, policyB) {
180+
delta.Add("Spec.Policy", a.ko.Spec.Policy, b.ko.Spec.Policy)
181+
}
182+
}
183+
184+
// compareRedrivePolicy compares the RedrivePolicy fields of two resources by
185+
// unmarshalling them into interface{} and using reflect.DeepEqual.
186+
// since RedrivePolicy is a JSON string, we need to unmarshal it
187+
// into an interface{} and then compare the two interface{}s.
188+
func compareRedrivePolicy(
189+
delta *ackcompare.Delta,
190+
a *resource,
191+
b *resource,
192+
) {
193+
var redriveA interface{}
194+
errA := json.Unmarshal([]byte(*a.ko.Spec.RedrivePolicy), &redriveA)
195+
196+
var redriveB interface{}
197+
errB := json.Unmarshal([]byte(*b.ko.Spec.RedrivePolicy), &redriveB)
198+
199+
if errA != nil || errB != nil || !reflect.DeepEqual(redriveA, redriveB) {
200+
delta.Add("Spec.RedrivePolicy", a.ko.Spec.RedrivePolicy, b.ko.Spec.RedrivePolicy)
201+
}
202+
}

0 commit comments

Comments
 (0)