From 7a4c51e4f865cd0f30f19fe1973e6a15d60663bf Mon Sep 17 00:00:00 2001 From: Huabing Zhao Date: Sat, 23 Nov 2024 07:33:35 +0000 Subject: [PATCH] fix test Signed-off-by: Huabing Zhao --- internal/gatewayapi/runner/runner.go | 14 +++++++++----- internal/gatewayapi/runner/runner_test.go | 2 -- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/internal/gatewayapi/runner/runner.go b/internal/gatewayapi/runner/runner.go index 2f79fe86d6a..cab5220da50 100644 --- a/internal/gatewayapi/runner/runner.go +++ b/internal/gatewayapi/runner/runner.go @@ -369,6 +369,7 @@ type StatusesToDelete struct { func (r *Runner) getAllStatuses() *StatusesToDelete { // Maps storing status keys to be deleted ds := &StatusesToDelete{ + GatewayStatusKeys: make(map[types.NamespacedName]bool), HTTPRouteStatusKeys: make(map[types.NamespacedName]bool), GRPCRouteStatusKeys: make(map[types.NamespacedName]bool), TLSRouteStatusKeys: make(map[types.NamespacedName]bool), @@ -386,11 +387,9 @@ func (r *Runner) getAllStatuses() *StatusesToDelete { } // Get current status keys - // Do not delete the status keys for the Gateway because the Gateway status has also been stored into the ProviderResources - // by the kubernetes provider to update the address and workload status. - // - // TODO: zhaohuabing It's not a big issue as the Gateway status typically does not occupy a lot of memory. - // but it's better to move all the status handling to Gateway API translator layer to avoid this. + for key := range r.ProviderResources.GatewayStatuses.LoadAll() { + ds.GatewayStatusKeys[key] = true + } for key := range r.ProviderResources.HTTPRouteStatuses.LoadAll() { ds.HTTPRouteStatusKeys[key] = true } @@ -429,6 +428,11 @@ func (r *Runner) getAllStatuses() *StatusesToDelete { } func (r *Runner) deleteStatusKeys(ds *StatusesToDelete) { + // Do not delete the status keys for the Gateway because the Gateway status has also been stored into the ProviderResources + // by the kubernetes provider to update the address and workload status. + // + // TODO: zhaohuabing this is acceptable as the Gateway status typically does not occupy a lot of memory, + // but it's better to move all the status handling to Gateway API translator layer to avoid this. for key := range ds.HTTPRouteStatusKeys { r.ProviderResources.HTTPRouteStatuses.Delete(key) delete(ds.HTTPRouteStatusKeys, key) diff --git a/internal/gatewayapi/runner/runner_test.go b/internal/gatewayapi/runner/runner_test.go index 58515da7e16..2b5c54fd12e 100644 --- a/internal/gatewayapi/runner/runner_test.go +++ b/internal/gatewayapi/runner/runner_test.go @@ -203,7 +203,6 @@ func TestDeleteStatusKeys(t *testing.T) { delete(ds.UDPRouteStatusKeys, keys[6]) r.deleteStatusKeys(ds) - require.Equal(t, 0, r.ProviderResources.GatewayStatuses.Len()) require.Equal(t, 0, r.ProviderResources.HTTPRouteStatuses.Len()) require.Equal(t, 0, r.ProviderResources.GRPCRouteStatuses.Len()) require.Equal(t, 0, r.ProviderResources.TLSRouteStatuses.Len()) @@ -278,7 +277,6 @@ func TestDeleteAllStatusKeys(t *testing.T) { // Checks that the keys are successfully stored to DeletableStatus and watchable maps ds := r.getAllStatuses() - require.True(t, ds.GatewayStatusKeys[keys[0]]) require.True(t, ds.HTTPRouteStatusKeys[keys[1]]) require.True(t, ds.GRPCRouteStatusKeys[keys[2]]) require.True(t, ds.TLSRouteStatusKeys[keys[3]])