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

Consolidate E2E environment variables with integration varaibles #4727

Merged
merged 19 commits into from
Oct 23, 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
74 changes: 67 additions & 7 deletions .github/workflows/_e2e_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,25 @@ jobs:
with:
password: ${{ secrets.PULP_PASSWORD }}

- name: split image and tag
id: split
env:
KONG: ${{ inputs.kong-image }}
CONTROLLER: ${{ inputs.controller-image }}
run: |
if [ "${{ inputs.kong-image }}" != "" ]; then
export kong_image=$(echo ${{ inputs.kong-image }} | awk '{split($0,a,":"); print a[1]}')
export kong_tag=$(echo ${{ inputs.kong-image }} | awk '{split($0,a,":"); print a[2]}')
rainest marked this conversation as resolved.
Show resolved Hide resolved
echo "kong-image=$kong_image" >> $GITHUB_OUTPUT
echo "kong-tag=$kong_tag" >> $GITHUB_OUTPUT
fi
if [ "${{ inputs.kic-image }}" != "" ]; then
export kic_image=$(echo ${{ inputs.kic-image }} | awk '{split($0,a,":"); print a[1]}')
export kic_tag=$(echo ${{ inputs.kic-image }} | awk '{split($0,a,":"); print a[2]}')
echo "kic-image=$kic_image" >> $GITHUB_OUTPUT
echo "kic-tag=$kic_tag" >> $GITHUB_OUTPUT
fi
# We need to pull the Gateway image locally if loading local image was specified.
# This is a "workaround" of the fact that we bind the env variable - responsible for
# indicating whether we'd like to load the images - for both controller
Expand All @@ -149,9 +168,11 @@ jobs:
env:
E2E_TEST_RUN: ${{ matrix.test }}
KONG_CLUSTER_VERSION: ${{ matrix.kubernetes-version }}
TEST_KONG_CONTROLLER_IMAGE_OVERRIDE: ${{ inputs.kic-image }}
TEST_CONTROLLER_IMAGE: ${{ steps.split.outputs.kic-image }}
TEST_CONTROLLER_TAG: ${{ steps.split.outputs.kic-tag }}
TEST_KONG_LOAD_IMAGES: ${{ inputs.load-local-image }}
TEST_KONG_IMAGE_OVERRIDE: ${{ inputs.kong-image }}
TEST_KONG_IMAGE: ${{ steps.split.outputs.kong-image }}
TEST_KONG_TAG: ${{ steps.split.outputs.kong-tag }}
TEST_KONG_KONNECT_ACCESS_TOKEN: ${{ secrets.K8S_TEAM_KONNECT_ACCESS_TOKEN }}
KONG_LICENSE_DATA: ${{ steps.license.outputs.license }}
GOTESTSUM_JUNITFILE: "e2e-${{ matrix.test }}${{ matrix.kubernetes-version }}-tests.xml"
Expand Down Expand Up @@ -199,20 +220,37 @@ jobs:
with:
password: ${{ secrets.PULP_PASSWORD }}

- name: split image and tag
id: split
env:
KONG: ${{ inputs.kong-image }}
CONTROLLER: ${{ inputs.controller-image }}
run: |
if [ "${{ inputs.kong-image }}" != "" ]; then
export kong_image=$(echo ${{ inputs.kong-image }} | awk '{split($0,a,":"); print a[1]}')
export kong_tag=$(echo ${{ inputs.kong-image }} | awk '{split($0,a,":"); print a[2]}')
echo "kong-image=$kong_image" >> $GITHUB_OUTPUT
echo "kong-tag=$kong_tag" >> $GITHUB_OUTPUT
fi
# see the https://github.com/Kong/kubernetes-testing-framework/issues/587 TODO below
# if we add local image GKE support, we probably need to split it into components here
- name: run ${{ matrix.test }}
run: make test.e2e
env:
# NOTE: The limitation of the GKE setup is that we cannot run tests against a local image,
# therefore we need to use the nightly one.
# TODO: Once we have a way to load images into GKE, we can use the local image.
# KTF issue that should enable it: https://github.com/Kong/kubernetes-testing-framework/issues/587
TEST_KONG_CONTROLLER_IMAGE_OVERRIDE: "kong/nightly-ingress-controller:nightly"
TEST_KONG_IMAGE_OVERRIDE: ${{ inputs.kong-image }}
TEST_CONTROLLER_IMAGE: "kong/nightly-ingress-controller"
TEST_CONTROLLER_TAG: "nightly"
TEST_KONG_IMAGE: ${{ steps.split.outputs.kong-image }}
TEST_KONG_TAG: ${{ steps.split.outputs.kong-tag }}
TEST_KONG_EFFECTIVE_VERSION: ${{ inputs.kong-effective-version }}
KONG_LICENSE_DATA: ${{ steps.license.outputs.license }}
TEST_KONG_KONNECT_ACCESS_TOKEN: ${{ secrets.K8S_TEAM_KONNECT_ACCESS_TOKEN }}
KONG_CLUSTER_VERSION: ${{ matrix.kubernetes-version }}
KONG_TEST_CLUSTER_PROVIDER: gke
KONG_CLUSTER_PROVIDER: gke
E2E_TEST_RUN: ${{ matrix.test }}
GOTESTSUM_JUNITFILE: "e2e-gke-${{ matrix.test }}-${{ matrix.kubernetes-version }}-tests.xml"
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
Expand Down Expand Up @@ -270,12 +308,34 @@ jobs:
with:
password: ${{ secrets.PULP_PASSWORD }}

