Skip to content

Commit d8bbfd9

Browse files
authored
chore(e2e) use shared envvar definitions (#4727)
* chore(e2e) use testenv.ClusterVersion() * chore(e2e) use testenv image/tag overrides * chore(e2e) use testenv pull credentials * chore(e2e) use testenv cluster info * chore(e2e) use testenv image load flag * chore(e2e) move Github env into testenv * chore(e2e) remove e2e-specific envvars * chore(e2e) update workflow envvars
1 parent 25e721e commit d8bbfd9

File tree

7 files changed

+217
-96
lines changed

7 files changed

+217
-96
lines changed

.github/workflows/_e2e_tests.yaml

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,25 @@ jobs:
134134
with:
135135
password: ${{ secrets.PULP_PASSWORD }}
136136

137+
- name: split image and tag
138+
id: split
139+
env:
140+
KONG: ${{ inputs.kong-image }}
141+
CONTROLLER: ${{ inputs.controller-image }}
142+
run: |
143+
if [ "${{ inputs.kong-image }}" != "" ]; then
144+
export kong_image=$(echo ${{ inputs.kong-image }} | awk '{split($0,a,":"); print a[1]}')
145+
export kong_tag=$(echo ${{ inputs.kong-image }} | awk '{split($0,a,":"); print a[2]}')
146+
echo "kong-image=$kong_image" >> $GITHUB_OUTPUT
147+
echo "kong-tag=$kong_tag" >> $GITHUB_OUTPUT
148+
fi
149+
if [ "${{ inputs.kic-image }}" != "" ]; then
150+
export kic_image=$(echo ${{ inputs.kic-image }} | awk '{split($0,a,":"); print a[1]}')
151+
export kic_tag=$(echo ${{ inputs.kic-image }} | awk '{split($0,a,":"); print a[2]}')
152+
echo "kic-image=$kic_image" >> $GITHUB_OUTPUT
153+
echo "kic-tag=$kic_tag" >> $GITHUB_OUTPUT
154+
fi
155+
137156
# We need to pull the Gateway image locally if loading local image was specified.
138157
# This is a "workaround" of the fact that we bind the env variable - responsible for
139158
# indicating whether we'd like to load the images - for both controller
@@ -149,9 +168,11 @@ jobs:
149168
env:
150169
E2E_TEST_RUN: ${{ matrix.test }}
151170
KONG_CLUSTER_VERSION: ${{ matrix.kubernetes-version }}
152-
TEST_KONG_CONTROLLER_IMAGE_OVERRIDE: ${{ inputs.kic-image }}
171+
TEST_CONTROLLER_IMAGE: ${{ steps.split.outputs.kic-image }}
172+
TEST_CONTROLLER_TAG: ${{ steps.split.outputs.kic-tag }}
153173
TEST_KONG_LOAD_IMAGES: ${{ inputs.load-local-image }}
154-
TEST_KONG_IMAGE_OVERRIDE: ${{ inputs.kong-image }}
174+
TEST_KONG_IMAGE: ${{ steps.split.outputs.kong-image }}
175+
TEST_KONG_TAG: ${{ steps.split.outputs.kong-tag }}
155176
TEST_KONG_KONNECT_ACCESS_TOKEN: ${{ secrets.K8S_TEAM_KONNECT_ACCESS_TOKEN }}
156177
KONG_LICENSE_DATA: ${{ steps.license.outputs.license }}
157178
GOTESTSUM_JUNITFILE: "e2e-${{ matrix.test }}${{ matrix.kubernetes-version }}-tests.xml"
@@ -199,20 +220,37 @@ jobs:
199220
with:
200221
password: ${{ secrets.PULP_PASSWORD }}
201222

223+
- name: split image and tag
224+
id: split
225+
env:
226+
KONG: ${{ inputs.kong-image }}
227+
CONTROLLER: ${{ inputs.controller-image }}
228+
run: |
229+
if [ "${{ inputs.kong-image }}" != "" ]; then
230+
export kong_image=$(echo ${{ inputs.kong-image }} | awk '{split($0,a,":"); print a[1]}')
231+
export kong_tag=$(echo ${{ inputs.kong-image }} | awk '{split($0,a,":"); print a[2]}')
232+
echo "kong-image=$kong_image" >> $GITHUB_OUTPUT
233+
echo "kong-tag=$kong_tag" >> $GITHUB_OUTPUT
234+
fi
235+
# see the https://github.com/Kong/kubernetes-testing-framework/issues/587 TODO below
236+
# if we add local image GKE support, we probably need to split it into components here
237+
202238
- name: run ${{ matrix.test }}
203239
run: make test.e2e
204240
env:
205241
# NOTE: The limitation of the GKE setup is that we cannot run tests against a local image,
206242
# therefore we need to use the nightly one.
207243
# TODO: Once we have a way to load images into GKE, we can use the local image.
208244
# KTF issue that should enable it: https://github.com/Kong/kubernetes-testing-framework/issues/587
209-
TEST_KONG_CONTROLLER_IMAGE_OVERRIDE: "kong/nightly-ingress-controller:nightly"
210-
TEST_KONG_IMAGE_OVERRIDE: ${{ inputs.kong-image }}
245+
TEST_CONTROLLER_IMAGE: "kong/nightly-ingress-controller"
246+
TEST_CONTROLLER_TAG: "nightly"
247+
TEST_KONG_IMAGE: ${{ steps.split.outputs.kong-image }}
248+
TEST_KONG_TAG: ${{ steps.split.outputs.kong-tag }}
211249
TEST_KONG_EFFECTIVE_VERSION: ${{ inputs.kong-effective-version }}
212250
KONG_LICENSE_DATA: ${{ steps.license.outputs.license }}
213251
TEST_KONG_KONNECT_ACCESS_TOKEN: ${{ secrets.K8S_TEAM_KONNECT_ACCESS_TOKEN }}
214252
KONG_CLUSTER_VERSION: ${{ matrix.kubernetes-version }}
215-
KONG_TEST_CLUSTER_PROVIDER: gke
253+
KONG_CLUSTER_PROVIDER: gke
216254
E2E_TEST_RUN: ${{ matrix.test }}
217255
GOTESTSUM_JUNITFILE: "e2e-gke-${{ matrix.test }}-${{ matrix.kubernetes-version }}-tests.xml"
218256
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
@@ -270,12 +308,34 @@ jobs:
270308
with:
271309
password: ${{ secrets.PULP_PASSWORD }}
272310

311+
- name: split image and tag
312+
id: split
313+
env:
314+
KONG: ${{ inputs.kong-image }}
315+
CONTROLLER: ${{ inputs.controller-image }}
316+
run: |
317+
if [ "${{ inputs.kong-image }}" != "" ]; then
318+
export kong_image=$(echo ${{ inputs.kong-image }} | awk '{split($0,a,":"); print a[1]}')
319+
export kong_tag=$(echo ${{ inputs.kong-image }} | awk '{split($0,a,":"); print a[2]}')
320+
echo "kong-image=$kong_image" >> $GITHUB_OUTPUT
321+
echo "kong-tag=$kong_tag" >> $GITHUB_OUTPUT
322+
fi
323+
if [ "${{ inputs.kic-image }}" != "" ]; then
324+
export kic_image=$(echo ${{ inputs.kic-image }} | awk '{split($0,a,":"); print a[1]}')
325+
export kic_tag=$(echo ${{ inputs.kic-image }} | awk '{split($0,a,":"); print a[2]}')
326+
echo "kic-image=$kic_image" >> $GITHUB_OUTPUT
327+
echo "kic-tag=$kic_tag" >> $GITHUB_OUTPUT
328+
fi
329+
330+
273331
- name: run Istio tests
274332
run: make test.istio
275333
env:
276-
TEST_KONG_CONTROLLER_IMAGE_OVERRIDE: ${{ inputs.kic-image }}
334+
TEST_CONTROLLER_IMAGE: ${{ steps.split.outputs.kic-image }}
335+
TEST_CONTROLLER_TAG: ${{ steps.split.outputs.kic-tag }}
277336
TEST_KONG_LOAD_IMAGES: ${{ inputs.load-local-image }}
278-
TEST_KONG_IMAGE_OVERRIDE: ${{ inputs.kong-image }}
337+
TEST_KONG_IMAGE: ${{ steps.split.outputs.kong-image }}
338+
TEST_KONG_TAG: ${{ steps.split.outputs.kong-tag }}
279339
KONG_LICENSE_DATA: ${{ steps.license.outputs.license }}
280340
KONG_CLUSTER_VERSION: ${{ matrix.kind }}
281341
ISTIO_VERSION: ${{ matrix.istio }}

test/e2e/environment.go

Lines changed: 0 additions & 37 deletions
This file was deleted.

test/e2e/features_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,11 @@ func TestWebhookUpdate(t *testing.T) {
9696
require.NoError(t, err)
9797
addons := []clusters.Addon{}
9898
addons = append(addons, metallb.New())
99-
if shouldLoadImages() {
100-
if b, err := loadimage.NewBuilder().WithImage(controllerImageOverride); err == nil {
99+
if testenv.ClusterLoadImages() == "true" {
100+
if b, err := loadimage.NewBuilder().WithImage(testenv.ControllerImageTag()); err == nil {
101101
addons = append(addons, b.Build())
102+
} else {
103+
require.NoError(t, err)
102104
}
103105
}
104106
builder := environments.NewBuilder().WithExistingCluster(cluster).WithAddons(addons...)

test/e2e/helpers_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ func setupE2ETest(t *testing.T, addons ...clusters.Addon) (context.Context, envi
115115
func getEnvironmentBuilder(ctx context.Context, t *testing.T) (*environments.Builder, error) {
116116
t.Helper()
117117

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

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

135135
clusterType, clusterName := clusterParts[0], clusterParts[1]
@@ -171,8 +171,8 @@ func createKINDBuilder(t *testing.T) *environments.Builder {
171171
clusterBuilder = clusterBuilder.WithClusterVersion(clusterVersion)
172172
}
173173
builder := environments.NewBuilder().WithClusterBuilder(clusterBuilder).WithAddons(metallb.New())
174-
if shouldLoadImages() {
175-
builder = builder.WithAddons(buildImageLoadAddon(t, controllerImageOverride, kongImageOverride))
174+
if testenv.ClusterLoadImages() == "true" {
175+
builder = builder.WithAddons(buildImageLoadAddon(t, testenv.ControllerImageTag(), testenv.KongImageTag()))
176176
}
177177
return builder
178178
}
@@ -184,8 +184,8 @@ func createExistingKINDBuilder(t *testing.T, name string) (*environments.Builder
184184

185185
builder = builder.WithExistingCluster(cluster)
186186
builder = builder.WithAddons(metallb.New())
187-
if shouldLoadImages() {
188-
builder = builder.WithAddons(buildImageLoadAddon(t, controllerImageOverride, kongImageOverride))
187+
if testenv.ClusterLoadImages() == "true" {
188+
builder = builder.WithAddons(buildImageLoadAddon(t, testenv.ControllerImageTag(), testenv.KongImageTag()))
189189
}
190190
return builder, nil
191191
}
@@ -237,7 +237,7 @@ type ManifestDeploy struct {
237237
Path string
238238

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

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

726-
if kongImagePullUsername == "" || kongImagePullPassword == "" {
726+
if testenv.KongPullUsername() == "" || testenv.KongPullPassword() == "" {
727727
return
728728
}
729729
kubeconfigFilename := getTemporaryKubeconfig(t, env)
@@ -733,8 +733,8 @@ func createKongImagePullSecret(ctx context.Context, t *testing.T, env environmen
733733
ctx,
734734
"kubectl", "--kubeconfig", kubeconfigFilename,
735735
"create", "secret", "docker-registry", secretName,
736-
"--docker-username="+kongImagePullUsername,
737-
"--docker-password="+kongImagePullPassword,
736+
"--docker-username="+testenv.KongPullUsername(),
737+
"--docker-password="+testenv.KongPullPassword(),
738738
)
739739
out, err := cmd.CombinedOutput()
740740
require.NoError(t, err, "command output: "+string(out))
@@ -792,18 +792,18 @@ func getTemporaryKubeconfig(t *testing.T, env environments.Environment) string {
792792
func runOnlyOnKindClusters(t *testing.T) {
793793
t.Helper()
794794

795-
existingClusterIsKind := strings.Split(existingCluster, ":")[0] == string(kind.KindClusterType)
795+
existingClusterIsKind := strings.Split(testenv.ExistingClusterName(), ":")[0] == string(kind.KindClusterType)
796796
if existingClusterIsKind {
797797
return
798798
}
799799

800-
clusterProviderIsKind := clusterProvider == string(kind.KindClusterType)
800+
clusterProviderIsKind := testenv.ClusterProvider() == string(kind.KindClusterType)
801801
if clusterProviderIsKind {
802802
return
803803
}
804804

805-
clusterProviderUnspecified := clusterProvider == ""
806-
existingClusterUnspecified := existingCluster == ""
805+
clusterProviderUnspecified := testenv.ClusterProvider() == ""
806+
existingClusterUnspecified := testenv.ExistingClusterName() == ""
807807
if clusterProviderUnspecified && existingClusterUnspecified {
808808
return
809809
}

test/e2e/konnect_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/kong/kubernetes-ingress-controller/v2/internal/konnect/roles"
3636
"github.com/kong/kubernetes-ingress-controller/v2/test/helpers/certificate"
3737
"github.com/kong/kubernetes-ingress-controller/v2/test/internal/helpers"
38+
"github.com/kong/kubernetes-ingress-controller/v2/test/internal/testenv"
3839
)
3940

4041
const (
@@ -176,9 +177,9 @@ func generateTestKonnectControlPlaneDescription(t *testing.T) string {
176177
t.Helper()
177178

178179
desc := fmt.Sprintf("control plane for test %s", t.Name())
179-
if githubServerURL != "" && githubRepo != "" && githubRunID != "" {
180+
if testenv.GithubServerURL() != "" && testenv.GithubRepo() != "" && testenv.GithubRunID() != "" {
180181
githubRunURL := fmt.Sprintf("%s/%s/actions/runs/%s",
181-
githubServerURL, githubRepo, githubRunID)
182+
testenv.GithubServerURL(), testenv.GithubRepo(), testenv.GithubRunID())
182183
desc += ", github workflow run " + githubRunURL
183184
}
184185

0 commit comments

Comments
 (0)