@@ -36,7 +36,7 @@ var EnvoyProxyCustomNameTest = suite.ConformanceTest{
3636 Description : "Test running Envoy with custom name" ,
3737 Manifests : []string {"testdata/envoyproxy-custom-name.yaml" },
3838 Test : func (t * testing.T , suite * suite.ConformanceTestSuite ) {
39- gatwayNS := GetGatewayResourceNamespace ()
39+ gatewayNS := GetGatewayResourceNamespace ()
4040
4141 t .Run ("Deployment" , func (t * testing.T ) {
4242 ns := "gateway-conformance-infra"
@@ -53,79 +53,58 @@ var EnvoyProxyCustomNameTest = suite.ConformanceTest{
5353 }
5454
5555 // Make sure there's deployment for the gateway
56- err := checkEnvoyProxyDeployment (t , suite , gwNN , gatwayNS , fmt .Sprintf ("envoy-%s-%s" , gwNN .Namespace , gwNN .Name ))
56+ err := checkEnvoyProxyDeployment (t , suite , gwNN , gatewayNS , fmt .Sprintf ("envoy-%s-%s" , gwNN .Namespace , gwNN .Name ))
5757 if err != nil {
5858 t .Fatalf ("Failed to check EnvoyProxy deployment: %v" , err )
5959 }
60- err = checkEnvoyProxyService (t , suite , gwNN , gatwayNS , fmt .Sprintf ("envoy-%s-%s" , gwNN .Namespace , gwNN .Name ))
60+ err = checkEnvoyProxyService (t , suite , gwNN , gatewayNS , fmt .Sprintf ("envoy-%s-%s" , gwNN .Namespace , gwNN .Name ))
6161 if err != nil {
6262 t .Fatalf ("Failed to check EnvoyProxy service: %v" , err )
6363 }
64- gwAddr := kubernetes .GatewayAndHTTPRoutesMustBeAccepted (t , suite .Client , suite .TimeoutConfig , suite .ControllerName , kubernetes .NewGatewayRef (gwNN ), routeNN )
6564 // Send a request to a valid path and expect a successful response
66- http . MakeRequestAndExpectEventuallyConsistentResponse (t , suite . RoundTripper , suite . TimeoutConfig , gwAddr , okResp )
65+ ExpectEventuallyConsistentResponse (t , suite , gwNN , routeNN , okResp )
6766
6867 // Update the Gateway to use a custom name
69- gw := & gwapiv1.Gateway {}
70- err = suite .Client .Get (context .Background (), gwNN , gw )
71- if err != nil {
72- t .Fatalf ("Failed to get Gateway: %v" , err )
73- }
74- gw .Spec .Infrastructure = & gwapiv1.GatewayInfrastructure {
68+ updateGateway (t , suite , gwNN , & gwapiv1.GatewayInfrastructure {
7569 ParametersRef : & gwapiv1.LocalParametersReference {
7670 Name : "deploy-custom-name" ,
7771 Kind : "EnvoyProxy" ,
7872 Group : "gateway.envoyproxy.io" ,
7973 },
80- }
81- err = suite .Client .Update (context .Background (), gw )
82- if err != nil {
83- t .Fatalf ("Failed to update Gateway: %v" , err )
84- }
74+ })
8575
86- err = checkEnvoyProxyDeployment (t , suite , gwNN , gatwayNS , "deploy-custom-name" )
76+ err = checkEnvoyProxyDeployment (t , suite , gwNN , gatewayNS , "deploy-custom-name" )
8777 if err != nil {
8878 t .Fatalf ("Failed to delete Gateway: %v" , err )
8979 }
90- err = checkEnvoyProxyService (t , suite , gwNN , gatwayNS , "deploy-custom-name" )
80+ err = checkEnvoyProxyService (t , suite , gwNN , gatewayNS , "deploy-custom-name" )
9181 if err != nil {
9282 t .Fatalf ("Failed to check EnvoyProxy service: %v" , err )
9383 }
94- gwAddr = kubernetes .GatewayAndHTTPRoutesMustBeAccepted (t , suite .Client , suite .TimeoutConfig , suite .ControllerName , kubernetes .NewGatewayRef (gwNN ), routeNN )
9584 // Send a request to a valid path and expect a successful response
96- http . MakeRequestAndExpectEventuallyConsistentResponse (t , suite . RoundTripper , suite . TimeoutConfig , gwAddr , okResp )
85+ ExpectEventuallyConsistentResponse (t , suite , gwNN , routeNN , okResp )
9786
9887 // Rollback the Gateway to without custom name
99- gw = & gwapiv1.Gateway {}
100- err = suite .Client .Get (context .Background (), gwNN , gw )
101- if err != nil {
102- t .Fatalf ("Failed to get Gateway: %v" , err )
103- }
104- gw .Spec .Infrastructure = & gwapiv1.GatewayInfrastructure {}
105- err = suite .Client .Update (context .Background (), gw )
106- if err != nil {
107- t .Fatalf ("Failed to update Gateway: %v" , err )
108- }
88+ updateGateway (t , suite , gwNN , & gwapiv1.GatewayInfrastructure {})
10989
11090 // Make sure there's deployment for the gateway
111- err = checkEnvoyProxyDeployment (t , suite , gwNN , gatwayNS , fmt .Sprintf ("envoy-%s-%s" , gwNN .Namespace , gwNN .Name ))
91+ err = checkEnvoyProxyDeployment (t , suite , gwNN , gatewayNS , fmt .Sprintf ("envoy-%s-%s" , gwNN .Namespace , gwNN .Name ))
11292 if err != nil {
11393 t .Fatalf ("Failed to check EnvoyProxy deployment: %v" , err )
11494 }
115- err = checkEnvoyProxyService (t , suite , gwNN , gatwayNS , fmt .Sprintf ("envoy-%s-%s" , gwNN .Namespace , gwNN .Name ))
95+ err = checkEnvoyProxyService (t , suite , gwNN , gatewayNS , fmt .Sprintf ("envoy-%s-%s" , gwNN .Namespace , gwNN .Name ))
11696 if err != nil {
11797 t .Fatalf ("Failed to check EnvoyProxy service: %v" , err )
11898 }
119- gwAddr = kubernetes .GatewayAndHTTPRoutesMustBeAccepted (t , suite .Client , suite .TimeoutConfig , suite .ControllerName , kubernetes .NewGatewayRef (gwNN ), routeNN )
12099 // Send a request to a valid path and expect a successful response
121- http . MakeRequestAndExpectEventuallyConsistentResponse (t , suite . RoundTripper , suite . TimeoutConfig , gwAddr , okResp )
100+ ExpectEventuallyConsistentResponse (t , suite , gwNN , routeNN , okResp )
122101 })
123102
124103 t .Run ("DaemonSet" , func (t * testing.T ) {
125104 ns := "gateway-conformance-infra"
126105 routeNN := types.NamespacedName {Name : "ds-route" , Namespace : ns }
127106 gwNN := types.NamespacedName {Name : "ds-custom-name" , Namespace : ns }
128- OkResp := http.ExpectedResponse {
107+ okResp := http.ExpectedResponse {
129108 Request : http.Request {
130109 Path : "/daemonset" ,
131110 },
@@ -136,82 +115,115 @@ var EnvoyProxyCustomNameTest = suite.ConformanceTest{
136115 }
137116
138117 // Make sure there's DaemonSet for the gateway
139- err := checkEnvoyProxyDaemonSet (t , suite , gwNN , gatwayNS , fmt .Sprintf ("envoy-%s-%s" , gwNN .Namespace , gwNN .Name ))
118+ err := checkEnvoyProxyDaemonSet (t , suite , gwNN , gatewayNS , fmt .Sprintf ("envoy-%s-%s" , gwNN .Namespace , gwNN .Name ))
140119 if err != nil {
141120 t .Fatalf ("Failed to check EnvoyProxy deployment: %v" , err )
142121 }
143- err = checkEnvoyProxyService (t , suite , gwNN , gatwayNS , fmt .Sprintf ("envoy-%s-%s" , gwNN .Namespace , gwNN .Name ))
122+ err = checkEnvoyProxyService (t , suite , gwNN , gatewayNS , fmt .Sprintf ("envoy-%s-%s" , gwNN .Namespace , gwNN .Name ))
144123 if err != nil {
145124 t .Fatalf ("Failed to check EnvoyProxy service: %v" , err )
146125 }
147- gwAddr := kubernetes .GatewayAndHTTPRoutesMustBeAccepted (t , suite .Client , suite .TimeoutConfig , suite .ControllerName , kubernetes .NewGatewayRef (gwNN ), routeNN )
148126 // Send a request to a valid path and expect a successful response
149- http . MakeRequestAndExpectEventuallyConsistentResponse (t , suite . RoundTripper , suite . TimeoutConfig , gwAddr , OkResp )
127+ ExpectEventuallyConsistentResponse (t , suite , gwNN , routeNN , okResp )
150128
151129 // Update the Gateway to use a custom name
152- gw := & gwapiv1.Gateway {}
153- err = suite .Client .Get (context .Background (), gwNN , gw )
154- if err != nil {
155- t .Fatalf ("Failed to get Gateway: %v" , err )
156- }
157- gw .Spec .Infrastructure = & gwapiv1.GatewayInfrastructure {
130+ updateGateway (t , suite , gwNN , & gwapiv1.GatewayInfrastructure {
158131 ParametersRef : & gwapiv1.LocalParametersReference {
159132 Name : "ds-custom-name" ,
160133 Kind : "EnvoyProxy" ,
161134 Group : "gateway.envoyproxy.io" ,
162135 },
163- }
164- err = suite .Client .Update (context .Background (), gw )
165- if err != nil {
166- t .Fatalf ("Failed to update Gateway: %v" , err )
167- }
136+ })
168137
169- err = checkEnvoyProxyDaemonSet (t , suite , gwNN , gatwayNS , "ds-custom-name" )
138+ err = checkEnvoyProxyDaemonSet (t , suite , gwNN , gatewayNS , "ds-custom-name" )
170139 if err != nil {
171140 t .Fatalf ("Failed to delete Gateway: %v" , err )
172141 }
173- err = checkEnvoyProxyService (t , suite , gwNN , gatwayNS , "ds-custom-name" )
142+ err = checkEnvoyProxyService (t , suite , gwNN , gatewayNS , "ds-custom-name" )
174143 if err != nil {
175144 t .Fatalf ("Failed to check EnvoyProxy service: %v" , err )
176145 }
177- gwAddr = kubernetes .GatewayAndHTTPRoutesMustBeAccepted (t , suite .Client , suite .TimeoutConfig , suite .ControllerName , kubernetes .NewGatewayRef (gwNN ), routeNN )
178146 // Send a request to a valid path and expect a successful response
179- http . MakeRequestAndExpectEventuallyConsistentResponse (t , suite . RoundTripper , suite . TimeoutConfig , gwAddr , OkResp )
147+ ExpectEventuallyConsistentResponse (t , suite , gwNN , routeNN , okResp )
180148
181149 // Rollback the Gateway to without custom name
182- gw = & gwapiv1.Gateway {}
183- err = suite .Client .Get (context .Background (), gwNN , gw )
184- if err != nil {
185- t .Fatalf ("Failed to get Gateway: %v" , err )
186- }
187- gw .Spec .Infrastructure = & gwapiv1.GatewayInfrastructure {
150+ updateGateway (t , suite , gwNN , & gwapiv1.GatewayInfrastructure {
188151 ParametersRef : & gwapiv1.LocalParametersReference {
189152 Name : "eg-daemonset" ,
190153 Kind : "EnvoyProxy" ,
191154 Group : "gateway.envoyproxy.io" ,
192155 },
193- }
194- err = suite .Client .Update (context .Background (), gw )
195- if err != nil {
196- t .Fatalf ("Failed to update Gateway: %v" , err )
197- }
156+ })
198157
199158 // Make sure there's DaemonSet for the gateway
200- err = checkEnvoyProxyDaemonSet (t , suite , gwNN , gatwayNS , fmt .Sprintf ("envoy-%s-%s" , gwNN .Namespace , gwNN .Name ))
159+ err = checkEnvoyProxyDaemonSet (t , suite , gwNN , gatewayNS , fmt .Sprintf ("envoy-%s-%s" , gwNN .Namespace , gwNN .Name ))
201160 if err != nil {
202161 t .Fatalf ("Failed to check EnvoyProxy deployment: %v" , err )
203162 }
204- err = checkEnvoyProxyService (t , suite , gwNN , gatwayNS , fmt .Sprintf ("envoy-%s-%s" , gwNN .Namespace , gwNN .Name ))
163+ err = checkEnvoyProxyService (t , suite , gwNN , gatewayNS , fmt .Sprintf ("envoy-%s-%s" , gwNN .Namespace , gwNN .Name ))
205164 if err != nil {
206165 t .Fatalf ("Failed to check EnvoyProxy service: %v" , err )
207166 }
208- gwAddr = kubernetes . GatewayAndHTTPRoutesMustBeAccepted ( t , suite . Client , suite . TimeoutConfig , suite . ControllerName , kubernetes . NewGatewayRef ( gwNN ), routeNN )
167+
209168 // Send a request to a valid path and expect a successful response
210- http . MakeRequestAndExpectEventuallyConsistentResponse (t , suite . RoundTripper , suite . TimeoutConfig , gwAddr , OkResp )
169+ ExpectEventuallyConsistentResponse (t , suite , gwNN , routeNN , okResp )
211170 })
212171 },
213172}
214173
174+ func updateGateway (t * testing.T , suite * suite.ConformanceTestSuite , gwNN types.NamespacedName , paramRef * gwapiv1.GatewayInfrastructure ) {
175+ err := wait .PollUntilContextTimeout (t .Context (), time .Second , suite .TimeoutConfig .CreateTimeout , true ,
176+ func (ctx context.Context ) (bool , error ) {
177+ gw := & gwapiv1.Gateway {}
178+ err := suite .Client .Get (context .Background (), gwNN , gw )
179+ if err != nil {
180+ tlog .Logf (t , "Failed to get Gateway %s: %v" , gwNN , err )
181+ return false , err
182+ }
183+ gw .Spec .Infrastructure = paramRef
184+ err = suite .Client .Update (context .Background (), gw )
185+ if err != nil {
186+ tlog .Logf (t , "Failed to update Gateway %s: %v" , gwNN , err )
187+ return false , err
188+ }
189+ return true , nil
190+ })
191+ if err != nil {
192+ t .Fatalf ("Failed to patch Gateway %s: %v" , gwNN , err )
193+ }
194+ }
195+
196+ // ExpectEventuallyConsistentResponse sends a request to the gateway and waits for an eventually consistent response.
197+ // This's different from because of the name may change, so we query the gateway address every time.
198+ func ExpectEventuallyConsistentResponse (t * testing.T , suite * suite.ConformanceTestSuite ,
199+ gwNN , routeNN types.NamespacedName , expected http.ExpectedResponse ,
200+ ) {
201+ t .Helper ()
202+
203+ err := wait .PollUntilContextTimeout (t .Context (), time .Second , suite .TimeoutConfig .CreateTimeout , true , func (ctx context.Context ) (bool , error ) {
204+ gwAddr := kubernetes .GatewayAndHTTPRoutesMustBeAccepted (t , suite .Client , suite .TimeoutConfig , suite .ControllerName , kubernetes .NewGatewayRef (gwNN ), routeNN )
205+ req := http .MakeRequest (t , & expected , gwAddr , "HTTP" , "http" )
206+
207+ cReq , cRes , err := suite .RoundTripper .CaptureRoundTrip (req )
208+ if err != nil {
209+ tlog .Logf (t , "Request failed: %v" , err .Error ())
210+ return false , nil
211+ }
212+
213+ if err := http .CompareRequest (t , & req , cReq , cRes , expected ); err != nil {
214+ tlog .Logf (t , "Response expectation failed for request: %+v %v" , req , err )
215+ return false , nil
216+ }
217+
218+ return true , nil
219+ })
220+ if err != nil {
221+ t .Fatalf ("Failed to get expected response: %v" , err )
222+ return
223+ }
224+ tlog .Logf (t , "Request passed" )
225+ }
226+
215227func checkEnvoyProxyDeployment (t * testing.T , suite * suite.ConformanceTestSuite , gwNN types.NamespacedName , exceptNs , exceptName string ) error {
216228 // Make sure there's deployment for the gateway
217229 return wait .PollUntilContextTimeout (context .TODO (), time .Second , suite .TimeoutConfig .CreateTimeout , true , func (ctx context.Context ) (bool , error ) {
0 commit comments