From 3db9258bd8647c069f9f8244a1361a6d1f6d90a4 Mon Sep 17 00:00:00 2001 From: Nina Polshakova Date: Fri, 9 Aug 2024 09:54:08 -0400 Subject: [PATCH] add edge happy path routing test, changelog (#9870) Co-authored-by: soloio-bulldozer[bot] <48420018+soloio-bulldozer[bot]@users.noreply.github.com> --- .../add-happy-path-routing-test.yaml | 4 + .../e2e/features/basicrouting/edge_suite.go | 114 ++++++++++++++++++ test/kubernetes/e2e/tests/edge_gw_tests.go | 2 + 3 files changed, 120 insertions(+) create mode 100644 changelog/v1.18.0-beta14/add-happy-path-routing-test.yaml create mode 100644 test/kubernetes/e2e/features/basicrouting/edge_suite.go diff --git a/changelog/v1.18.0-beta14/add-happy-path-routing-test.yaml b/changelog/v1.18.0-beta14/add-happy-path-routing-test.yaml new file mode 100644 index 00000000000..d7f7aff19f0 --- /dev/null +++ b/changelog/v1.18.0-beta14/add-happy-path-routing-test.yaml @@ -0,0 +1,4 @@ +changelog: + - type: NON_USER_FACING + description: >- + Adds a happy path routing edge Gateway e2e test. \ No newline at end of file diff --git a/test/kubernetes/e2e/features/basicrouting/edge_suite.go b/test/kubernetes/e2e/features/basicrouting/edge_suite.go new file mode 100644 index 00000000000..35031017cdf --- /dev/null +++ b/test/kubernetes/e2e/features/basicrouting/edge_suite.go @@ -0,0 +1,114 @@ +package basicrouting + +import ( + "context" + "net/http" + + "github.com/onsi/gomega" + "github.com/solo-io/gloo/pkg/utils/kubeutils" + "github.com/solo-io/gloo/pkg/utils/kubeutils/kubectl" + "github.com/solo-io/gloo/pkg/utils/requestutils/curl" + gatewaydefaults "github.com/solo-io/gloo/projects/gateway/pkg/defaults" + "github.com/solo-io/gloo/projects/gloo/pkg/defaults" + testmatchers "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" + ossvalidation "github.com/solo-io/gloo/test/kubernetes/e2e/features/validation" + "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/suite" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +var _ e2e.NewSuiteFunc = NewBasicEdgeRoutingSuite + +// edgeBasicRoutingSuite is the Suite of happy path tests for the basic routing cases for edge gateway resources (VirtualService, Upstream, etc.) +type edgeBasicRoutingSuite struct { + suite.Suite + + ctx context.Context + + // testInstallation contains all the metadata/utilities necessary to execute a series of tests + // against an installation of Gloo Gateway + testInstallation *e2e.TestInstallation +} + +func NewBasicEdgeRoutingSuite(ctx context.Context, testInst *e2e.TestInstallation) suite.TestingSuite { + return &edgeBasicRoutingSuite{ + ctx: ctx, + testInstallation: testInst, + } +} + +func (s *edgeBasicRoutingSuite) TestBasicVirtualServiceRouting() { + s.T().Cleanup(func() { + err := s.testInstallation.Actions.Kubectl().DeleteFile(s.ctx, testdefaults.NginxPodManifest) + s.Assertions.NoError(err, "can delete nginx pod") + + err = s.testInstallation.Actions.Kubectl().DeleteFile(s.ctx, testdefaults.CurlPodManifest) + s.Assertions.NoError(err, "can delete curl pod") + + err = s.testInstallation.Actions.Kubectl().DeleteFile(s.ctx, ossvalidation.ExampleVS, "-n", s.testInstallation.Metadata.InstallNamespace) + s.Assertions.NoError(err, "can delete virtual service") + + err = s.testInstallation.Actions.Kubectl().DeleteFile(s.ctx, ossvalidation.ExampleUpstream, "-n", s.testInstallation.Metadata.InstallNamespace) + s.Assertions.NoError(err, "can delete upstream") + }) + + err := s.testInstallation.Actions.Kubectl().ApplyFile(s.ctx, testdefaults.NginxPodManifest) + s.Assert().NoError(err) + // Check that test resources are running + s.testInstallation.Assertions.EventuallyPodsRunning(s.ctx, testdefaults.NginxPod.ObjectMeta.GetNamespace(), metav1.ListOptions{ + LabelSelector: "app.kubernetes.io/name=nginx", + }) + + err = s.testInstallation.Actions.Kubectl().ApplyFile(s.ctx, testdefaults.CurlPodManifest) + s.Assert().NoError(err) + // Check that test resources are running + s.testInstallation.Assertions.EventuallyPodsRunning(s.ctx, testdefaults.CurlPod.ObjectMeta.GetNamespace(), metav1.ListOptions{ + LabelSelector: "app.kubernetes.io/name=curl", + }) + + // Upstream is only rejected when the upstream plugin is run when a valid cluster is present + err = s.testInstallation.Actions.Kubectl().ApplyFile(s.ctx, ossvalidation.ExampleUpstream, "-n", s.testInstallation.Metadata.InstallNamespace) + s.Assert().NoError(err, "can apply valid upstream") + s.testInstallation.Assertions.EventuallyResourceStatusMatchesState( + func() (resources.InputResource, error) { + return s.testInstallation.ResourceClients.UpstreamClient().Read(s.testInstallation.Metadata.InstallNamespace, ossvalidation.ExampleUpstreamName, clients.ReadOpts{Ctx: s.ctx}) + }, + core.Status_Accepted, + defaults.GlooReporter, + ) + err = s.testInstallation.Actions.Kubectl().ApplyFile(s.ctx, ossvalidation.ExampleVS, "-n", s.testInstallation.Metadata.InstallNamespace) + s.Assert().NoError(err, "can apply valid virtual service") + s.testInstallation.Assertions.EventuallyResourceStatusMatchesState( + func() (resources.InputResource, error) { + return s.testInstallation.ResourceClients.VirtualServiceClient().Read(s.testInstallation.Metadata.InstallNamespace, ossvalidation.ExampleVsName, clients.ReadOpts{Ctx: s.ctx}) + }, + core.Status_Accepted, + defaults.GlooReporter, + ) + + // Should have a successful response + s.testInstallation.Assertions.AssertEventualCurlResponse( + s.ctx, + kubectl.PodExecOptions{ + Name: testdefaults.CurlPod.Name, + Namespace: testdefaults.CurlPod.Namespace, + Container: "curl", + }, + []curl.Option{ + curl.WithHost(kubeutils.ServiceFQDN(metav1.ObjectMeta{ + Name: gatewaydefaults.GatewayProxyName, + Namespace: s.testInstallation.Metadata.InstallNamespace, + })), + curl.WithHostHeader("example.com"), + curl.WithPort(80), + }, + &testmatchers.HttpResponse{ + StatusCode: http.StatusOK, + Body: gomega.ContainSubstring(testdefaults.NginxResponse), + }) + +} diff --git a/test/kubernetes/e2e/tests/edge_gw_tests.go b/test/kubernetes/e2e/tests/edge_gw_tests.go index 5d3faad46db..b1fc855924f 100644 --- a/test/kubernetes/e2e/tests/edge_gw_tests.go +++ b/test/kubernetes/e2e/tests/edge_gw_tests.go @@ -3,6 +3,7 @@ package tests import ( "github.com/solo-io/gloo/test/kubernetes/e2e" "github.com/solo-io/gloo/test/kubernetes/e2e/features/admin_server" + "github.com/solo-io/gloo/test/kubernetes/e2e/features/basicrouting" "github.com/solo-io/gloo/test/kubernetes/e2e/features/client_tls" "github.com/solo-io/gloo/test/kubernetes/e2e/features/headless_svc" "github.com/solo-io/gloo/test/kubernetes/e2e/features/port_routing" @@ -19,6 +20,7 @@ func EdgeGwSuiteRunner() e2e.SuiteRunner { edgeGwSuiteRunner.Register("ValidationAllowWarnings", validation_allow_warnings.NewTestingSuite) edgeGwSuiteRunner.Register("GlooAdminServer", admin_server.NewTestingSuite) edgeGwSuiteRunner.Register("ClientTls", client_tls.NewTestingSuite) + edgeGwSuiteRunner.Register("BasicRouting", basicrouting.NewBasicEdgeRoutingSuite) return edgeGwSuiteRunner }