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 13 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
27 changes: 24 additions & 3 deletions .github/workflows/_e2e_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,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 @@ -141,9 +160,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 @@ -205,7 +226,7 @@ jobs:
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
43 changes: 0 additions & 43 deletions test/e2e/environment.go

This file was deleted.

9 changes: 5 additions & 4 deletions test/e2e/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/kong/kubernetes-ingress-controller/v2/test/consts"
"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"
)

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -84,8 +85,8 @@ func TestWebhookUpdate(t *testing.T) {
t.Log("building test cluster and environment")
clusterBuilder := kind.NewBuilder()
clusterBuilder.WithConfigReader(strings.NewReader(webhookKINDConfig))
if clusterVersionStr != "" {
clusterVersion, err := semver.ParseTolerant(clusterVersionStr)
if testenv.ClusterVersion() != "" {
clusterVersion, err := semver.ParseTolerant(testenv.ClusterVersion())
require.NoError(t, err)
t.Logf("k8s cluster version is set to %v", clusterVersion)
clusterBuilder.WithClusterVersion(clusterVersion)
Expand All @@ -94,8 +95,8 @@ 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())
}
}
Expand Down
44 changes: 22 additions & 22 deletions test/e2e/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,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 @@ -129,13 +129,13 @@ 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]
if clusterVersionStr != "" {
if testenv.ClusterVersion() != "" {
return nil, fmt.Errorf("cannot provide cluster version with existing cluster")
}

Expand Down Expand Up @@ -168,13 +168,13 @@ kubeadmConfigPatches:

func createKINDBuilder(t *testing.T) *environments.Builder {
clusterBuilder := kind.NewBuilder().WithConfigReader(strings.NewReader(kindConfig))
if clusterVersionStr != "" {
clusterVersion := semver.MustParse(strings.TrimPrefix(clusterVersionStr, "v"))
if testenv.ClusterVersion() != "" {
clusterVersion := semver.MustParse(strings.TrimPrefix(testenv.ClusterVersion(), "v"))
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 @@ -186,8 +186,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 @@ -221,8 +221,8 @@ func createGKEBuilder(t *testing.T) (*environments.Builder, error) {
WithCreateSubnet(true).
WithLabels(gkeTestClusterLabels())

if clusterVersionStr != "" {
k8sVersion, err := semver.Parse(strings.TrimPrefix(clusterVersionStr, "v"))
if testenv.ClusterVersion() != "" {
k8sVersion, err := semver.Parse(strings.TrimPrefix(testenv.ClusterVersion(), "v"))
if err != nil {
return nil, err
}
Expand All @@ -239,7 +239,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 @@ -776,7 +776,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 @@ -786,8 +786,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 @@ -845,18 +845,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 (
rgc "github.com/kong/kubernetes-ingress-controller/v2/internal/konnect/runtimegroupsconfig"
"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 @@ -179,9 +180,9 @@ func generateTestKonnectRuntimeGroupDescription(t *testing.T) string {
t.Helper()

desc := fmt.Sprintf("runtime group 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