Skip to content

Commit 7f7c5da

Browse files
committed
Fix weighted target group comparison for forward action
1 parent fee9ed8 commit 7f7c5da

File tree

2 files changed

+912
-9
lines changed

2 files changed

+912
-9
lines changed

pkg/equality/elbv2/compare_option_for_actions.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,34 @@ import (
66
"github.com/google/go-cmp/cmp"
77
"github.com/google/go-cmp/cmp/cmpopts"
88
"sigs.k8s.io/aws-load-balancer-controller/pkg/equality"
9+
"sort"
910
)
1011

1112
func CompareOptionForTargetGroupTuples() cmp.Option {
1213
return cmp.Options{
1314
cmpopts.IgnoreUnexported(elbv2types.TargetGroupTuple{}),
14-
cmpopts.AcyclicTransformer("normalizeWeights", func(tgt []elbv2types.TargetGroupTuple) []elbv2types.TargetGroupTuple {
15-
if len(tgt) != 1 {
15+
cmpopts.AcyclicTransformer("sortAndNormalize", func(tgt []elbv2types.TargetGroupTuple) []elbv2types.TargetGroupTuple {
16+
// Handle empty slice
17+
if len(tgt) == 0 {
1618
return tgt
1719
}
18-
singleTG := tgt[0]
19-
return []elbv2types.TargetGroupTuple{
20-
{
21-
TargetGroupArn: singleTG.TargetGroupArn,
22-
Weight: nil,
23-
},
20+
21+
// Sort by ARN for consistent ordering (for all cases)
22+
result := make([]elbv2types.TargetGroupTuple, len(tgt))
23+
copy(result, tgt)
24+
25+
sort.Slice(result, func(i, j int) bool {
26+
arnI := awssdk.ToString(result[i].TargetGroupArn)
27+
arnJ := awssdk.ToString(result[j].TargetGroupArn)
28+
return arnI < arnJ
29+
})
30+
31+
// Normalize weights (only for single target groups)
32+
if len(result) == 1 {
33+
result[0].Weight = nil
2434
}
35+
36+
return result
2537
}),
2638
}
2739
}

0 commit comments

Comments
 (0)