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

ci: allow disabling addons in tests #334

Merged
merged 3 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ jobs:
- name: run integration tests
run: make test.integration
env:
KONG_TEST_DISABLE_CERTMANAGER: "true"
WEBHOOK_ENABLED: ${{ matrix.webhook-enabled }}
KONG_CONTROLLER_OUT: stdout
GOTESTSUM_JUNITFILE: integration-tests-webhook-enabled-${{ matrix.webhook-enabled }}.xml
Expand Down Expand Up @@ -302,6 +303,7 @@ jobs:
- name: run integration tests
run: make test.integration_bluegreen
env:
KONG_TEST_DISABLE_CERTMANAGER: "true"
WEBHOOK_ENABLED: ${{ matrix.webhook-enabled }}
KONG_CONTROLLER_OUT: stdout
GOTESTSUM_JUNITFILE: integration-tests-bluegreen-webhook-enabled-${{ matrix.webhook-enabled }}.xml
Expand Down Expand Up @@ -338,8 +340,6 @@ jobs:
steps:
- name: checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: setup golang
uses: actions/setup-go@v5
Expand All @@ -353,6 +353,7 @@ jobs:
- name: run integration tests
run: make test.integration_provision_dataplane_fail
env:
KONG_TEST_DISABLE_CERTMANAGER: "true"
KONG_CONTROLLER_OUT: stdout
GOTESTSUM_JUNITFILE: integration-tests-provision-dataplane-fail.xml
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -404,6 +405,7 @@ jobs:
- name: run e2e tests
run: make test.e2e
env:
KONG_TEST_DISABLE_CERTMANAGER: "true"
KONG_TEST_GATEWAY_OPERATOR_IMAGE_LOAD: gateway-operator:e2e-${{ github.sha }}
GOTESTSUM_JUNITFILE: "e2e-tests.xml"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
5 changes: 4 additions & 1 deletion test/conformance/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/kong/gateway-operator/modules/manager"
"github.com/kong/gateway-operator/modules/manager/scheme"
testutils "github.com/kong/gateway-operator/pkg/utils/test"
"github.com/kong/gateway-operator/test"
)

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -80,7 +81,9 @@ func TestMain(m *testing.M) {
// that would allow e.g. cross namespace traffic.
// Related upstream discussion: https://github.com/kubernetes-sigs/gateway-api/discussions/2137
env, err = testutils.BuildEnvironment(ctx, existingCluster, func(b *environments.Builder, t clusters.Type) {
b.WithAddons(metallb.New())
if !test.IsMetalLBDisabled() {
b.WithAddons(metallb.New())
}
})
exitOnErr(err)

Expand Down
23 changes: 17 additions & 6 deletions test/e2e/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/kong/gateway-operator/internal/versions"
"github.com/kong/gateway-operator/pkg/clientset"
testutils "github.com/kong/gateway-operator/pkg/utils/test"
"github.com/kong/gateway-operator/test"
"github.com/kong/gateway-operator/test/helpers"
)

Expand Down Expand Up @@ -147,27 +148,37 @@ func CreateEnvironment(t *testing.T, ctx context.Context, opts ...TestEnvOption)
cluster, err := kind.NewFromExisting(clusterName)
require.NoError(t, err)
builder.WithExistingCluster(cluster)
builder.WithAddons(metallb.New())
builder.WithAddons(certmanager.New())

