Skip to content

Commit

Permalink
tests: Fix flaky tests and cleanup leftover resources in tests (solo-…
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjumani authored Oct 10, 2024
1 parent 4fcf50f commit d92d3d2
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 9 deletions.
17 changes: 11 additions & 6 deletions .github/workflows/pr-kubernetes-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,30 @@ jobs:
go-test-args: '-v -timeout=25m'
go-test-run-regex: '^TestK8sGateway$$/^RouteDelegation$$|^TestK8sGateway$$/^Services$$|^TestGlooctlGlooGatewayEdgeGateway$$|^TestGlooctlK8sGateway$$'

# Oct 3, 2024: 25 minutes
# Oct 10, 2024: 24 minutes
- cluster-name: 'cluster-two'
go-test-args: '-v -timeout=25m'
go-test-run-regex: '^TestDiscoveryWatchlabels$$|^TestK8sGatewayIstioRevision$$|^TestRevisionIstioRegression$$|^TestK8sGateway$$/^Deployer$$|^TestK8sGateway$$/^RouteOptions$$|^TestK8sGateway$$/^VirtualHostOptions$$|^TestK8sGateway$$/^Upstreams$$|^TestK8sGateway$$/^HeadlessSvc$$|^TestK8sGateway$$/^PortRouting$$|^TestK8sGatewayMinimalDefaultGatewayParameters$$|^TestK8sGateway$$/^DirectResponse$$|^TestK8sGateway$$/^HttpListenerOptions$$|^TestK8sGateway$$/^ListenerOptions$$|^TestK8sGateway$$/^GlooAdminServer$$'
go-test-run-regex: '^TestK8sGatewayIstioRevision$$|^TestRevisionIstioRegression$$|^TestK8sGateway$$/^Deployer$$|^TestK8sGateway$$/^RouteOptions$$|^TestK8sGateway$$/^VirtualHostOptions$$|^TestK8sGateway$$/^Upstreams$$|^TestK8sGateway$$/^HeadlessSvc$$|^TestK8sGateway$$/^PortRouting$$|^TestK8sGatewayMinimalDefaultGatewayParameters$$|^TestK8sGateway$$/^DirectResponse$$|^TestK8sGateway$$/^HttpListenerOptions$$|^TestK8sGateway$$/^ListenerOptions$$|^TestK8sGateway$$/^GlooAdminServer$$'

# Oct 3, 2024: 25 minutes
- cluster-name: 'cluster-three'
go-test-args: '-v -timeout=30m'
go-test-run-regex: '(^TestK8sGatewayIstioAutoMtls$$|^TestAutomtlsIstioEdgeApisGateway$$|^TestIstioEdgeApiGateway$$|^TestIstioRegression$$)'

# Oct 3, 2024: 24 minutes
# Oct 10, 2024: 20 minutes
- cluster-name: 'cluster-four'
go-test-args: '-v -timeout=30m'
go-test-run-regex: '(^TestK8sGatewayIstio$$|^TestGlooGatewayEdgeGateway$$|^TestGlooctlIstioInjectEdgeApiGateway$$|^TestK8sGatewayNoValidation$$)'
go-test-run-regex: '(^TestK8sGatewayIstio$$|^TestGlooGatewayEdgeGateway$$|^TestGlooctlIstioInjectEdgeApiGateway$$)'

# October 1, 2024: 27 minutes
# October 10, 2024: 22 minutes
- cluster-name: 'cluster-five'
go-test-args: '-v -timeout=25m'
go-test-run-regex: '^TestFullEnvoyValidation$$|^TestValidationStrict$$|^TestValidationAlwaysAccept$$|^TestTransformationValidationDisabled$$|^TestGloomtlsGatewayEdgeGateway$$|^TestHelm$$|^TestHelmSettings$$|^TestWatchNamespaceSelector$$'
go-test-run-regex: '^TestFullEnvoyValidation$$|^TestValidationStrict$$|^TestValidationAlwaysAccept$$|^TestTransformationValidationDisabled$$|^TestGloomtlsGatewayEdgeGateway$$|^TestWatchNamespaceSelector$$'

# October 10, 2024: 12 minutes
- cluster-name: 'cluster-six'
go-test-args: '-v -timeout=25m'
go-test-run-regex: '^TestDiscoveryWatchlabels$$|^TestK8sGatewayNoValidation$$|^TestHelm$$|^TestHelmSettings$$'

# In our PR tests, we run the suite of tests using the upper ends of versions that we claim to support
# The versions should mirror: https://docs.solo.io/gloo-edge/latest/reference/support/
Expand Down
4 changes: 4 additions & 0 deletions changelog/v1.18.0-beta26/cleanup-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changelog:
- type: NON_USER_FACING
description: Cleanup leftover resources in tests.

Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import (

gloo_defaults "github.com/solo-io/gloo/projects/gloo/pkg/defaults"
"github.com/solo-io/gloo/test/kubernetes/e2e"
testdefaults "github.com/solo-io/gloo/test/kubernetes/e2e/defaults"
"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 = NewTestingSuite
Expand All @@ -34,7 +36,23 @@ func NewTestingSuite(ctx context.Context, testInst *e2e.TestInstallation) suite.

// TestRejectInvalidTransformation checks webhook rejects invalid transformation when fullEnvoyValidation=true
func (s *testingSuite) TestRejectInvalidTransformation() {
err := s.testInstallation.Actions.Kubectl().ApplyFile(s.ctx, validation.ExampleUpstream, "-n", s.testInstallation.Metadata.InstallNamespace)

s.T().Cleanup(func() {
err := s.testInstallation.Actions.Kubectl().DeleteFileSafe(s.ctx, validation.ExampleUpstream, "-n", s.testInstallation.Metadata.InstallNamespace)
s.Assertions.NoError(err, "can delete upstream")

err = s.testInstallation.Actions.Kubectl().DeleteFileSafe(s.ctx, testdefaults.NginxPodManifest)
s.Assertions.NoError(err, "can delete nginx pod")
})

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, validation.ExampleUpstream, "-n", s.testInstallation.Metadata.InstallNamespace)
s.Assert().NoError(err)
s.testInstallation.Assertions.EventuallyResourceStatusMatchesState(
func() (resources.InputResource, error) {
Expand All @@ -43,6 +61,11 @@ func (s *testingSuite) TestRejectInvalidTransformation() {
core.Status_Accepted,
gloo_defaults.GlooReporter,
)

s.T().Cleanup(func() {
err := s.testInstallation.Actions.Kubectl().DeleteFileSafe(s.ctx, validation.VSTransformationHeaderText, "-n", s.testInstallation.Metadata.InstallNamespace)
s.Assert().NoError(err)
})
// rejects invalid inja template in transformation
output, err := s.testInstallation.Actions.Kubectl().ApplyFileWithOutput(s.ctx, validation.VSTransformationHeaderText, "-n", s.testInstallation.Metadata.InstallNamespace)
s.Assert().Error(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ func NewTestingSuite(ctx context.Context, testInst *e2e.TestInstallation) suite.

// TestDoesNotReject checks webhook does not reject invalid transformation when disable_transformation_validation=false
func (s *testingSuite) TestDoesNotReject() {
s.T().Cleanup(func() {
err := s.testInstallation.Actions.Kubectl().DeleteFileSafe(s.ctx, validation.VSTransformationSingleReplace, "-n", s.testInstallation.Metadata.InstallNamespace)
s.Assertions.NoError(err)

err = s.testInstallation.Actions.Kubectl().DeleteFileSafe(s.ctx, validation.VSTransformationHeaderText, "-n", s.testInstallation.Metadata.InstallNamespace)
s.Assertions.NoError(err)

err = s.testInstallation.Actions.Kubectl().DeleteFileSafe(s.ctx, validation.VSTransformationExtractors, "-n", s.testInstallation.Metadata.InstallNamespace)
s.Assertions.NoError(err)
})

// accepts invalid inja template in transformation
err := s.testInstallation.Actions.Kubectl().ApplyFile(s.ctx, validation.VSTransformationExtractors, "-n", s.testInstallation.Metadata.InstallNamespace)
s.Assert().NoError(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (s *testingSuite) TestMissingUpstream() {
err = s.testInstallation.Actions.Kubectl().DeleteFileSafe(s.ctx, validation.ExampleVS, "-n", s.testInstallation.Metadata.InstallNamespace)
s.Assert().NoError(err, "can delete "+validation.ExampleVS)

err = s.testInstallation.Actions.Kubectl().ApplyFile(s.ctx, testdefaults.NginxPodManifest)
err = s.testInstallation.Actions.Kubectl().DeleteFileSafe(s.ctx, testdefaults.NginxPodManifest)
s.Assert().NoError(err)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ func NewTestingSuite(ctx context.Context, testInst *e2e.TestInstallation) suite.
}

func (s *testingSuite) TestRejectsInvalidVSMethodMatcher() {
s.T().Cleanup(func() {
err := s.testInstallation.Actions.Kubectl().DeleteFileSafe(s.ctx, validation.InvalidVirtualServiceMatcher, "-n", s.testInstallation.Metadata.InstallNamespace)
s.Assert().NoError(err)
})

err := s.testInstallation.Actions.Kubectl().ApplyFile(s.ctx, validation.InvalidVirtualServiceMatcher, "-n", s.testInstallation.Metadata.InstallNamespace)
s.Assert().NoError(err)
s.testInstallation.Assertions.EventuallyResourceStatusMatchesState(
Expand All @@ -64,6 +69,12 @@ func (s *testingSuite) TestAcceptInvalidRatelimitConfigResources() {
if s.testInstallation.Metadata.IsEnterprise {
s.T().Skip("RateLimitConfig is enterprise-only, skipping test when running enterprise helm chart")
}

s.T().Cleanup(func() {
err := s.testInstallation.Actions.Kubectl().DeleteFileSafe(s.ctx, validation.InvalidRLC, "-n", s.testInstallation.Metadata.InstallNamespace)
s.Assert().NoError(err)
})

err := s.testInstallation.Actions.Kubectl().ApplyFile(s.ctx, validation.InvalidRLC, "-n", s.testInstallation.Metadata.InstallNamespace)
s.Assert().NoError(err)
// We don't expect an error exit code here because alwaysAccept=true
Expand All @@ -80,6 +91,11 @@ func (s *testingSuite) TestAcceptInvalidRatelimitConfigResources() {
}

func (s *testingSuite) TestAcceptsInvalidGatewayResources() {
s.T().Cleanup(func() {
err := s.testInstallation.Actions.Kubectl().DeleteFileSafe(s.ctx, validation.InvalidGateway, "-n", s.testInstallation.Metadata.InstallNamespace)
s.Assert().NoError(err)
})

err := s.testInstallation.Actions.Kubectl().ApplyFile(s.ctx, validation.InvalidGateway, "-n", s.testInstallation.Metadata.InstallNamespace)
s.Assert().NoError(err)

Expand Down Expand Up @@ -202,6 +218,9 @@ func (s *testingSuite) TestPersistInvalidVirtualService() {
err = s.testInstallation.Actions.Kubectl().DeleteFile(s.ctx, validation.ValidVS, "-n", s.testInstallation.Metadata.InstallNamespace)
s.NoError(err, "can delete "+validation.ValidVS)

err = s.testInstallation.Actions.Kubectl().DeleteFileSafe(s.ctx, validation.InvalidVS, "-n", s.testInstallation.Metadata.InstallNamespace)
s.Assert().NoError(err, "can delete "+validation.InvalidVS)

err = s.testInstallation.Actions.Kubectl().DeleteFile(s.ctx, testdefaults.NginxPodManifest)
s.Assert().NoError(err)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ func (s *testingSuite) TestVirtualServiceWithSecretDeletion() {

// TestRejectsInvalidGatewayResources tests behaviors when Gloo rejects invalid Edge Gateway resources
func (s *testingSuite) TestRejectsInvalidGatewayResources() {
s.T().Cleanup(func() {
// Can delete resources in correct order
err := s.testInstallation.Actions.Kubectl().DeleteFileSafe(s.ctx, validation.InvalidGateway, "-n", s.testInstallation.Metadata.InstallNamespace)
s.Assert().NoError(err)
})

output, err := s.testInstallation.Actions.Kubectl().ApplyFileWithOutput(s.ctx, validation.InvalidGateway, "-n", s.testInstallation.Metadata.InstallNamespace)
s.Assert().Error(err)
s.Assert().Contains(output, fmt.Sprintf(`admission webhook "gloo.%s.svc" denied the request`, s.testInstallation.Metadata.InstallNamespace))
Expand All @@ -140,6 +146,11 @@ func (s *testingSuite) TestRejectsInvalidRatelimitConfigResources() {
if s.testInstallation.Metadata.IsEnterprise {
s.T().Skip("RateLimitConfig is enterprise-only, skipping test when running enterprise helm chart")
}

s.T().Cleanup(func() {
err := s.testInstallation.Actions.Kubectl().DeleteFileSafe(s.ctx, validation.InvalidRLC, "-n", s.testInstallation.Metadata.InstallNamespace)
s.Assert().NoError(err)
})
output, _ := s.testInstallation.Actions.Kubectl().ApplyFileWithOutput(s.ctx, validation.InvalidRLC, "-n", s.testInstallation.Metadata.InstallNamespace)
// We don't expect an error exit code here because this is a warning
s.Assert().Contains(output, fmt.Sprintf(`admission webhook "gloo.%s.svc" denied the request`, s.testInstallation.Metadata.InstallNamespace))
Expand All @@ -149,6 +160,11 @@ func (s *testingSuite) TestRejectsInvalidRatelimitConfigResources() {

// TestRejectsInvalidVSMethodMatcher tests behaviors when Gloo rejects invalid VirtualService resources due to incorrect matchers
func (s *testingSuite) TestRejectsInvalidVSMethodMatcher() {
s.T().Cleanup(func() {
err := s.testInstallation.Actions.Kubectl().DeleteFileSafe(s.ctx, validation.InvalidVirtualServiceMatcher, "-n", s.testInstallation.Metadata.InstallNamespace)
s.Assert().NoError(err)
})

output, err := s.testInstallation.Actions.Kubectl().ApplyFileWithOutput(s.ctx, validation.InvalidVirtualServiceMatcher, "-n", s.testInstallation.Metadata.InstallNamespace)
s.Assert().Error(err)
s.Assert().Contains(output, fmt.Sprintf(`admission webhook "gloo.%s.svc" denied the request`, s.testInstallation.Metadata.InstallNamespace))
Expand All @@ -158,6 +174,11 @@ func (s *testingSuite) TestRejectsInvalidVSMethodMatcher() {

// TestRejectsInvalidVSTypo tests behaviors when Gloo rejects invalid VirtualService resources due to typos
func (s *testingSuite) TestRejectsInvalidVSTypo() {
s.T().Cleanup(func() {
err := s.testInstallation.Actions.Kubectl().DeleteFileSafe(s.ctx, validation.InvalidVirtualServiceTypo, "-n", s.testInstallation.Metadata.InstallNamespace)
s.Assert().NoError(err)
})

output, err := s.testInstallation.Actions.Kubectl().ApplyFileWithOutput(s.ctx, validation.InvalidVirtualServiceTypo, "-n", s.testInstallation.Metadata.InstallNamespace)
s.Assert().Error(err)
println(output)
Expand All @@ -177,6 +198,17 @@ func (s *testingSuite) TestRejectsInvalidVSTypo() {

// TestRejectTransformation checks webhook rejects invalid transformation when disableTransformationValidation=false
func (s *testingSuite) TestRejectTransformation() {
s.T().Cleanup(func() {
err := s.testInstallation.Actions.Kubectl().DeleteFileSafe(s.ctx, validation.VSTransformationSingleReplace, "-n", s.testInstallation.Metadata.InstallNamespace)
s.Assert().NoError(err)

err = s.testInstallation.Actions.Kubectl().DeleteFileSafe(s.ctx, validation.VSTransformationExtractors, "-n", s.testInstallation.Metadata.InstallNamespace)
s.Assert().NoError(err)

err = s.testInstallation.Actions.Kubectl().DeleteFileSafe(s.ctx, validation.VSTransformationHeaderText, "-n", s.testInstallation.Metadata.InstallNamespace)
s.Assert().NoError(err)
})

// reject invalid inja template in transformation
// This is only rejected when allowWarnings=false
output, err := s.testInstallation.Actions.Kubectl().ApplyFileWithOutput(s.ctx, validation.VSTransformationHeaderText, "-n", s.testInstallation.Metadata.InstallNamespace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ func (s *testingSuite) TestVirtualServiceWithSecretDeletion() {
// TestInvalidUpstreamMissingPort tests behaviors when Gloo rejects an invalid upstream with a missing port
func (s *testingSuite) TestInvalidUpstreamMissingPort() {
s.T().Cleanup(func() {
err := s.testInstallation.Actions.Kubectl().DeleteFileSafe(s.ctx, validation.ExampleVS, "-n", s.testInstallation.Metadata.InstallNamespace)
err := s.testInstallation.Actions.Kubectl().DeleteFileSafe(s.ctx, validation.InvalidUpstreamNoPort, "-n", s.testInstallation.Metadata.InstallNamespace)
s.NoError(err)

err = s.testInstallation.Actions.Kubectl().DeleteFileSafe(s.ctx, validation.ExampleVS, "-n", s.testInstallation.Metadata.InstallNamespace)
s.Assert().NoError(err, "can delete "+validation.ExampleVS)

// Delete can fail with strict validation if VS is not deleted first from snapshot, so try multiple times so that snapshot has time to update
Expand Down Expand Up @@ -176,6 +179,11 @@ func (s *testingSuite) TestInvalidUpstreamMissingPort() {

// TestRejectsInvalidVSMissingUpstream tests behaviors when Gloo rejects invalid VirtualService resources due to missing upstream
func (s *testingSuite) TestRejectsInvalidVSMissingUpstream() {
s.T().Cleanup(func() {
err := s.testInstallation.Actions.Kubectl().DeleteFileSafe(s.ctx, validation.InvalidVirtualMissingUpstream, "-n", s.testInstallation.Metadata.InstallNamespace)
s.NoError(err)
})

output, err := s.testInstallation.Actions.Kubectl().ApplyFileWithOutput(s.ctx, validation.InvalidVirtualMissingUpstream, "-n", s.testInstallation.Metadata.InstallNamespace)
s.Assert().Error(err)
s.Assert().Contains(output, fmt.Sprintf(`admission webhook "gloo.%s.svc" denied the request`, s.testInstallation.Metadata.InstallNamespace))
Expand Down

0 comments on commit d92d3d2

Please sign in to comment.