Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure namespace override consistency #9888

Merged
merged 12 commits into from
Aug 14, 2024
16 changes: 9 additions & 7 deletions .github/workflows/nightly-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
name: End-to-End (branch=${{ github.ref_name }}, cluster=${{ matrix.test.cluster-name }}, version=${{ matrix.version-files.label }} )
if: ${{ github.event_name == 'workflow_dispatch' && inputs.run-kubernetes-end-to-end && inputs.branch == 'workflow_initiating_branch' }}
runs-on: ubuntu-22.04
timeout-minutes: 90
timeout-minutes: 150
strategy:
# Since we are running these on a schedule, there is no value in failing fast
# In fact, we want to ensure that all tests run, so that we have a clearer picture of which tests are prone to flaking
Expand All @@ -66,7 +66,7 @@ jobs:
# When running the tests at night, there is no value in splitting the tests across multiple clusters and running them in parallel.
# As a result, we increase the threshold for the tests, since they all run serially on a single cluster
- cluster-name: 'cluster-one'
go-test-args: '-v -timeout=90m'
go-test-args: '-v -timeout=120m'
go-test-run-regex: ${{ inputs.kubernetes-end-to-end-run-regex }}
# In our nightly tests, we run the suite of tests using the lower and upper ends of versions that we claim to support
# The versions should mirror: https://docs.solo.io/gloo-edge/latest/reference/support/
Expand Down Expand Up @@ -116,7 +116,7 @@ jobs:
name: End-to-End (branch=main, cluster=${{ matrix.test.cluster-name }}, version=${{ matrix.version-files.label }} )
if: ${{ (github.event_name == 'workflow_dispatch' && inputs.run-kubernetes-end-to-end && inputs.branch == 'main') || github.event.schedule == '0 5 * * *' }}
runs-on: ubuntu-22.04
timeout-minutes: 90
timeout-minutes: 150
strategy:
# Since we are running these on a schedule, there is no value in failing fast
# In fact, we want to ensure that all tests run, so that we have a clearer picture of which tests are prone to flaking
Expand All @@ -126,7 +126,8 @@ jobs:
# When running the tests at night, there is no value in splitting the tests across multiple clusters and running them in parallel.
# As a result, we increase the threshold for the tests, since they all run serially on a single cluster
- cluster-name: 'cluster-one'
go-test-args: '-v -timeout=90m'
go-test-args: '-v -timeout=120m'
# Specifying an empty regex means all tests will be run.
go-test-run-regex: ""
# In our nightly tests, we run the suite of tests using the lower and upper ends of versions that we claim to support
# The versions should mirror: https://docs.solo.io/gloo-edge/latest/reference/support/
Expand Down Expand Up @@ -175,7 +176,7 @@ jobs:
name: End-to-End (branch=v1.17.x, cluster=${{ matrix.test.cluster-name }}, version=${{ matrix.version-files.label }} )
if: ${{ (github.event_name == 'workflow_dispatch' && inputs.run-kubernetes-end-to-end && inputs.branch == 'v1.17.x') || github.event.schedule == '0 6 * * 1' }}
runs-on: ubuntu-22.04
timeout-minutes: 90
timeout-minutes: 150
strategy:
# Since we are running these on a schedule, there is no value in failing fast
# In fact, we want to ensure that all tests run, so that we have a clearer picture of which tests are prone to flaking
Expand All @@ -185,7 +186,8 @@ jobs:
# When running the tests at night, there is no value in splitting the tests across multiple clusters and running them in parallel.
# As a result, we increase the threshold for the tests, since they all run serially on a single cluster
- cluster-name: 'cluster-one'
go-test-args: '-v -timeout=90m'
go-test-args: '-v -timeout=120m'
# Specifying an empty regex means all tests will be run.
go-test-run-regex: ""
# In our nightly tests, we run the suite of tests using the lower and upper ends of versions that we claim to support
# The versions should mirror: https://docs.solo.io/gloo-edge/latest/reference/support/
Expand Down Expand Up @@ -488,4 +490,4 @@ jobs:
PREAMBLE: ${{ steps.compute-preamble.outputs.preamble }} # text to hyperlink at start of slack message
SLACKBOT_BEARER: ${{ secrets.SLACKBOT_BEARER }}
run: |
go run .github/workflows/helpers/notify/slack.go '${{ toJSON(needs) }}'
go run .github/workflows/helpers/notify/slack.go '${{ toJSON(needs) }}'
4 changes: 2 additions & 2 deletions .github/workflows/pr-unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ jobs:
- name: Run Tests
shell: bash
env:
TEST_PKG: ./projects/gateway2/...
TEST_PKG: "./projects/gateway2/... ./test/kubernetes/testutils/helper"
jbohanon marked this conversation as resolved.
Show resolved Hide resolved
run: make go-test-with-coverage
- name: Validate Test Coverage
shell: bash
# The make will error if test coverage drops below a certain threshold
# We intentionally ignore the errors while we build out our test coverage, to establish a good baseline
# However, we should strive to establish a baseline, and then make it required on PRs
run: make --always-make --ignore-errors validate-test-coverage
run: make --always-make --ignore-errors validate-test-coverage
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ test-with-coverage: test
go tool cover -html $(OUTPUT_DIR)/coverage.cov