- name: split image and tag
id: split
env:
KONG: ${{ inputs.kong-image }}
CONTROLLER: ${{ inputs.controller-image }}
run: |
if [ "${{ inputs.kong-image }}" != "" ]; then
export kong_image=$(echo ${{ inputs.kong-image }} | awk '{split($0,a,":"); print a[1]}')
export kong_tag=$(echo ${{ inputs.kong-image }} | awk '{split($0,a,":"); print a[2]}')
echo "kong-image=$kong_image" >> $GITHUB_OUTPUT
echo "kong-tag=$kong_tag" >> $GITHUB_OUTPUT
fi
if [ "${{ inputs.kic-image }}" != "" ]; then
export kic_image=$(echo ${{ inputs.kic-image }} | awk '{split($0,a,":"); print a[1]}')
export kic_tag=$(echo ${{ inputs.kic-image }} | awk '{split($0,a,":"); print a[2]}')
echo "kic-image=$kic_image" >> $GITHUB_OUTPUT
echo "kic-tag=$kic_tag" >> $GITHUB_OUTPUT
fi
- name: run Istio tests
run: make test.istio
env:
TEST_KONG_CONTROLLER_IMAGE_OVERRIDE: ${{ inputs.kic-image }}
TEST_CONTROLLER_IMAGE: ${{ steps.split.outputs.kic-image }}
TEST_CONTROLLER_TAG: ${{ steps.split.outputs.kic-tag }}
TEST_KONG_LOAD_IMAGES: ${{ inputs.load-local-image }}
TEST_KONG_IMAGE_OVERRIDE: ${{ inputs.kong-image }}
TEST_KONG_IMAGE: ${{ steps.split.outputs.kong-image }}
TEST_KONG_TAG: ${{ steps.split.outputs.kong-tag }}
KONG_LICENSE_DATA: ${{ steps.license.outputs.license }}
KONG_CLUSTER_VERSION: ${{ matrix.kind }}
ISTIO_VERSION: ${{ matrix.istio }}
Expand Down
37 changes: 0 additions & 37 deletions test/e2e/environment.go

This file was deleted.

