diff --git a/changelog/v1.17.17/remove-hardcoded-namespace-in-tracing-test-v1.17.x.yaml b/changelog/v1.17.17/remove-hardcoded-namespace-in-tracing-test-v1.17.x.yaml new file mode 100644 index 00000000000..3692f1b47e7 --- /dev/null +++ b/changelog/v1.17.17/remove-hardcoded-namespace-in-tracing-test-v1.17.x.yaml @@ -0,0 +1,11 @@ +changelog: + - type: NON_USER_FACING + description: >- + Fix failing unit tests in `test/kubernetes/testutils/helper/util_test.go` + and `test/kubernetes/testutils/helper/util_test.go` + - type: NON_USER_FACING + issueLink: https://github.com/solo-io/solo-projects/issues/7223 + resolvesIssue: false + description: >- + Remove hard-coded namespaces from the tracing tests. This issue is + causing tests to pass in OSS gloo, but fail in solo-projects. diff --git a/test/kube2e/upgrade/upgrade_utils_test.go b/test/kube2e/upgrade/upgrade_utils_test.go index b12948c79bb..6be4156498a 100644 --- a/test/kube2e/upgrade/upgrade_utils_test.go +++ b/test/kube2e/upgrade/upgrade_utils_test.go @@ -26,9 +26,9 @@ var _ = Describe("upgrade utils unit tests", func() { It("should return latest patch", func() { ctx := context.Background() client, _ := githubutils.GetClient(ctx) - minor, err := getLatestReleasedPatchVersion(ctx, client, "gloo", 1, 8) + minor, err := getLatestReleasedPatchVersion(ctx, client, "gloo", 1, 9) Expect(err).NotTo(HaveOccurred()) - Expect(minor.String()).To(Equal("v1.8.37")) + Expect(minor.String()).To(Equal("v1.9.30")) }) }) diff --git a/test/kubernetes/e2e/features/tracing/suite.go b/test/kubernetes/e2e/features/tracing/suite.go index 5a9a6235345..c1d2a3034e2 100644 --- a/test/kubernetes/e2e/features/tracing/suite.go +++ b/test/kubernetes/e2e/features/tracing/suite.go @@ -7,9 +7,13 @@ import ( "github.com/solo-io/gloo/pkg/utils/kubeutils" "github.com/solo-io/gloo/pkg/utils/requestutils/curl" + gloo_defaults "github.com/solo-io/gloo/projects/gloo/pkg/defaults" "github.com/solo-io/gloo/test/gomega/matchers" "github.com/solo-io/gloo/test/kubernetes/e2e" testdefaults "github.com/solo-io/gloo/test/kubernetes/e2e/defaults" + "github.com/solo-io/solo-kit/pkg/api/v1/clients" + "github.com/solo-io/solo-kit/pkg/api/v1/resources" + "github.com/solo-io/solo-kit/pkg/api/v1/resources/core" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -94,15 +98,38 @@ func (s *testingSuite) BeforeTest(string, string) { otelcolSelector, ) - // Attempt to apply tracingConfigManifest multiple times. The first time - // fails regularly with this message: "failed to validate Proxy [namespace: - // gloo-gateway-edge-test, name: gateway-proxy] with gloo validation: - // HttpListener Error: ProcessingError. Reason: *v1.Upstream { - // default.opentelemetry-collector } not found" - s.Assert().Eventually(func() bool { - err := s.testInstallation.Actions.Kubectl().ApplyFile(s.ctx, tracingConfigManifest) - return err == nil - }, time.Second*30, time.Second*5, "can apply gloo tracing config") + err = s.testInstallation.Actions.Kubectl().ApplyFile(s.ctx, tracingConfigManifest) + s.NoError(err, "can apply gloo tracing resources") + // accept the upstream + s.testInstallation.Assertions.EventuallyResourceStatusMatchesState( + func() (resources.InputResource, error) { + return s.testInstallation.ResourceClients.UpstreamClient().Read( + otelcolUpstream.Namespace, otelcolUpstream.Name, clients.ReadOpts{Ctx: s.ctx}) + }, + core.Status_Accepted, + gloo_defaults.GlooReporter, + ) + // accept the virtual service + s.testInstallation.Assertions.EventuallyResourceStatusMatchesState( + func() (resources.InputResource, error) { + return s.testInstallation.ResourceClients.VirtualServiceClient().Read( + tracingVs.Namespace, tracingVs.Name, clients.ReadOpts{Ctx: s.ctx}) + }, + core.Status_Accepted, + gloo_defaults.GlooReporter, + ) + + err = s.testInstallation.Actions.Kubectl().ApplyFile(s.ctx, gatewayConfigManifest, + "-n", s.testInstallation.Metadata.InstallNamespace) + s.NoError(err, "can create gateway and service") + s.testInstallation.Assertions.EventuallyResourceStatusMatchesState( + func() (resources.InputResource, error) { + return s.testInstallation.ResourceClients.GatewayClient().Read( + s.testInstallation.Metadata.InstallNamespace, "gateway-proxy-tracing", clients.ReadOpts{Ctx: s.ctx}) + }, + core.Status_Accepted, + gloo_defaults.GlooReporter, + ) } func (s *testingSuite) AfterTest(string, string) { @@ -112,6 +139,10 @@ func (s *testingSuite) AfterTest(string, string) { err = s.testInstallation.Actions.Kubectl().DeleteFile(s.ctx, tracingConfigManifest) s.Assertions.NoError(err, "can delete gloo tracing config") + + err = s.testInstallation.Actions.Kubectl().DeleteFile(s.ctx, gatewayConfigManifest, + "-n", s.testInstallation.Metadata.InstallNamespace) + s.Assertions.NoError(err, "can delete gloo tracing config") } func (s *testingSuite) TestSpanNameTransformationsWithoutRouteDecorator() { @@ -125,10 +156,12 @@ func (s *testingSuite) TestSpanNameTransformationsWithoutRouteDecorator() { curl.WithHostHeader(testHostname), curl.WithPort(gatewayProxyPort), curl.WithPath(pathWithoutRouteDescriptor), + curl.Silent(), }, &matchers.HttpResponse{ StatusCode: http.StatusOK, }, + 5*time.Second, 30*time.Second, ) s.EventuallyWithT(func(c *assert.CollectT) { @@ -150,10 +183,12 @@ func (s *testingSuite) TestSpanNameTransformationsWithRouteDecorator() { curl.WithHostHeader("example.com"), curl.WithPort(gatewayProxyPort), curl.WithPath(pathWithRouteDescriptor), + curl.Silent(), }, &matchers.HttpResponse{ StatusCode: http.StatusOK, }, + 5*time.Second, 30*time.Second, ) s.EventuallyWithT(func(c *assert.CollectT) { diff --git a/test/kubernetes/e2e/features/tracing/testdata/gateway.yaml b/test/kubernetes/e2e/features/tracing/testdata/gateway.yaml new file mode 100644 index 00000000000..7a04283601e --- /dev/null +++ b/test/kubernetes/e2e/features/tracing/testdata/gateway.yaml @@ -0,0 +1,42 @@ +# Avoid using the default gateway because we don't want to destroy it when this +# test is over - that will break other tests that depend on the default gateway +# existing. +apiVersion: gateway.solo.io/v1 +kind: Gateway +metadata: + labels: + app: gloo + app.kubernetes.io/name: gateway-proxy-tracing + name: gateway-proxy-tracing +spec: + bindAddress: '::' + bindPort: 18080 + proxyNames: + - gateway-proxy + httpGateway: + virtualServiceSelector: + gateway-type: tracing + options: + httpConnectionManagerSettings: + tracing: + openTelemetryConfig: + collectorUpstreamRef: + name: opentelemetry-collector + namespace: default +--- +apiVersion: v1 +kind: Service +metadata: + name: gateway-proxy-tracing + labels: + app.kubernetes.io/name: gateway-proxy-tracing-service +spec: + ports: + - name: gateway-proxy-tracing + port: 18080 + protocol: TCP + targetPort: 18080 + selector: + gateway-proxy: live + gateway-proxy-id: gateway-proxy + diff --git a/test/kubernetes/e2e/features/tracing/testdata/tracing.yaml b/test/kubernetes/e2e/features/tracing/testdata/tracing.yaml index a2dc5f904c5..93718e56a6d 100644 --- a/test/kubernetes/e2e/features/tracing/testdata/tracing.yaml +++ b/test/kubernetes/e2e/features/tracing/testdata/tracing.yaml @@ -31,7 +31,8 @@ spec: apiVersion: gateway.solo.io/v1 kind: VirtualService metadata: - name: default + name: virtual-service + namespace: default labels: gateway-type: tracing spec: @@ -71,47 +72,3 @@ spec: autoHostRewrite: true tracing: routeDescriptor: THISISAROUTEDESCRIPTOR ---- -# Avoid using the default gateway because we don't want to destroy it when this -# test is over - that will break other tests that depend on the default gateway -# existing. -apiVersion: gateway.solo.io/v1 -kind: Gateway -metadata: - labels: - app: gloo - app.kubernetes.io/name: gateway-proxy-tracing - name: gateway-proxy-tracing - namespace: gloo-gateway-edge-test -spec: - bindAddress: '::' - bindPort: 18080 - proxyNames: - - gateway-proxy - httpGateway: - virtualServiceSelector: - gateway-type: tracing - options: - httpConnectionManagerSettings: - tracing: - openTelemetryConfig: - collectorUpstreamRef: - name: opentelemetry-collector - namespace: default ---- -apiVersion: v1 -kind: Service -metadata: - name: gateway-proxy-tracing - namespace: gloo-gateway-edge-test - labels: - app.kubernetes.io/name: gateway-proxy-tracing-service -spec: - ports: - - name: gateway-proxy-tracing - port: 18080 - protocol: TCP - targetPort: 18080 - selector: - gateway-proxy: live - gateway-proxy-id: gateway-proxy diff --git a/test/kubernetes/e2e/features/tracing/types.go b/test/kubernetes/e2e/features/tracing/types.go index 4c4883e0201..1ea872ed746 100644 --- a/test/kubernetes/e2e/features/tracing/types.go +++ b/test/kubernetes/e2e/features/tracing/types.go @@ -19,6 +19,7 @@ const ( var ( setupOtelcolManifest = filepath.Join(util.MustGetThisDir(), "testdata", "setup-otelcol.yaml") tracingConfigManifest = filepath.Join(util.MustGetThisDir(), "testdata", "tracing.yaml") + gatewayConfigManifest = filepath.Join(util.MustGetThisDir(), "testdata", "gateway.yaml") otelcolPod = &corev1.Pod{ ObjectMeta: metav1.ObjectMeta{Name: "otel-collector", Namespace: "default"}, @@ -26,4 +27,12 @@ var ( otelcolSelector = metav1.ListOptions{ LabelSelector: "app.kubernetes.io/name=otel-collector", } + otelcolUpstream = &metav1.ObjectMeta{ + Name: "opentelemetry-collector", + Namespace: "default", + } + tracingVs = &metav1.ObjectMeta{ + Name: "virtual-service", + Namespace: "default", + } ) diff --git a/test/kubernetes/testutils/helper/util_test.go b/test/kubernetes/testutils/helper/util_test.go index 91a8a4ac272..ed8c891639b 100644 --- a/test/kubernetes/testutils/helper/util_test.go +++ b/test/kubernetes/testutils/helper/util_test.go @@ -23,8 +23,8 @@ func TestReturnsLatestPatchForMinor(t *testing.T) { ctx := context.Background() // this is fine because this is a public repo client := githubutils.GetClientWithOrWithoutToken(ctx) - minor, err := getLatestReleasedPatchVersion(ctx, client, "gloo", 1, 8) + minor, err := getLatestReleasedPatchVersion(ctx, client, "gloo", 1, 9) require.NoError(t, err) - assert.Equal(t, "v1.8.37", minor.String()) + assert.Equal(t, "v1.9.30", minor.String()) }