if !test.IsCertManagerDisabled() {
builder.WithAddons(certmanager.New())
}
if !test.IsMetalLBDisabled() {
builder.WithAddons(metallb.New())
}
case string(gke.GKEClusterType):
cluster, err := gke.NewFromExistingWithEnv(ctx, clusterName)
require.NoError(t, err)
builder.WithExistingCluster(cluster)
builder.WithAddons(certmanager.New())
if !test.IsCertManagerDisabled() {
builder.WithAddons(certmanager.New())
}
default:
t.Fatal(fmt.Errorf("unknown cluster type: %s", clusterType))
}
} else {
t.Log("no existing cluster found, deploying using Kubernetes In Docker (KIND)")
builder.WithAddons(metallb.New())
builder.WithAddons(certmanager.New())
if !test.IsCertManagerDisabled() {
builder.WithAddons(certmanager.New())
}
if !test.IsMetalLBDisabled() {
builder.WithAddons(metallb.New())
}
}
if imageLoad != "" {
imageLoader, err := loadimage.NewBuilder().WithImage(imageLoad)
require.NoError(t, err)
t.Logf("loading image: %s", imageLoad)
builder.WithAddons(imageLoader.Build())
builder.WithAddons(certmanager.New())
}

if len(opt.Image) == 0 {
Expand Down
40 changes: 40 additions & 0 deletions test/envvars.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package test

import (
"fmt"
"os"
"strings"
)

// IsCalicoCNIDisabled returns true if the Calico CNI plugin is disabled in the test environment.
func IsCalicoCNIDisabled() bool {
ret := strings.ToLower(os.Getenv("KONG_TEST_DISABLE_CALICO")) == "true"
if ret {
fmt.Println("INFO: CalicoCNI plugin is disabled")
} else {
fmt.Println("INFO: CalicoCNI plugin is enabled")
}
return ret
}

// IsCertManagerDisabled returns true if the Cert-Manager is disabled in the test environment.
func IsCertManagerDisabled() bool {
ret := strings.ToLower(os.Getenv("KONG_TEST_DISABLE_CERTMANAGER")) == "true"
if ret {
fmt.Println("INFO: CertManager plugin is disabled")
} else {
fmt.Println("INFO: CertManager plugin is enabled")
}
return ret
}

// IsMetalLBDisabled returns true if the MetalLB is disabled in the test environment.
func IsMetalLBDisabled() bool {
ret := strings.ToLower(os.Getenv("KONG_TEST_DISABLE_METALLB")) == "true"
if ret {
fmt.Println("INFO: MetalLB plugin is disabled")
} else {
fmt.Println("INFO: MetalLB plugin is enabled")
}
return ret
}
10 changes: 4 additions & 6 deletions test/integration/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/kong/gateway-operator/config"
"github.com/kong/gateway-operator/modules/manager"
testutils "github.com/kong/gateway-operator/pkg/utils/test"
"github.com/kong/gateway-operator/test"
"github.com/kong/gateway-operator/test/helpers"
"github.com/kong/gateway-operator/test/helpers/certificate"
)
Expand All @@ -40,9 +41,6 @@ var (
webhookServerIP = os.Getenv("GATEWAY_OPERATOR_WEBHOOK_IP")
bluegreenController = strings.ToLower(os.Getenv("GATEWAY_OPERATOR_BLUEGREEN_CONTROLLER")) == "true"
webhookServerPort = 9443
disableCalicoCNI = strings.ToLower(os.Getenv("KONG_TEST_DISABLE_CALICO")) == "true"
disableCertManager = strings.ToLower(os.Getenv("KONG_TEST_DISABLE_CERTMANAGER")) == "true"
disableMetalLB = strings.ToLower(os.Getenv("KONG_TEST_DISABLE_METALLB")) == "true"
)

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -124,13 +122,13 @@ func TestMain(
fmt.Println("INFO: configuring cluster for testing environment")
env, err = testutils.BuildEnvironment(GetCtx(), existingCluster,
func(b *environments.Builder, ct clusters.Type) {
if !disableCalicoCNI {
if !test.IsCalicoCNIDisabled() {
b.WithCalicoCNI()
}
if !disableCertManager {
if !test.IsCertManagerDisabled() {
b.WithAddons(certmanager.New())
}
if !disableMetalLB && ct == kind.KindClusterType {
if !test.IsMetalLBDisabled() && ct == kind.KindClusterType {
b.WithAddons(metallb.New())
}
},
Expand Down
Loading