6 changes: 4 additions & 2 deletions test/e2e/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ func TestWebhookUpdate(t *testing.T) {
require.NoError(t, err)
addons := []clusters.Addon{}
addons = append(addons, metallb.New())
if shouldLoadImages() {
if b, err := loadimage.NewBuilder().WithImage(controllerImageOverride); err == nil {
if testenv.ClusterLoadImages() == "true" {
if b, err := loadimage.NewBuilder().WithImage(testenv.ControllerImageTag()); err == nil {
rainest marked this conversation as resolved.
Show resolved Hide resolved
addons = append(addons, b.Build())
} else {
require.NoError(t, err)
}
}
builder := environments.NewBuilder().WithExistingCluster(cluster).WithAddons(addons...)
Expand Down
34 changes: 17 additions & 17 deletions test/e2e/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ func setupE2ETest(t *testing.T, addons ...clusters.Addon) (context.Context, envi
func getEnvironmentBuilder(ctx context.Context, t *testing.T) (*environments.Builder, error) {
t.Helper()

if existingCluster == "" {
t.Logf("no existing cluster provided, creating a new one for %q type", clusterProvider)
switch clusterProvider {
if testenv.ExistingClusterName() == "" {
t.Logf("no existing cluster provided, creating a new one for %q type", testenv.ClusterProvider())
switch testenv.ClusterProvider() {
case string(gke.GKEClusterType):
t.Log("creating a GKE cluster builder")
return createGKEBuilder(t)
Expand All @@ -127,9 +127,9 @@ func getEnvironmentBuilder(ctx context.Context, t *testing.T) (*environments.Bui
}
}

clusterParts := strings.Split(existingCluster, ":")
clusterParts := strings.Split(testenv.ExistingClusterName(), ":")
if len(clusterParts) < 2 {
return nil, fmt.Errorf("expected existing cluster in format <type>:<name>, got %s", existingCluster)
return nil, fmt.Errorf("expected existing cluster in format <type>:<name>, got %s", testenv.ExistingClusterName())
}

clusterType, clusterName := clusterParts[0], clusterParts[1]
Expand Down Expand Up @@ -171,8 +171,8 @@ func createKINDBuilder(t *testing.T) *environments.Builder {
clusterBuilder = clusterBuilder.WithClusterVersion(clusterVersion)
}
builder := environments.NewBuilder().WithClusterBuilder(clusterBuilder).WithAddons(metallb.New())
if shouldLoadImages() {
builder = builder.WithAddons(buildImageLoadAddon(t, controllerImageOverride, kongImageOverride))
if testenv.ClusterLoadImages() == "true" {
builder = builder.WithAddons(buildImageLoadAddon(t, testenv.ControllerImageTag(), testenv.KongImageTag()))
}
return builder
}
Expand All @@ -184,8 +184,8 @@ func createExistingKINDBuilder(t *testing.T, name string) (*environments.Builder

builder = builder.WithExistingCluster(cluster)
builder = builder.WithAddons(metallb.New())
if shouldLoadImages() {
builder = builder.WithAddons(buildImageLoadAddon(t, controllerImageOverride, kongImageOverride))
if testenv.ClusterLoadImages() == "true" {
builder = builder.WithAddons(buildImageLoadAddon(t, testenv.ControllerImageTag(), testenv.KongImageTag()))
}
return builder, nil
}
Expand Down Expand Up @@ -237,7 +237,7 @@ type ManifestDeploy struct {
Path string

// SkipTestPatches is a flag that controls whether to apply standard test patches (e.g. replace controller
// image when TEST_KONG_CONTROLLER_IMAGE_OVERRIDE set, etc.) to the manifests before deploying them.
// image when TEST_CONTROLLER_IMAGE set, etc.) to the manifests before deploying them.
SkipTestPatches bool

// AdditionalSecrets is a list of additional secrets to create before deploying the manifest.
Expand Down Expand Up @@ -723,7 +723,7 @@ func buildImageLoadAddon(t *testing.T, images ...string) clusters.Addon {
func createKongImagePullSecret(ctx context.Context, t *testing.T, env environments.Environment) {
t.Helper()

if kongImagePullUsername == "" || kongImagePullPassword == "" {
if testenv.KongPullUsername() == "" || testenv.KongPullPassword() == "" {
return
}
kubeconfigFilename := getTemporaryKubeconfig(t, env)
Expand All @@ -733,8 +733,8 @@ func createKongImagePullSecret(ctx context.Context, t *testing.T, env environmen
ctx,
"kubectl", "--kubeconfig", kubeconfigFilename,
"create", "secret", "docker-registry", secretName,
"--docker-username="+kongImagePullUsername,
"--docker-password="+kongImagePullPassword,
"--docker-username="+testenv.KongPullUsername(),
"--docker-password="+testenv.KongPullPassword(),
)
out, err := cmd.CombinedOutput()
require.NoError(t, err, "command output: "+string(out))
Expand Down Expand Up @@ -792,18 +792,18 @@ func getTemporaryKubeconfig(t *testing.T, env environments.Environment) string {
func runOnlyOnKindClusters(t *testing.T) {
t.Helper()

existingClusterIsKind := strings.Split(existingCluster, ":")[0] == string(kind.KindClusterType)
existingClusterIsKind := strings.Split(testenv.ExistingClusterName(), ":")[0] == string(kind.KindClusterType)
if existingClusterIsKind {
return
}

clusterProviderIsKind := clusterProvider == string(kind.KindClusterType)
clusterProviderIsKind := testenv.ClusterProvider() == string(kind.KindClusterType)
if clusterProviderIsKind {
return
}

clusterProviderUnspecified := clusterProvider == ""
existingClusterUnspecified := existingCluster == ""
clusterProviderUnspecified := testenv.ClusterProvider() == ""
existingClusterUnspecified := testenv.ExistingClusterName() == ""
if clusterProviderUnspecified && existingClusterUnspecified {
return
}
Expand Down
5 changes: 3 additions & 2 deletions test/e2e/konnect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/kong/kubernetes-ingress-controller/v2/internal/konnect/roles"
"github.com/kong/kubernetes-ingress-controller/v2/test/helpers/certificate"
"github.com/kong/kubernetes-ingress-controller/v2/test/internal/helpers"
"github.com/kong/kubernetes-ingress-controller/v2/test/internal/testenv"
)

const (
Expand Down Expand Up @@ -176,9 +177,9 @@ func generateTestKonnectControlPlaneDescription(t *testing.T) string {
t.Helper()

desc := fmt.Sprintf("control plane for test %s", t.Name())
if githubServerURL != "" && githubRepo != "" && githubRunID != "" {
if testenv.GithubServerURL() != "" && testenv.GithubRepo() != "" && testenv.GithubRunID() != "" {
githubRunURL := fmt.Sprintf("%s/%s/actions/runs/%s",
githubServerURL, githubRepo, githubRunID)
testenv.GithubServerURL(), testenv.GithubRepo(), testenv.GithubRunID())
desc += ", github workflow run " + githubRunURL
}

Expand Down
Loading