.PHONY: run-tests
run-tests: GINKGO_FLAGS += -skip-package=e2e,gateway2 ## Run all non E2E tests, or only run the test package at {TEST_PKG} if it is specified
run-tests: GINKGO_FLAGS += -skip-package=e2e,gateway2,test/kubernetes/testutils/helper ## Run all non E2E tests, or only run the test package at {TEST_PKG} if it is specified
run-tests: GINKGO_FLAGS += --label-filter="!end-to-end && !performance"
run-tests: test

Expand Down
6 changes: 6 additions & 0 deletions changelog/v1.18.0-beta15/test-summaries.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
changelog:
- type: NON_USER_FACING
description: >-
Update all tests to use INSTALL_NAMESPACE defined by the TestInstallation setup.
Move test utils unit tests to GHA because it requires an authorized token.
Update nightlies timeout.
12 changes: 0 additions & 12 deletions pkg/utils/env/env.go

This file was deleted.

20 changes: 20 additions & 0 deletions pkg/utils/envutils/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,23 @@ func IsTruthyValue(value string) bool {
envValue, _ := strconv.ParseBool(value)
return envValue
}

// GetOrDefault returns the value of the environment variable for the given key,
// or the default value if the environment variable is not set.
func GetOrDefault(key, fallback string) string {
if value, ok := os.LookupEnv(key); ok {
return value
}
return fallback
}

// LookupOrDefault returns the value of the environment variable for the given key,
// or the default value if the environment variable is not set. Also returns whether
// the value existed.
func LookupOrDefault(key, fallback string) (string, bool) {
if value, ok := os.LookupEnv(key); ok {
return value, ok
} else {
return fallback, ok
}
}
14 changes: 13 additions & 1 deletion test/kubernetes/e2e/example/debug_logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ package example

