-
Notifications
You must be signed in to change notification settings - Fork 53
Issue 2090/route table order dependence #236
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 14 commits
5d80b8f
a5e0f0e
2386870
6b8268f
9bd0e21
5cce445
86e6f18
2ac08c2
9d6f263
7d7fb6c
87b8df9
13385d6
9843ec3
ece9faa
b433937
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,14 @@ | ||
ack_generate_info: | ||
build_date: "2025-02-24T08:32:50Z" | ||
build_date: "2025-02-26T00:29:35Z" | ||
build_hash: a326346bd3a6973254d247c9ab2dc76790c36241 | ||
go_version: go1.24.0 | ||
go_version: go1.23.5 | ||
version: v0.43.2 | ||
api_directory_checksum: b31faecf6092fab9677498f3624e624fee4cbaed | ||
api_version: v1alpha1 | ||
aws_sdk_go_version: v1.32.6 | ||
generator_config_info: | ||
file_checksum: b3d6924c2a4a2252ea9a7fa775eb86bd1660eeef | ||
file_checksum: 4f9d21bd7c46b495cd9374e454a3a0e1e6de5d08 | ||
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.
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. nit: can we also add an e2e test addressing the issue? 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. To replicate my initial problem, I'd need to understand when order of routes changes in the AWS API. Otherwise, I wouldn't know how to test this. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package route_table | ||
|
||
import ( | ||
"testing" | ||
|
||
svcapitypes "github.com/aws-controllers-k8s/ec2-controller/apis/v1alpha1" | ||
ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare" | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCustomerPreCompare(t *testing.T) { | ||
type Routes []*svcapitypes.CreateRouteInput | ||
|
||
peeringRoute := func(pcxID string, cidr string) *svcapitypes.CreateRouteInput { | ||
return &svcapitypes.CreateRouteInput{ | ||
DestinationCIDRBlock: aws.String(cidr), | ||
VPCPeeringConnectionID: aws.String(pcxID), | ||
} | ||
} | ||
|
||
createRouteTableTestResource := func(routes []*svcapitypes.CreateRouteInput) *resource { | ||
return &resource{ | ||
ko: &svcapitypes.RouteTable{ | ||
Spec: svcapitypes.RouteTableSpec{ | ||
Routes: routes, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
assertRoutesIdentical := func(t *testing.T, a, b []*svcapitypes.CreateRouteInput) { | ||
assert.Len(t, a, len(b)) | ||
for i := range a { | ||
assert.EqualValues(t, a[i], b[i]) | ||
} | ||
} | ||
|
||
tt := []struct { | ||
id string | ||
desiredRoutes Routes | ||
latestRoutes Routes | ||
toAdd Routes | ||
toDelete Routes | ||
}{ | ||
{"all identical", | ||
Routes{peeringRoute("pcx-123", "172.30.1.0/24")}, | ||
Routes{peeringRoute("pcx-123", "172.30.1.0/24")}, | ||
nil, nil, | ||
}, | ||
{"add route", | ||
Routes{peeringRoute("pcx-123", "172.30.1.0/24")}, | ||
nil, | ||
Routes{peeringRoute("pcx-123", "172.30.1.0/24")}, | ||
nil, | ||
}, | ||
{"delete route", | ||
nil, | ||
Routes{peeringRoute("pcx-123", "172.30.1.0/24")}, | ||
nil, | ||
Routes{peeringRoute("pcx-123", "172.30.1.0/24")}, | ||
}, | ||
{"keep one delete one", | ||
Routes{peeringRoute("pcx-123", "172.30.1.0/24")}, | ||
Routes{peeringRoute("pcx-123", "172.30.1.0/24"), peeringRoute("pcx-123", "172.30.2.0/24")}, | ||
nil, | ||
Routes{peeringRoute("pcx-123", "172.30.2.0/24")}, | ||
}, | ||
{"keep one add one", | ||
Routes{peeringRoute("pcx-123", "172.30.1.0/24"), peeringRoute("pcx-123", "172.30.2.0/24")}, | ||
Routes{peeringRoute("pcx-123", "172.30.1.0/24")}, | ||
Routes{peeringRoute("pcx-123", "172.30.2.0/24")}, | ||
nil, | ||
}, | ||
{"keep one add one delete one", | ||
Routes{peeringRoute("pcx-123", "172.30.1.0/24"), peeringRoute("pcx-123", "172.30.2.0/24")}, | ||
Routes{peeringRoute("pcx-123", "172.30.1.0/24"), peeringRoute("pcx-123", "172.30.3.0/24")}, | ||
Routes{peeringRoute("pcx-123", "172.30.2.0/24")}, | ||
Routes{peeringRoute("pcx-123", "172.30.3.0/24")}, | ||
}, | ||
} | ||
|
||
for _, tti := range tt { | ||
t.Run(tti.id, func(t *testing.T) { | ||
delta := ackcompare.NewDelta() | ||
a := createRouteTableTestResource(tti.desiredRoutes) | ||
b := createRouteTableTestResource(tti.latestRoutes) | ||
customPreCompare(delta, a, b) | ||
if len(tti.toAdd) == 0 && len(tti.toDelete) == 0 { | ||
assert.Equal(t, 0, len(delta.Differences)) | ||
} else { | ||
diff := delta.Differences[0] | ||
diffA := diff.A.([]*svcapitypes.CreateRouteInput) | ||
diffB := diff.B.([]*svcapitypes.CreateRouteInput) | ||
assert.True(t, diff.Path.Contains("Spec.Routes")) | ||
assert.ElementsMatch(t, tti.desiredRoutes, diffA) | ||
assert.ElementsMatch(t, tti.latestRoutes, diffB) | ||
|
||
// Check the different routes are identified correctly | ||
toAdd, toDelete := getRoutesDifference(tti.desiredRoutes, tti.latestRoutes) | ||
assertRoutesIdentical(t, tti.toAdd, toAdd) | ||
assertRoutesIdentical(t, tti.toDelete, toDelete) | ||
} | ||
}) | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.