@@ -236,3 +236,129 @@ func (s *HTTPRouteTestSuite) Test_HTTPRoute_OK_Multiple_Listeners_One_Gateway()
236236 // For FE https
237237 s .ExpectMapContents (mapFilePath2 , expectedMapsPath )
238238}
239+
240+ // Test_HTTPRoute_OK_No_reload_When_Modification_Only_Affect_Maps check that if we change a route and it's only affects
241+ // maps (e.g. Path Prefix) it does not reload.
242+ //
243+ // the test scenario is the following:
244+ // - create a route with no endpoints and PathPrefix = /path1
245+ // - edit the route's path prefix to /path2 and check configuration is updated without reload and route condition is updated. updating route w/o endpoints allows testing conner cases
246+ // - scale up to 3 endpoints and check configuration is updated without reload.
247+ // - scale down to 1 endpoints and check configuration is updated without reload.
248+ // - update route path's PathPrefix = /path1 and check configuration is updated without reload and route condition is updated.
249+ func (s * HTTPRouteTestSuite ) Test_HTTPRoute_OK_No_reload_When_Modification_Only_Affect_Maps () {
250+ fixtureDirPath := utils .GetCRDFixturePath ()
251+ fixtureDir := "basic"
252+
253+ fixturePath := path .Join (fixtureDirPath , fixtureDir , "ok_no_reload_when_modification_only_affect_maps" )
254+ s .CreateFixtures (fixturePath , []string {"gatewayclass.yaml" , "gateway.yaml" , "http-echo.yaml" , "route-path-prefix-1.yaml" })
255+ mapFilePath1 := "hug_http_8080"
256+ mapFilePath2 := "hug_http_8088"
257+ defer s .CleanupFixturesCheckMapFiles (fixturePath , []string {"gatewayclass.yaml" , "gateway.yaml" , "http-echo.yaml" , "route-path-prefix-1.yaml" }, []string {mapFilePath1 , mapFilePath2 })
258+
259+ // Expected Conditions
260+ expectationsPath := path .Join (fixturePath , "expectations" )
261+ expectedCondPath := path .Join (expectationsPath , "route-gen-1-conditions.yaml" )
262+ expectedConditions := s .YamlToRouteConditions (expectedCondPath )
263+
264+ httpRouteName := "route-echo"
265+ s .expectConditionsUpdated (s .Test ().Ctx , s .Test ().Namespace , httpRouteName , expectedConditions )
266+
267+ // Check AttachedRoutes on Gateway status
268+ s .expectAttachedRoute (s .Test ().Ctx , s .Test ().Namespace , "gateway" , "http" , 1 )
269+ s .expectAttachedRoute (s .Test ().Ctx , s .Test ().Namespace , "gateway" , "http2" , 1 )
270+
271+ // haproxy.cfg Backends
272+ const backendName = "hug_e2e-tests-httproute_http-echo_80__"
273+ expectedBackends := []string {backendName }
274+ s .ExpectBackends (s .Test ().Ctx , path .Join (expectationsPath , "backends-gen-1" ), expectedBackends )
275+
276+ // Check Maps for route-prefix-1 (ie pathPrefix = /path1)
277+ expectedMapsPathV1 := path .Join (expectationsPath , "maps-path-prefix-1" )
278+ s .ExpectListenerRouteMapContents (expectedMapsPathV1 )
279+ s .ExpectMapContents (mapFilePath1 , expectedMapsPathV1 ) // For FE http
280+ s .ExpectMapContents (mapFilePath2 , expectedMapsPathV1 ) // For FE https
281+
282+ // check Server
283+ s .ExpectServers (backendName , []string {})
284+
285+ // From now we should not have any reloads
286+ oldPid := s .WaitForNoReloadsAnyMore (10 * time .Second , 2 * time .Second )
287+
288+ s .T ().Logf ("====================================== Edit route to update Path Prefix (no endpoints) ======================================" )
289+ s .CreateFixtures (fixturePath , []string {"route-path-prefix-2.yaml" }) // no need to clean up it the same obj as route-path-prefix-1.yaml
290+
291+ expectedConditionsV2 := s .YamlToRouteConditions (path .Join (expectationsPath , "route-gen-2-conditions.yaml" ))
292+ s .expectConditionsUpdated (s .Test ().Ctx , s .Test ().Namespace , httpRouteName , expectedConditionsV2 )
293+
294+ // haproxy.cfg Backends
295+ s .ExpectBackends (s .Test ().Ctx , path .Join (expectationsPath , "backends-gen-2-ep-0" ), expectedBackends )
296+
297+ // Check Maps-prefix-2
298+ expectedMapsPathV2 := path .Join (expectationsPath , "maps-path-prefix-2" )
299+ s .ExpectListenerRouteMapContents (expectedMapsPathV2 )
300+ s .ExpectMapContents (mapFilePath1 , expectedMapsPathV2 ) // For FE http
301+ s .ExpectMapContents (mapFilePath2 , expectedMapsPathV2 ) // For FE https
302+
303+ // check Server
304+ s .ExpectServers (backendName , []string {})
305+
306+ s .ConsistentlyNoReload (oldPid , 4 * time .Second )
307+
308+ s .T ().Logf ("====================================== scale up endpoints to 3 ======================================" )
309+
310+ // scale deploy to 3 pods
311+ s .CreateFixtures (fixturePath , []string {"echo-endpoints-1.yaml" })
312+ defer s .CleanupFixtures (fixturePath , []string {"echo-endpoints-1.yaml" })
313+ s .expectConditionsUpdated (s .Test ().Ctx , s .Test ().Namespace , httpRouteName , expectedConditionsV2 )
314+
315+ // haproxy.cfg Backends
316+ s .ExpectBackends (s .Test ().Ctx , path .Join (expectationsPath , "backends-gen-2-ep-3" ), expectedBackends )
317+
318+ // Check Maps-prefix-2 (should be the same)
319+ s .ExpectListenerRouteMapContents (expectedMapsPathV2 )
320+ s .ExpectMapContents (mapFilePath1 , expectedMapsPathV2 ) // For FE http
321+ s .ExpectMapContents (mapFilePath2 , expectedMapsPathV2 ) // For FE https
322+
323+ // check Server
324+ s .ExpectServers (backendName , []string {"SRV_4827409c6115096b8dde5db0092cea2f54213123" , "SRV_8ec3713870978506a7ecded834e9907edcf2e619" , "SRV_fe3f9ea252b531060fe66a137b37d38263502132" })
325+
326+ s .ConsistentlyNoReload (oldPid , 4 * time .Second )
327+
328+ s .T ().Logf ("====================================== scale down endpoint to 1 ======================================" )
329+
330+ // scale deploy to 1 pods
331+ s .CreateFixtures (fixturePath , []string {"echo-endpoints-2.yaml" }) // no need to clean up it's the same obj as scale=3
332+
333+ // haproxy.cfg Backends
334+ s .ExpectBackends (s .Test ().Ctx , path .Join (expectationsPath , "backends-gen-2-ep-1" ), expectedBackends )
335+
336+ // Check Maps-prefix-2 (should be the same)
337+ s .ExpectListenerRouteMapContents (expectedMapsPathV2 )
338+ s .ExpectMapContents (mapFilePath1 , expectedMapsPathV2 ) // For FE http
339+ s .ExpectMapContents (mapFilePath2 , expectedMapsPathV2 ) // For FE https
340+
341+ // check Server
342+ s .ExpectServers (backendName , []string {"SRV_4827409c6115096b8dde5db0092cea2f54213123" })
343+ s .ConsistentlyNoReload (oldPid , 4 * time .Second )
344+
345+ s .T ().Logf ("====================================== edit PathPrefix = path1 ======================================" )
346+ s .CreateFixtures (fixturePath , []string {"route-path-prefix-1.yaml" }) // no need to clean up it the same obj as route-path-prefix-1.yaml
347+ expectedConditionsV3 := s .YamlToRouteConditions (path .Join (expectationsPath , "route-gen-3-conditions.yaml" ))
348+ s .expectConditionsUpdated (s .Test ().Ctx , s .Test ().Namespace , httpRouteName , expectedConditionsV3 )
349+
350+ // Check AttachedRoutes on Gateway status
351+ s .expectAttachedRoute (s .Test ().Ctx , s .Test ().Namespace , "gateway" , "http" , 1 )
352+ s .expectAttachedRoute (s .Test ().Ctx , s .Test ().Namespace , "gateway" , "http2" , 1 )
353+
354+ // haproxy.cfg Backends
355+ s .ExpectBackends (s .Test ().Ctx , path .Join (expectationsPath , "backends-gen-3" ), expectedBackends )
356+
357+ // Check Maps for route-path-prefix-1 (ie pathPrefix = /path1)
358+ s .ExpectListenerRouteMapContents (expectedMapsPathV1 )
359+ s .ExpectMapContents (mapFilePath1 , expectedMapsPathV1 ) // For FE http
360+ s .ExpectMapContents (mapFilePath2 , expectedMapsPathV1 ) // For FE https
361+
362+ s .ExpectServers (backendName , []string {"SRV_4827409c6115096b8dde5db0092cea2f54213123" })
363+ s .ConsistentlyNoReload (oldPid , 4 * time .Second )
364+ }
0 commit comments