88package tests
99
1010import (
11+ "context"
1112 "testing"
1213 "time"
1314
1415 "github.com/stretchr/testify/require"
16+ corev1 "k8s.io/api/core/v1"
1517 "k8s.io/apimachinery/pkg/types"
18+ "sigs.k8s.io/controller-runtime/pkg/client"
1619 gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
1720 "sigs.k8s.io/gateway-api/conformance/utils/http"
1821 "sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
@@ -35,8 +38,43 @@ var MultipleExtManagers = suite.ResilienceTest{
3538 ControllerName : "gateway.envoyproxy.io/gatewayclass-controller" ,
3639 }
3740
38- // Apply the multi-manager ConfigMap and restart the control plane to pick it up.
39- ap .MustApplyWithCleanup (t , suite .Client , suite .TimeoutConfig , "testdata/config_multiple_ext_managers.yaml" , true )
41+ // Install the extension CRDs before the control plane restarts so its provider
42+ // can establish watches on ext-a/ext-b resources; otherwise controller-runtime
43+ // times out on cache sync and the pod enters CrashLoopBackOff.
44+ ap .MustApplyWithCleanup (t , suite .Client , suite .TimeoutConfig , "testdata/extension_crds.yaml" , true )
45+
46+ // Capture the original envoy-gateway-config data so we can restore it on cleanup.
47+ // The conformance Applier's cleanup deletes resources it Updated, which would
48+ // remove the helm-owned ConfigMap and wedge the cluster for subsequent test runs.
49+ cmKey := client.ObjectKey {Name : "envoy-gateway-config" , Namespace : namespace }
50+ originalCM := & corev1.ConfigMap {}
51+ require .NoError (t , suite .Client .Get (ctx , cmKey , originalCM ), "Failed to read original envoy-gateway-config" )
52+ originalData := originalCM .Data
53+ t .Cleanup (func () {
54+ restoreCtx , cancel := context .WithTimeout (context .Background (), time .Minute )
55+ defer cancel ()
56+ cm := & corev1.ConfigMap {}
57+ if err := suite .Client .Get (restoreCtx , cmKey , cm ); err != nil {
58+ t .Logf ("could not fetch envoy-gateway-config for restore: %v" , err )
59+ return
60+ }
61+ cm .Data = originalData
62+ if err := suite .Client .Update (restoreCtx , cm ); err != nil {
63+ t .Logf ("failed to restore envoy-gateway-config: %v" , err )
64+ return
65+ }
66+ if err := suite .Kube ().ScaleDeploymentAndWait (restoreCtx , envoygateway , namespace , 0 , time .Minute , false ); err != nil {
67+ t .Logf ("failed to scale down envoy-gateway during restore: %v" , err )
68+ }
69+ if err := suite .Kube ().ScaleDeploymentAndWait (restoreCtx , envoygateway , namespace , 1 , time .Minute , false ); err != nil {
70+ t .Logf ("failed to scale up envoy-gateway during restore: %v" , err )
71+ }
72+ })
73+
74+ // Apply the multi-manager ConfigMap (cleanup=false so the Applier does not Delete
75+ // the pre-existing helm-owned resource; the restore Cleanup above handles teardown)
76+ // and restart the control plane to pick it up.
77+ ap .MustApplyWithCleanup (t , suite .Client , suite .TimeoutConfig , "testdata/config_multiple_ext_managers.yaml" , false )
4078 err := suite .Kube ().ScaleDeploymentAndWait (ctx , envoygateway , namespace , 0 , time .Minute , false )
4179 require .NoError (t , err , "Failed to scale down envoy-gateway" )
4280 err = suite .Kube ().ScaleDeploymentAndWait (ctx , envoygateway , namespace , 1 , time .Minute , false )
@@ -48,7 +86,7 @@ var MultipleExtManagers = suite.ResilienceTest{
4886 localTimeout .RequiredConsecutiveSuccesses = 2
4987 localTimeout .MaxTimeToConsistency = time .Minute
5088
51- t .Run ("chaining applies both VirtualHost mutations in order" , func (t * testing.T ) {
89+ t .Run ("Chaining applies both VirtualHost mutations in order" , func (t * testing.T ) {
5290 ns := "gateway-resilience"
5391 routeNN := types.NamespacedName {Name : "chaining-route" , Namespace : ns }
5492 gwNN := types.NamespacedName {Name : "all-namespaces" , Namespace : ns }
@@ -81,12 +119,11 @@ var MultipleExtManagers = suite.ResilienceTest{
81119 })
82120 })
83121
84- t .Run ("resource isolation: only owning extension receives resources" , func (t * testing.T ) {
122+ t .Run ("Resource isolation: only owning extension receives resources" , func (t * testing.T ) {
85123 ns := "gateway-resilience"
86124 routeNN := types.NamespacedName {Name : "isolation-route" , Namespace : ns }
87125 gwNN := types.NamespacedName {Name : "all-namespaces" , Namespace : ns }
88126
89- ap .MustApplyWithCleanup (t , suite .Client , suite .TimeoutConfig , "testdata/extension_crds.yaml" , true )
90127 ap .MustApplyWithCleanup (t , suite .Client , suite .TimeoutConfig , "testdata/route_for_resource_isolation.yaml" , true )
91128 gwAddr := kubernetes .GatewayAndRoutesMustBeAccepted (t , suite .Client , suite .TimeoutConfig , suite .ControllerName , kubernetes .NewGatewayRef (gwNN ), & gwapiv1.HTTPRoute {}, false , routeNN )
92129
0 commit comments