@@ -53,6 +53,7 @@ tests by ensuring the console output is clean for each test.
53534. parse stdout from otelcol to see if the trace contains the data that we want
5454*/
5555
56+ // SetupSuite installs the echo-server and curl pods
5657func (s * testingSuite ) SetupSuite () {
5758 var err error
5859
@@ -91,6 +92,7 @@ func (s *testingSuite) SetupSuite() {
9192 s .NoError (err , "can apply service/gateway-proxy-tracing" )
9293}
9394
95+ // TearDownSuite cleans up the resources created in SetupSuite
9496func (s * testingSuite ) TearDownSuite () {
9597 var err error
9698
@@ -105,6 +107,7 @@ func (s *testingSuite) TearDownSuite() {
105107 s .NoError (err , "can delete service/gateway-proxy-tracing" )
106108}
107109
110+ // BeforeTest sets up the common resources (otel, upstreams, virtual services)
108111func (s * testingSuite ) BeforeTest (string , string ) {
109112 var err error
110113
@@ -138,10 +141,24 @@ func (s *testingSuite) BeforeTest(string, string) {
138141 core .Status_Accepted ,
139142 gloo_defaults .GlooReporter ,
140143 )
144+ }
145+
146+ // AfterTest cleans up the common resources (otel, upstreams, virtual services)
147+ func (s * testingSuite ) AfterTest (string , string ) {
148+ var err error
149+ err = s .testInstallation .Actions .Kubectl ().DeleteFile (s .ctx , setupOtelcolManifest )
150+ s .Assertions .NoError (err , "can delete otel collector" )
141151
142- err = s .testInstallation .Actions .Kubectl ().ApplyFile (s .ctx , gatewayConfigManifest ,
152+ err = s .testInstallation .Actions .Kubectl ().DeleteFile (s .ctx , tracingConfigManifest )
153+ s .Assertions .NoError (err , "can delete gloo tracing config" )
154+ }
155+
156+ // BeforeGlooGatewayTest sets up the Gloo Gateway resources
157+ func (s * testingSuite ) BeforeGlooGatewayTest () {
158+ err := s .testInstallation .Actions .Kubectl ().ApplyFile (s .ctx , gatewayConfigManifest ,
143159 "-n" , s .testInstallation .Metadata .InstallNamespace )
144160 s .NoError (err , "can create gateway and service" )
161+
145162 s .testInstallation .Assertions .EventuallyResourceStatusMatchesState (
146163 func () (resources.InputResource , error ) {
147164 return s .testInstallation .ResourceClients .GatewayClient ().Read (
@@ -152,20 +169,39 @@ func (s *testingSuite) BeforeTest(string, string) {
152169 )
153170}
154171
155- func (s * testingSuite ) AfterTest (string , string ) {
156- var err error
157- err = s .testInstallation .Actions .Kubectl ().DeleteFile (s .ctx , setupOtelcolManifest )
158- s .Assertions .NoError (err , "can delete otel collector" )
159-
160- err = s .testInstallation .Actions .Kubectl ().DeleteFile (s .ctx , tracingConfigManifest )
161- s .Assertions .NoError (err , "can delete gloo tracing config" )
162-
163- err = s .testInstallation .Actions .Kubectl ().DeleteFile (s .ctx , gatewayConfigManifest ,
172+ // AfterGlooGatewayTest cleans up the Gloo Gateway resources
173+ func (s * testingSuite ) AfterGlooGatewayTest () {
174+ err := s .testInstallation .Actions .Kubectl ().DeleteFile (s .ctx , gatewayConfigManifest ,
164175 "-n" , s .testInstallation .Metadata .InstallNamespace )
165176 s .Assertions .NoError (err , "can delete gateway config" )
166177}
167178
168- func (s * testingSuite ) TestSpanNameTransformationsWithoutRouteDecorator () {
179+ // BeforeK8sGatewayTest sets up the K8s Gateway resources
180+ func (s * testingSuite ) BeforeK8sGatewayTest (hloManifest string ) {
181+ if ! s .testInstallation .Metadata .K8sGatewayEnabled {
182+ s .T ().Skip ("Installation of Gloo Gateway does not have K8s Gateway enabled, skipping test as there is nothing to test" )
183+ }
184+
185+ s .T ().Cleanup (func () {
186+ err := s .testInstallation .Actions .Kubectl ().DeleteFile (s .ctx , k8sGatewayManifest )
187+ s .Assertions .NoError (err , "cannot delete k8s gateway resources" )
188+
189+ err = s .testInstallation .Actions .Kubectl ().DeleteFile (s .ctx , hloManifest )
190+ s .Assertions .NoError (err , "cannot delete k8s gateway hlo" )
191+ })
192+
193+ err := s .testInstallation .Actions .Kubectl ().ApplyFile (s .ctx , hloManifest )
194+ s .Assertions .NoError (err , "can apply k8s gateway hlo" )
195+
196+ err = s .testInstallation .Actions .Kubectl ().ApplyFile (s .ctx , k8sGatewayManifest )
197+ s .Assertions .NoError (err , "can apply k8s gateway resources" )
198+
199+ s .testInstallation .Assertions .EventuallyObjectsExist (s .ctx , proxyService , proxyDeployment )
200+ }
201+
202+ func (s * testingSuite ) TestGlooGatewaySpanNameTransformationsWithoutRouteDecorator () {
203+ s .BeforeGlooGatewayTest ()
204+
169205 testHostname := "test-really-cool-hostname.com"
170206 s .testInstallation .Assertions .AssertEventuallyConsistentCurlResponse (s .ctx , testdefaults .CurlPodExecOpt ,
171207 []curl.Option {
@@ -191,9 +227,13 @@ func (s *testingSuite) TestSpanNameTransformationsWithoutRouteDecorator() {
191227 // Name : <value of host header>
192228 assert .Regexp (c , "Name *: " + testHostname , logs )
193229 }, time .Second * 30 , time .Second * 3 , "otelcol logs contain span with name == hostname" )
230+
231+ s .AfterGlooGatewayTest ()
194232}
195233
196- func (s * testingSuite ) TestSpanNameTransformationsWithRouteDecorator () {
234+ func (s * testingSuite ) TestGlooGatewaySpanNameTransformationsWithRouteDecorator () {
235+ s .BeforeGlooGatewayTest ()
236+
197237 s .testInstallation .Assertions .AssertEventuallyConsistentCurlResponse (s .ctx , testdefaults .CurlPodExecOpt ,
198238 []curl.Option {
199239 curl .WithHost (kubeutils .ServiceFQDN (metav1.ObjectMeta {
@@ -218,9 +258,13 @@ func (s *testingSuite) TestSpanNameTransformationsWithRouteDecorator() {
218258 // Name : <value of routeDescriptorSpanName>
219259 assert .Regexp (c , "Name *: " + routeDescriptorSpanName , logs )
220260 }, time .Second * 30 , time .Second * 3 , "otelcol logs contain span with name == routeDescriptor" )
261+
262+ s .AfterGlooGatewayTest ()
221263}
222264
223- func (s * testingSuite ) TestGatewayWithoutOtelTracingGrpcAuthority () {
265+ func (s * testingSuite ) TestGlooGatewayWithoutOtelTracingGrpcAuthority () {
266+ s .BeforeGlooGatewayTest ()
267+
224268 s .testInstallation .Assertions .AssertEventuallyConsistentCurlResponse (s .ctx , testdefaults .CurlPodExecOpt ,
225269 []curl.Option {
226270 curl .WithHost (kubeutils .ServiceFQDN (metav1.ObjectMeta {
@@ -244,9 +288,20 @@ func (s *testingSuite) TestGatewayWithoutOtelTracingGrpcAuthority() {
244288 assert .Regexp (c , `-> authority: Str\(opentelemetry-collector_default\)` , logs )
245289 //s.Fail("this test is not implemented yet")
246290 }, time .Second * 30 , time .Second * 3 , "otelcol logs contain cluster name as authority" )
291+
292+ s .AfterGlooGatewayTest ()
247293}
248294
249- func (s * testingSuite ) TestGatewayWithOtelTracingGrpcAuthority () {
295+ func (s * testingSuite ) TestGlooGatewayWithOtelTracingGrpcAuthority () {
296+ s .BeforeGlooGatewayTest ()
297+
298+ s .T ().Cleanup (func () {
299+ // cleanup the gateway
300+ err := s .testInstallation .Actions .Kubectl ().DeleteFile (s .ctx , gatewayAuthorityConfigManifest ,
301+ "-n" , s .testInstallation .Metadata .InstallNamespace )
302+ s .Assertions .NoError (err , "can delete gateway config" )
303+ })
304+
250305 // create new gateway with grpc authority set
251306 err := s .testInstallation .Actions .Kubectl ().ApplyFile (s .ctx , gatewayAuthorityConfigManifest ,
252307 "-n" , s .testInstallation .Metadata .InstallNamespace )
@@ -260,13 +315,6 @@ func (s *testingSuite) TestGatewayWithOtelTracingGrpcAuthority() {
260315 gloo_defaults .GlooReporter ,
261316 )
262317
263- s .T ().Cleanup (func () {
264- // cleanup the gateway
265- err = s .testInstallation .Actions .Kubectl ().DeleteFile (s .ctx , gatewayAuthorityConfigManifest ,
266- "-n" , s .testInstallation .Metadata .InstallNamespace )
267- s .Assertions .NoError (err , "can delete gateway config" )
268- })
269-
270318 s .testInstallation .Assertions .AssertEventuallyConsistentCurlResponse (s .ctx , testdefaults .CurlPodExecOpt ,
271319 []curl.Option {
272320 curl .WithHost (kubeutils .ServiceFQDN (metav1.ObjectMeta {
@@ -292,3 +340,55 @@ func (s *testingSuite) TestGatewayWithOtelTracingGrpcAuthority() {
292340 //s.Fail("this test is not implemented yet")
293341 }, time .Second * 30 , time .Second * 3 , "otelcol logs contain authority set in gateway" )
294342}
343+
344+ func (s * testingSuite ) TestK8sGatewayWithOtelTracing () {
345+ s .BeforeK8sGatewayTest (k8sGatewayHloTracingManifest )
346+
347+ s .testInstallation .Assertions .AssertEventuallyConsistentCurlResponse (
348+ s .ctx ,
349+ testdefaults .CurlPodExecOpt ,
350+ []curl.Option {
351+ curl .WithHost (kubeutils .ServiceFQDN (proxyService .ObjectMeta )),
352+ curl .WithHostHeader ("example.com" ),
353+ curl .Silent (),
354+ },
355+ & matchers.HttpResponse {
356+ StatusCode : http .StatusOK ,
357+ },
358+ 5 * time .Second , 30 * time .Second ,
359+ )
360+
361+ s .EventuallyWithT (func (c * assert.CollectT ) {
362+ logs , err := s .testInstallation .Actions .Kubectl ().GetContainerLogs (s .ctx ,
363+ otelcolPod .ObjectMeta .GetNamespace (), otelcolPod .ObjectMeta .GetName ())
364+ assert .NoError (c , err , "can get otelcol logs" )
365+
366+ assert .Regexp (c , `-> authority: Str\(opentelemetry-collector_default\)` , logs )
367+ }, time .Second * 30 , time .Second * 3 , "otelcol logs contain cluster name as authority" )
368+ }
369+
370+ func (s * testingSuite ) TestK8sGatewayWithOtelTracingGrpcAuthority () {
371+ s .BeforeK8sGatewayTest (k8sGatewayHloAuthorityManifest )
372+
373+ s .testInstallation .Assertions .AssertEventuallyConsistentCurlResponse (
374+ s .ctx ,
375+ testdefaults .CurlPodExecOpt ,
376+ []curl.Option {
377+ curl .WithHost (kubeutils .ServiceFQDN (proxyService .ObjectMeta )),
378+ curl .WithHostHeader ("example.com" ),
379+ curl .Silent (),
380+ },
381+ & matchers.HttpResponse {
382+ StatusCode : http .StatusOK ,
383+ },
384+ 5 * time .Second , 30 * time .Second ,
385+ )
386+
387+ s .EventuallyWithT (func (c * assert.CollectT ) {
388+ logs , err := s .testInstallation .Actions .Kubectl ().GetContainerLogs (s .ctx ,
389+ otelcolPod .ObjectMeta .GetNamespace (), otelcolPod .ObjectMeta .GetName ())
390+ assert .NoError (c , err , "can get otelcol logs" )
391+
392+ assert .Regexp (c , `-> authority: Str\(test-authority\)` , logs )
393+ }, time .Second * 30 , time .Second * 3 , "otelcol logs contain authority set in gateway" )
394+ }
0 commit comments