Skip to content

Commit

Permalink
tests: fix HTTPRoute update in integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek committed Oct 4, 2024
1 parent 44131a7 commit 0f9048d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
23 changes: 23 additions & 0 deletions pkg/utils/test/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,29 @@ func DataPlaneUpdateEventually(t *testing.T, ctx context.Context, dataplaneNN ty
}
}

// HTTPRouteUpdateEventually is a helper function for tests that returns a function
// that can be used to update the HTTPRoute.
// Should be used in conjunction with require.Eventually or assert.Eventually.
func HTTPRouteUpdateEventually(t *testing.T, ctx context.Context, httpRouteNN types.NamespacedName, clients K8sClients, updateFunc func(*gatewayv1.HTTPRoute)) func() bool {
return func() bool {
cl := clients.GatewayClient.GatewayV1().HTTPRoutes(httpRouteNN.Namespace)
dp, err := cl.Get(ctx, httpRouteNN.Name, metav1.GetOptions{})
if err != nil {
t.Logf("error getting HTTPRoute: %v", err)
return false
}

updateFunc(dp)

_, err = cl.Update(ctx, dp, metav1.UpdateOptions{})
if err != nil {
t.Logf("error updating HTTPRoute: %v", err)
return false
}
return true
}
}

// ControlPlaneUpdateEventually is a helper function for tests that returns a function
// that can be used to update the ControlPlane.
// Should be used in conjunction with require.Eventually or assert.Eventually.
Expand Down
20 changes: 11 additions & 9 deletions test/integration/test_kongplugininstallation.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ func attachKPI(t *testing.T, gatewayConfigNN k8stypes.NamespacedName, kpiNN k8st
}

func attachKongPluginBasedOnKPIToRoute(t *testing.T, cleaner *clusters.Cleaner, httpRouteNN, kpiNN k8stypes.NamespacedName) {
t.Helper()

kongPluginName := kpiNN.Name + "-plugin"
// To have it in the same namespace as the HTTPRoute to which it is attached.
kongPluginNamespace := httpRouteNN.Namespace
Expand All @@ -320,16 +322,16 @@ func attachKongPluginBasedOnKPIToRoute(t *testing.T, cleaner *clusters.Cleaner,
require.NoError(t, err)
cleaner.Add(&kongPlugin)

t.Logf("attaching KongPlugin to GatewayConfiguration")
// Update httpRoute with KongPlugin
httpRoute, err := GetClients().GatewayClient.GatewayV1().HTTPRoutes(httpRouteNN.Namespace).Get(GetCtx(), httpRouteNN.Name, metav1.GetOptions{})
require.NoError(t, err)
const kpAnnotation = "konghq.com/plugins"
httpRoute.Annotations[kpAnnotation] = strings.Join(
append(strings.Split(httpRoute.Annotations[kpAnnotation], ","), kongPluginName), ",",
t.Logf("attaching KongPlugin %s to HTTPRoute %s", kongPluginName, httpRouteNN)
require.Eventually(t,
testutils.HTTPRouteUpdateEventually(t, GetCtx(), httpRouteNN, clients, func(h *gatewayv1.HTTPRoute) {
const kpAnnotation = "konghq.com/plugins"
h.Annotations[kpAnnotation] = strings.Join(
append(strings.Split(h.Annotations[kpAnnotation], ","), kongPluginName), ",",
)
}),
time.Minute, 250*time.Millisecond,
)
_, err = GetClients().GatewayClient.GatewayV1().HTTPRoutes(httpRouteNN.Namespace).Update(GetCtx(), httpRoute, metav1.UpdateOptions{})
require.NoError(t, err)
}

func checkDataPlaneStatus(
Expand Down

0 comments on commit 0f9048d

Please sign in to comment.