import (
"context"
"os"
"path/filepath"
"testing"
"time"

"github.com/solo-io/gloo/pkg/utils/envutils"
"github.com/solo-io/gloo/test/kubernetes/testutils/helper"
"github.com/solo-io/gloo/test/testutils"

"github.com/solo-io/skv2/codegen/util"
"github.com/stretchr/testify/suite"
Expand All @@ -21,19 +24,28 @@ import (
// TestInstallationWithDebugLogLevel is the function which executes a series of tests against a given installation
func TestInstallationWithDebugLogLevel(t *testing.T) {
ctx := context.Background()
installNs, overrodeNs := envutils.LookupOrDefault(testutils.InstallNamespace, "automtls-istio-edge-api-test")
testInstallation := e2e.CreateTestInstallation(
t,
&gloogateway.Context{
InstallNamespace: "debug-example",
InstallNamespace: installNs,
ValuesManifestFile: filepath.Join(util.MustGetThisDir(), "manifests", "debug-example.yaml"),
},
)

testHelper := e2e.MustTestHelper(ctx, testInstallation)

// Set the env to the install namespace if it is not already set
if os.Getenv(testutils.InstallNamespace) == "" {
os.Setenv(testutils.InstallNamespace, installNs)
}

// We register the cleanup function _before_ we actually perform the installation.
// This allows us to uninstall Gloo Gateway, in case the original installation only completed partially
t.Cleanup(func() {
if overrodeNs {
os.Unsetenv(testutils.InstallNamespace)
}
if t.Failed() {
testInstallation.PreFailHandler(ctx)
}
Expand Down
14 changes: 13 additions & 1 deletion test/kubernetes/e2e/tests/automtls_istio_edge_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package tests_test

import (
"context"
"os"
"path/filepath"
"testing"
"time"

"github.com/solo-io/gloo/pkg/utils/envutils"
"github.com/solo-io/gloo/test/kubernetes/testutils/helper"
"github.com/solo-io/gloo/test/testutils"

"github.com/solo-io/skv2/codegen/util"

Expand All @@ -19,10 +22,11 @@ import (
// the k8s Gateway controller is disabled
func TestAutomtlsIstioEdgeApisGateway(t *testing.T) {
ctx := context.Background()
installNs, overrodeNs := envutils.LookupOrDefault(testutils.InstallNamespace, "automtls-istio-edge-api-test")
testInstallation := e2e.CreateTestInstallation(
t,
&gloogateway.Context{
InstallNamespace: "automtls-istio-edge-api-test",
InstallNamespace: installNs,
ValuesManifestFile: filepath.Join(util.MustGetThisDir(), "manifests", "istio-automtls-edge-gateway-test-helm.yaml"),
},
)
Expand All @@ -33,9 +37,17 @@ func TestAutomtlsIstioEdgeApisGateway(t *testing.T) {
t.Fatalf("failed to get istioctl: %v", err)
}

// Set the env to the install namespace if it is not already set
if os.Getenv(testutils.InstallNamespace) == "" {
os.Setenv(testutils.InstallNamespace, installNs)
}

// We register the cleanup function _before_ we actually perform the installation.
// This allows us to uninstall Gloo Gateway, in case the original installation only completed partially
t.Cleanup(func() {
if overrodeNs {
os.Unsetenv(testutils.InstallNamespace)
}
if t.Failed() {
testInstallation.PreFailHandler(ctx)

Expand Down
14 changes: 13 additions & 1 deletion test/kubernetes/e2e/tests/automtls_istio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,28 @@ package tests_test

import (
"context"
"os"
"path/filepath"
"testing"
"time"

"github.com/solo-io/gloo/pkg/utils/envutils"
"github.com/solo-io/gloo/test/kubernetes/e2e"
. "github.com/solo-io/gloo/test/kubernetes/e2e/tests"
"github.com/solo-io/gloo/test/kubernetes/testutils/gloogateway"
"github.com/solo-io/gloo/test/kubernetes/testutils/helper"
"github.com/solo-io/gloo/test/testutils"
"github.com/solo-io/skv2/codegen/util"
)

// TestK8sGatewayIstioAutoMtls is the function which executes a series of tests against a given installation
func TestK8sGatewayIstioAutoMtls(t *testing.T) {
ctx := context.Background()
installNs, overrodeNs := envutils.LookupOrDefault(testutils.InstallNamespace, "automtls-istio-k8s-gw-test")
testInstallation := e2e.CreateTestInstallation(
t,
&gloogateway.Context{
InstallNamespace: "automtls-istio-k8s-gw-test",
InstallNamespace: installNs,
ValuesManifestFile: filepath.Join(util.MustGetThisDir(), "manifests", "istio-automtls-k8s-gateway-test-helm.yaml"),
},
)
Expand All @@ -30,9 +34,17 @@ func TestK8sGatewayIstioAutoMtls(t *testing.T) {
t.Errorf("failed to add istioctl: %v\n", err)
}

// Set the env to the install namespace if it is not already set
if os.Getenv(testutils.InstallNamespace) == "" {
os.Setenv(testutils.InstallNamespace, installNs)
}

// We register the cleanup function _before_ we actually perform the installation.
// This allows us to uninstall Gloo Gateway, in case the original installation only completed partially
t.Cleanup(func() {
if overrodeNs {
os.Unsetenv(testutils.InstallNamespace)
}
if t.Failed() {
testInstallation.PreFailHandler(ctx)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,46 @@ package tests_test

import (
"context"
"os"
"path/filepath"
"testing"
"time"

"github.com/solo-io/gloo/pkg/utils/envutils"
"github.com/solo-io/gloo/test/kubernetes/e2e"
. "github.com/solo-io/gloo/test/kubernetes/e2e/tests"
"github.com/solo-io/gloo/test/kubernetes/testutils/gloogateway"
"github.com/solo-io/gloo/test/kubernetes/testutils/helper"
"github.com/solo-io/gloo/test/testutils"
"github.com/solo-io/skv2/codegen/util"
)

// TestTransformationValidationDisabled is the function which executes a series of tests against a given
// installation where validation has disableTransformationValidation=true
func TestTransformationValidationDisabled(t *testing.T) {
ctx := context.Background()
installNs, overrodeNs := envutils.LookupOrDefault(testutils.InstallNamespace, "disable-transformation-validation-test")
jbohanon marked this conversation as resolved.
Show resolved Hide resolved
testInstallation := e2e.CreateTestInstallation(
t,
&gloogateway.Context{
InstallNamespace: "disable-transformation-validation-test",
InstallNamespace: installNs,
ValuesManifestFile: filepath.Join(util.MustGetThisDir(), "manifests", "disable-transformation-validation-helm.yaml"),
},
)

testHelper := e2e.MustTestHelper(ctx, testInstallation)

// Set the env to the install namespace if it is not already set
if os.Getenv(testutils.InstallNamespace) == "" {
os.Setenv(testutils.InstallNamespace, installNs)
}

// We register the cleanup function _before_ we actually perform the installation.
// This allows us to uninstall Gloo Gateway, in case the original installation only completed partially
t.Cleanup(func() {
if overrodeNs {
os.Unsetenv(testutils.InstallNamespace)
}
if t.Failed() {
testInstallation.PreFailHandler(ctx)
}
Expand Down
7 changes: 5 additions & 2 deletions test/kubernetes/e2e/tests/edge_gw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"
"time"

"github.com/solo-io/gloo/pkg/utils/env"
"github.com/solo-io/gloo/pkg/utils/envutils"
"github.com/solo-io/gloo/test/kubernetes/e2e"
. "github.com/solo-io/gloo/test/kubernetes/e2e/tests"
"github.com/solo-io/gloo/test/kubernetes/testutils/gloogateway"
Expand All @@ -20,7 +20,7 @@ import (
// the k8s Gateway controller is disabled
func TestGlooGatewayEdgeGateway(t *testing.T) {
ctx := context.Background()
installNs := env.GetOrDefault(testutils.InstallNamespace, "gloo-gateway-edge-test")
installNs, overrodeNs := envutils.LookupOrDefault(testutils.InstallNamespace, "gloo-gateway-edge-test")
testInstallation := e2e.CreateTestInstallation(
t,
&gloogateway.Context{
Expand All @@ -38,6 +38,9 @@ func TestGlooGatewayEdgeGateway(t *testing.T) {
// We register the cleanup function _before_ we actually perform the installation.
// This allows us to uninstall Gloo Gateway, in case the original installation only completed partially
t.Cleanup(func() {
if overrodeNs {
os.Unsetenv(testutils.InstallNamespace)
}
if t.Failed() {
testInstallation.PreFailHandler(ctx)
}
Expand Down
14 changes: 13 additions & 1 deletion test/kubernetes/e2e/tests/glooctl_edge_gw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,46 @@ package tests_test

import (
"context"
"os"
"path/filepath"
"testing"
"time"

"github.com/solo-io/gloo/pkg/utils/envutils"
"github.com/solo-io/gloo/test/kubernetes/e2e"
. "github.com/solo-io/gloo/test/kubernetes/e2e/tests"
"github.com/solo-io/gloo/test/kubernetes/testutils/gloogateway"
"github.com/solo-io/gloo/test/kubernetes/testutils/helper"
"github.com/solo-io/gloo/test/testutils"
"github.com/solo-io/skv2/codegen/util"
)

// TestGlooctlGlooGatewayEdgeGateway is the function which executes a series of glooctl tests against a given
// installation where the k8s Gateway controller is disabled.
func TestGlooctlGlooGatewayEdgeGateway(t *testing.T) {
ctx := context.Background()
installNs, overrodeNs := envutils.LookupOrDefault(testutils.InstallNamespace, "glooctl-gloo-gateway-edge-test")
testInstallation := e2e.CreateTestInstallation(
t,
&gloogateway.Context{
InstallNamespace: "glooctl-gloo-gateway-edge-test",
InstallNamespace: installNs,
ValuesManifestFile: filepath.Join(util.MustGetThisDir(), "manifests", "glooctl-edge-gateway-test-helm.yaml"),
},
)

testHelper := e2e.MustTestHelper(ctx, testInstallation)

// Set the env to the install namespace if it is not already set
if os.Getenv(testutils.InstallNamespace) == "" {
os.Setenv(testutils.InstallNamespace, installNs)
}

// We register the cleanup function _before_ we actually perform the installation.
// This allows us to uninstall Gloo Gateway, in case the original installation only completed partially
t.Cleanup(func() {
if overrodeNs {
os.Unsetenv(testutils.InstallNamespace)
}
if t.Failed() {
testInstallation.PreFailHandler(ctx)
}
Expand Down
Loading
Loading