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

tests: delete migrations job before upgrade in e2e test #4100

Merged
merged 1 commit into from
May 29, 2023
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
1 change: 0 additions & 1 deletion test/e2e/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ nodes:
`
validationWebhookName = "kong-validation-webhook"
kongNamespace = "kong"
admissionScriptPath = "../../hack/deploy-admission-controller.sh"
)

// openssl req -new -x509 -nodes -newkey ec:<(openssl ecparam -name secp384r1) -keyout cert.key -out cert.crt -days 3650 -subj '/CN=first.example/'
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ const (

// proxyContainerName is the name of the proxy container in all manifests variants.
proxyContainerName = "proxy"

// migrationsJobName is the name of the migrations job in postgres manifests variant.
migrationsJobName = "kong-migrations"
)

// setupE2ETest builds a testing environment for the E2E test. It also sets up the environment's teardown and test
Expand Down
32 changes: 29 additions & 3 deletions test/e2e/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
package e2e

import (
"context"
"fmt"
"testing"

"github.com/kong/kubernetes-testing-framework/pkg/environments"
"github.com/samber/lo"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/kong/kubernetes-ingress-controller/v2/test/internal/helpers"
)
Expand All @@ -25,16 +29,33 @@ const (
func TestDeployAndUpgradeAllInOneDBLESS(t *testing.T) {
fromManifestURL := fmt.Sprintf(dblessURLTemplate, upgradeTestFromTag)
toManifestPath := dblessPath
testManifestsUpgrade(t, fromManifestURL, toManifestPath)
testManifestsUpgrade(t, fromManifestURL, toManifestPath, nil)
}

func TestDeployAndUpgradeAllInOnePostgres(t *testing.T) {
fromManifestURL := fmt.Sprintf(postgresURLTemplate, upgradeTestFromTag)
toManifestPath := postgresPath
testManifestsUpgrade(t, fromManifestURL, toManifestPath)

// Injecting a beforeUpgradeHook to delete the old migrations job before the upgrade. This is necessary because it's
// not allowed to modify the existing job's spec.
beforeUpgradeHook := func(ctx context.Context, t *testing.T, env environments.Environment) {
err := env.Cluster().Client().BatchV1().Jobs(namespace).Delete(ctx, migrationsJobName, metav1.DeleteOptions{
PropagationPolicy: lo.ToPtr(metav1.DeletePropagationBackground),
})
require.NoError(t, err, "failed to delete old migrations job before upgrade")
}
testManifestsUpgrade(t, fromManifestURL, toManifestPath, beforeUpgradeHook)
}

func testManifestsUpgrade(t *testing.T, fromManifestURL string, toManifestPath string) {
// beforeUpgradeFn is a function that is run before the upgrade to clean up any resources that may interfere with the upgrade.
type beforeUpgradeFn func(ctx context.Context, t *testing.T, env environments.Environment)

func testManifestsUpgrade(
t *testing.T,
fromManifestURL string,
toManifestPath string,
beforeUpgradeHook beforeUpgradeFn,
) {
t.Parallel()

httpClient := helpers.RetryableHTTPClient(helpers.DefaultHTTPClient())
Expand All @@ -52,6 +73,11 @@ func testManifestsUpgrade(t *testing.T, fromManifestURL string, toManifestPath s
deployIngress(ctx, t, env)
verifyIngress(ctx, t, env)

if beforeUpgradeHook != nil {
t.Log("running before upgrade hook")
beforeUpgradeHook(ctx, t, env)
}

t.Logf("deploying target version of kong manifests: %s", toManifestPath)
manifest := getTestManifest(t, toManifestPath)
deployKong(ctx, t, env, manifest)
Expand Down