Skip to content

Commit

Permalink
Merge pull request kgateway-dev#10359 from solo-io/remove-hardcoded-n…
Browse files Browse the repository at this point in the history
…amespace-in-tracing-test-v1.17.x

Remove hardcoded namespace in tracing test v1.17.x
  • Loading branch information
ashishb-solo authored Nov 15, 2024
2 parents 051b0ca + 664f692 commit 7442ffc
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions test/kube2e/upgrade/upgrade_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
})
})

Expand Down
53 changes: 44 additions & 9 deletions test/kubernetes/e2e/features/tracing/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand All @@ -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() {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
42 changes: 42 additions & 0 deletions test/kubernetes/e2e/features/tracing/testdata/gateway.yaml
Original file line number Diff line number Diff line change
@@ -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

47 changes: 2 additions & 45 deletions test/kubernetes/e2e/features/tracing/testdata/tracing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
9 changes: 9 additions & 0 deletions test/kubernetes/e2e/features/tracing/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,20 @@ 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"},
}
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",
}
)
4 changes: 2 additions & 2 deletions test/kubernetes/testutils/helper/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

0 comments on commit 7442ffc

Please sign in to comment.