Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 4 additions & 4 deletions apis/v1alpha1/ack-generate-metadata.yaml
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
6 changes: 6 additions & 0 deletions apis/v1alpha1/generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ resources:
values:
- All
hooks:
delta_pre_compare:
code: customPreCompare(delta, a, b)
sdk_get_attributes_pre_set_output:
template_path: hooks/queue/sdk_get_attributes_pre_set_output.go.tpl
sdk_get_attributes_post_set_output:
Expand Down Expand Up @@ -75,6 +77,8 @@ resources:
service_name: iam
resource: Policy
path: Spec.PolicyDocument
compare:
is_ignored: true
ReceiveMessageWaitTimeSeconds:
is_attribute: true
type: string
Expand All @@ -92,6 +96,8 @@ resources:
RedrivePolicy:
is_attribute: true
type: string
compare:
is_ignored: true
RedriveAllowPolicy:
is_attribute: true
type: string
Expand Down
6 changes: 6 additions & 0 deletions generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ resources:
values:
- All
hooks:
delta_pre_compare:
code: customPreCompare(delta, a, b)
sdk_get_attributes_pre_set_output:
template_path: hooks/queue/sdk_get_attributes_pre_set_output.go.tpl
sdk_get_attributes_post_set_output:
Expand Down Expand Up @@ -75,6 +77,8 @@ resources:
service_name: iam
resource: Policy
path: Spec.PolicyDocument
compare:
is_ignored: true
ReceiveMessageWaitTimeSeconds:
is_attribute: true
type: string
Expand All @@ -92,6 +96,8 @@ resources:
RedrivePolicy:
is_attribute: true
type: string
compare:
is_ignored: true
RedriveAllowPolicy:
is_attribute: true
type: string
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ require (
github.com/aws/aws-sdk-go-v2/service/sqs v1.37.10
github.com/aws/smithy-go v1.22.2
github.com/go-logr/logr v1.4.2
github.com/micahhausler/aws-iam-policy v0.4.2
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0
k8s.io/api v0.32.1
k8s.io/apimachinery v0.32.1
k8s.io/client-go v0.32.1
Expand Down Expand Up @@ -61,6 +63,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/micahhausler/aws-iam-policy v0.4.2 h1:HF7bERLnpqEmffV9/wTT4jZ7TbSNVk0JbpXo1Cj3up0=
github.com/micahhausler/aws-iam-policy v0.4.2/go.mod h1:Ojgst9ZFn+VEEJpqtuw/LxVGqEf2+hwWBlkYWvF/XWM=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down
15 changes: 1 addition & 14 deletions pkg/resource/queue/delta.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions pkg/resource/queue/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Copy link
Member

@michaelhtm michaelhtm Apr 29, 2025

Choose a reason for hiding this comment

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

should this be && instead?

Copy link
Member Author

@rushmash91 rushmash91 Apr 30, 2025

Choose a reason for hiding this comment

The 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) {
delta.Add("Spec.RedrivePolicy", a.ko.Spec.RedrivePolicy, b.ko.Spec.RedrivePolicy)
}
}
Loading