Skip to content

Commit

Permalink
fix: sort gateways by creation timestamp before translate (#3344)
Browse files Browse the repository at this point in the history
sort gateways by creation timestamp before translate

Signed-off-by: shawnh2 <shawnhxh@outlook.com>
Co-authored-by: zirain <zirain2009@gmail.com>
  • Loading branch information
shawnh2 and zirain authored May 8, 2024
1 parent 6a28046 commit c8f1220
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 7 additions & 0 deletions internal/gatewayapi/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
package gatewayapi

import (
"sort"

"golang.org/x/exp/maps"
"k8s.io/apimachinery/pkg/runtime/schema"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
Expand Down Expand Up @@ -156,6 +158,11 @@ func (t *Translator) Translate(resources *Resources) *TranslateResult {
// Get Gateways belonging to our GatewayClass.
gateways := t.GetRelevantGateways(resources.Gateways)

// Sort gateways based on timestamp.
sort.Slice(gateways, func(i, j int) bool {
return gateways[i].CreationTimestamp.Before(&(gateways[j].CreationTimestamp))
})

// Build IR maps.
xdsIR, infraIR := t.InitIRs(gateways, resources)

Expand Down
5 changes: 2 additions & 3 deletions test/e2e/tests/merge_gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,21 +240,20 @@ var MergeGatewaysTest = suite.ConformanceTest{
})
})

t.Run("clean-up conflicted gateway", func(t *testing.T) {
// Clean-up the conflicted gateway and route resources.
t.Cleanup(func() {
conflictedGateway := new(gwapiv1.Gateway)
conflictedHTTPRoute := new(gwapiv1.HTTPRoute)

if err := suite.Client.Get(ctx, gw4NN, conflictedGateway); err != nil {
t.Errorf("failed to get conflicted gateway: %v", err)
t.FailNow()
}
if err := suite.Client.Delete(ctx, conflictedGateway); err != nil {
t.Errorf("failed to delete conflicted gateway: %v", err)
}

if err := suite.Client.Get(ctx, route4NN, conflictedHTTPRoute); err != nil {
t.Errorf("failed to get conflicted httproute: %v", err)
t.FailNow()
}
if err := suite.Client.Delete(ctx, conflictedHTTPRoute); err != nil {
t.Errorf("failed to delete conflicted httproute: %v", err)
Expand Down

0 comments on commit c8f1220

Please sign in to comment.