diff --git a/test/e2e/all_in_one_test.go b/test/e2e/all_in_one_test.go index a109d279c1..d15ca30830 100644 --- a/test/e2e/all_in_one_test.go +++ b/test/e2e/all_in_one_test.go @@ -13,8 +13,6 @@ import ( "github.com/kong/kubernetes-testing-framework/pkg/clusters" "github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/kong" - "github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/metallb" - "github.com/kong/kubernetes-testing-framework/pkg/environments" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" autoscalingv1 "k8s.io/api/autoscaling/v1" @@ -107,13 +105,8 @@ func TestDeployAndUpgradeAllInOneDBLESS(t *testing.T) { defer cancel() t.Log("building test cluster and environment") - addons := []clusters.Addon{} - addons = append(addons, metallb.New()) - - addons = append(addons, buildImageLoadAddons(t, imageLoad, kongImageLoad)...) - - builder := setBuilderKubernetesVersion(t, - environments.NewBuilder().WithAddons(addons...), clusterVersionStr) + builder, err := getEnvironmentBuilder(ctx) + require.NoError(t, err) env, err := builder.Build(ctx) require.NoError(t, err) @@ -159,13 +152,8 @@ func TestDeployAllInOneEnterpriseDBLESS(t *testing.T) { defer cancel() t.Log("building test cluster and environment") - addons := []clusters.Addon{} - addons = append(addons, metallb.New()) - - addons = append(addons, buildImageLoadAddons(t, imageLoad, kongImageLoad)...) - - builder := setBuilderKubernetesVersion(t, - environments.NewBuilder().WithAddons(addons...), clusterVersionStr) + builder, err := getEnvironmentBuilder(ctx) + require.NoError(t, err) env, err := builder.Build(ctx) require.NoError(t, err) @@ -215,13 +203,8 @@ func TestDeployAllInOnePostgres(t *testing.T) { defer cancel() t.Log("building test cluster and environment") - addons := []clusters.Addon{} - addons = append(addons, metallb.New()) - - addons = append(addons, buildImageLoadAddons(t, imageLoad, kongImageLoad)...) - - builder := setBuilderKubernetesVersion(t, - environments.NewBuilder().WithAddons(addons...), clusterVersionStr) + builder, err := getEnvironmentBuilder(ctx) + require.NoError(t, err) env, err := builder.Build(ctx) require.NoError(t, err) @@ -256,13 +239,8 @@ func TestDeployAllInOnePostgresWithMultipleReplicas(t *testing.T) { defer cancel() t.Log("building test cluster and environment") - addons := []clusters.Addon{} - addons = append(addons, metallb.New()) - - addons = append(addons, buildImageLoadAddons(t, imageLoad, kongImageLoad)...) - - builder := setBuilderKubernetesVersion(t, - environments.NewBuilder().WithAddons(addons...), clusterVersionStr) + builder, err := getEnvironmentBuilder(ctx) + require.NoError(t, err) env, err := builder.Build(ctx) require.NoError(t, err) @@ -412,13 +390,8 @@ func TestDeployAllInOneEnterprisePostgres(t *testing.T) { defer cancel() t.Log("building test cluster and environment") - addons := []clusters.Addon{} - addons = append(addons, metallb.New()) - - addons = append(addons, buildImageLoadAddons(t, imageLoad, kongImageLoad)...) - - builder := setBuilderKubernetesVersion(t, - environments.NewBuilder().WithAddons(addons...), clusterVersionStr) + builder, err := getEnvironmentBuilder(ctx) + require.NoError(t, err) env, err := builder.Build(ctx) require.NoError(t, err) createKongImagePullSecret(ctx, t, env) diff --git a/test/e2e/features_test.go b/test/e2e/features_test.go index 9cef3f70a5..7267ce0476 100644 --- a/test/e2e/features_test.go +++ b/test/e2e/features_test.go @@ -135,6 +135,18 @@ func TestWebhookUpdate(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() + // on KIND, this test requires webhookKINDConfig. the generic getEnvironmentBuilder we use for most tests doesn't + // support this: the configuration is specific to KIND but should not be used by default, and the scaffolding isn't + // flexible enough to support tests building their own clusters or passing additional builder functions. this still + // uses the setup style from before getEnvironmentBuilder/GKE support as such, and just skips if it's attempting + // to run on GKE + if existingCluster != "" { + clusterType := strings.Split(existingCluster, ":")[0] + if clusterType != string(kind.KindClusterType) { + t.Skip("test not supported on non-KIND clusters") + } + } + t.Log("building test cluster and environment") configFile, err := os.CreateTemp(os.TempDir(), "webhook-kind-config-") require.NoError(t, err) @@ -302,14 +314,8 @@ func TestDeployAllInOneDBLESSGateway(t *testing.T) { defer cancel() t.Log("building test cluster and environment") - addons := []clusters.Addon{} - addons = append(addons, metallb.New()) - if b, err := loadimage.NewBuilder().WithImage(imageLoad); err == nil { - addons = append(addons, b.Build()) - } - - builder := setBuilderKubernetesVersion(t, - environments.NewBuilder().WithAddons(addons...), clusterVersionStr) + builder, err := getEnvironmentBuilder(ctx) + require.NoError(t, err) env, err := builder.Build(ctx) require.NoError(t, err) @@ -498,13 +504,8 @@ func TestDeployAllInOneDBLESSNoLoadBalancer(t *testing.T) { defer cancel() t.Log("building test cluster and environment") - addons := []clusters.Addon{} - if b, err := loadimage.NewBuilder().WithImage(imageLoad); err == nil { - addons = append(addons, b.Build()) - } - - builder := setBuilderKubernetesVersion(t, - environments.NewBuilder().WithAddons(addons...), clusterVersionStr) + builder, err := getEnvironmentBuilder(ctx) + require.NoError(t, err) env, err := builder.Build(ctx) require.NoError(t, err) cleaner := clusters.NewCleaner(env.Cluster()) @@ -568,29 +569,8 @@ func TestDefaultIngressClass(t *testing.T) { defer cancel() t.Log("building test cluster and environment") - configFile, err := os.CreateTemp(os.TempDir(), "test-default-ingress-class") - require.NoError(t, err) - defer os.Remove(configFile.Name()) - defer configFile.Close() - written, err := configFile.Write([]byte(webhookKINDConfig)) + builder, err := getEnvironmentBuilder(ctx) require.NoError(t, err) - require.Equal(t, len(webhookKINDConfig), written) - - clusterBuilder := kind.NewBuilder() - clusterBuilder.WithConfig(configFile.Name()) - if clusterVersionStr != "" { - clusterVersion, err := semver.ParseTolerant(clusterVersionStr) - require.NoError(t, err) - clusterBuilder.WithClusterVersion(clusterVersion) - } - cluster, err := clusterBuilder.Build(ctx) - require.NoError(t, err) - addons := []clusters.Addon{} - addons = append(addons, metallb.New()) - if b, err := loadimage.NewBuilder().WithImage(imageLoad); err == nil { - addons = append(addons, b.Build()) - } - builder := environments.NewBuilder().WithExistingCluster(cluster).WithAddons(addons...) env, err := builder.Build(ctx) require.NoError(t, err) @@ -712,21 +692,8 @@ func TestMissingCRDsDontCrashTheController(t *testing.T) { defer cancel() t.Log("building test cluster and environment") - clusterBuilder := kind.NewBuilder() - if clusterVersionStr != "" { - clusterVersion, err := semver.ParseTolerant(clusterVersionStr) - require.NoError(t, err) - clusterBuilder.WithClusterVersion(clusterVersion) - } - cluster, err := clusterBuilder.Build(ctx) + builder, err := getEnvironmentBuilder(ctx) require.NoError(t, err) - addons := []clusters.Addon{metallb.New()} - - if b, err := loadimage.NewBuilder().WithImage(imageLoad); err == nil { - addons = append(addons, b.Build()) - } - - builder := environments.NewBuilder().WithExistingCluster(cluster).WithAddons(addons...) env, err := builder.Build(ctx) require.NoError(t, err) @@ -739,7 +706,7 @@ func TestMissingCRDsDontCrashTheController(t *testing.T) { t.Logf("%s failed, dumped diagnostics to %s", t.Name(), output) } } - assert.NoError(t, cluster.Cleanup(ctx)) + assert.NoError(t, cleaner.Cleanup(ctx)) }() t.Log("deploying kong components") diff --git a/test/e2e/helpers_test.go b/test/e2e/helpers_test.go index 410bcc979a..4bd77df665 100644 --- a/test/e2e/helpers_test.go +++ b/test/e2e/helpers_test.go @@ -102,15 +102,13 @@ func getEnvironmentBuilder(ctx context.Context) (*environments.Builder, error) { func createDefaultKINDBuilder() *environments.Builder { builder := environments.NewBuilder() clusterBuilder := kind.NewBuilder() - if false { // condition on image loads - // TODO load image but refactored - } if clusterVersionStr != "" { clusterVersion := semver.MustParse(strings.TrimPrefix(clusterVersionStr, "v")) clusterBuilder = clusterBuilder.WithClusterVersion(clusterVersion) } builder = builder.WithClusterBuilder(clusterBuilder) builder = builder.WithAddons(metallb.New()) + builder = builder.WithAddons(buildImageLoadAddons(imageLoad, kongImageLoad)...) return builder } @@ -120,11 +118,9 @@ func createExistingKINDBuilder(name string) (*environments.Builder, error) { if err != nil { return nil, err } - if false { // condition on image loads - // TODO load image but refactored - } builder = builder.WithExistingCluster(cluster) builder = builder.WithAddons(metallb.New()) + builder = builder.WithAddons(buildImageLoadAddons(imageLoad, kongImageLoad)...) return builder, nil } @@ -404,13 +400,13 @@ func killKong(ctx context.Context, t *testing.T, env environments.Environment, p } // buildImageLoadAddons creates addons to load KIC and kong images. -func buildImageLoadAddons(t *testing.T, images ...string) []clusters.Addon { +func buildImageLoadAddons(images ...string) []clusters.Addon { addons := []clusters.Addon{} for _, image := range images { if image != "" { - t.Logf("load image %s", image) - b, err := loadimage.NewBuilder().WithImage(image) - require.NoError(t, err) + // https://github.com/Kong/kubernetes-testing-framework/issues/440 this error only occurs if image == "" + // it will eventually be removed from the WithImage return signature + b, _ := loadimage.NewBuilder().WithImage(image) addons = append(addons, b.Build()) } } diff --git a/test/e2e/kuma_test.go b/test/e2e/kuma_test.go index bca9560935..f209411cf8 100644 --- a/test/e2e/kuma_test.go +++ b/test/e2e/kuma_test.go @@ -10,8 +10,6 @@ import ( "github.com/kong/kubernetes-testing-framework/pkg/clusters" "github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/kuma" - "github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/metallb" - "github.com/kong/kubernetes-testing-framework/pkg/environments" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" autoscalingv1 "k8s.io/api/autoscaling/v1" @@ -26,15 +24,9 @@ func TestDeployAllInOneDBLESSKuma(t *testing.T) { defer cancel() t.Log("building test cluster and environment") - addons := []clusters.Addon{} - addons = append(addons, metallb.New()) - - addons = append(addons, buildImageLoadAddons(t, imageLoad, kongImageLoad)...) - - addons = append(addons, kuma.New()) - - builder := setBuilderKubernetesVersion(t, - environments.NewBuilder().WithAddons(addons...), clusterVersionStr) + builder, err := getEnvironmentBuilder(ctx) + require.NoError(t, err) + builder = builder.WithAddons(kuma.New()) env, err := builder.Build(ctx) require.NoError(t, err) @@ -113,14 +105,9 @@ func TestDeployAllInOnePostgresKuma(t *testing.T) { defer cancel() t.Log("building test cluster and environment") - addons := []clusters.Addon{} - addons = append(addons, metallb.New()) - addons = append(addons, kuma.New()) - - addons = append(addons, buildImageLoadAddons(t, imageLoad, kongImageLoad)...) - - builder := setBuilderKubernetesVersion(t, - environments.NewBuilder().WithAddons(addons...), clusterVersionStr) + builder, err := getEnvironmentBuilder(ctx) + require.NoError(t, err) + builder = builder.WithAddons(kuma.New()) env, err := builder.Build(ctx) require.NoError(t, err) defer func() {