From df00f65f66f2e475f6a444c2db08c8d6471301f6 Mon Sep 17 00:00:00 2001 From: Jay Jijie Chen <1180092+jijiechen@users.noreply.github.com> Date: Wed, 22 Jan 2025 15:27:47 +0800 Subject: [PATCH] test(kubernetes): fix incorrect namespace ref when generating demo YAML (#40) Signed-off-by: Jay Chen <1180092+jijiechen@users.noreply.github.com> --- test/kubernetes/install_test.go | 24 +++++++++++++++++++----- test/kubernetes/upgrade_test.go | 11 +---------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/test/kubernetes/install_test.go b/test/kubernetes/install_test.go index a89115b..44f3b4e 100644 --- a/test/kubernetes/install_test.go +++ b/test/kubernetes/install_test.go @@ -6,6 +6,7 @@ import ( "github.com/gruntwork-io/terratest/modules/retry" "github.com/gruntwork-io/terratest/modules/testing" "github.com/kumahq/kuma/test/framework/deployments/kic" + "github.com/kumahq/kuma/test/framework/kumactl" "github.com/pkg/errors" "os" "path/filepath" @@ -81,11 +82,8 @@ spec: It("should support running the demo app with builtin gateway", func() { By("install the demo app and wait for it to become ready") - kumactl := NewKumactlOptionsE2E(cluster.GetTesting(), cluster.Name(), true) - demoAppYAML, err := kumactl.RunKumactlAndGetOutput("install", "demo", - "--namespace", TestNamespace, - "--system-namespace", Config.KumaNamespace) - + kumactlOpts := NewKumactlOptionsE2E(cluster.GetTesting(), cluster.Name(), true) + demoAppYAML, err := generateDemoAppYAML(kumactlOpts, TestNamespace, Config.KumaNamespace) Expect(err).ToNot(HaveOccurred()) Expect(cluster.Install(YamlK8s(demoAppYAML))).To(Succeed()) @@ -183,6 +181,22 @@ spec: ) } +func generateDemoAppYAML(kumactlOpts *kumactl.KumactlOptions, appNamespace, kumaNamespace string) (string, error) { + demoAppYAML, err := kumactlOpts.RunKumactlAndGetOutput("install", "demo", + "--namespace", appNamespace, + "--system-namespace", kumaNamespace) + if err != nil { + return "", err + } + + // in 2.8.x and older versions, the YAML generated from "kumactl install demo" has a bug in their MeshHTTPRoute resources + // causing the kuma.io/service tag fail to support changing app namespace + demoAppYAML = strings.Replace(demoAppYAML, + "demo-app-gateway_kuma-demo_svc", + fmt.Sprintf("demo-app-gateway_%s_svc", appNamespace), -1) + return demoAppYAML, nil +} + func meshTrafficPermission(namespace string) string { mtp := ` apiVersion: kuma.io/v1alpha1 diff --git a/test/kubernetes/upgrade_test.go b/test/kubernetes/upgrade_test.go index 23d049d..a705387 100644 --- a/test/kubernetes/upgrade_test.go +++ b/test/kubernetes/upgrade_test.go @@ -10,7 +10,6 @@ import ( "github.com/pkg/errors" "os" "path/filepath" - "strings" "time" "github.com/kumahq/kuma/pkg/config/core" @@ -71,15 +70,7 @@ func Upgrade() { It("should run the demo app with mTLS and gateways", func() { By("install the demo app and wait for it to become ready") - demoAppYAML, err := cluster.GetKumactlOptions().RunKumactlAndGetOutput("install", "demo", - "--namespace", TestNamespace, - "--system-namespace", Config.KumaNamespace) - // in 2.8.x and older versions, the YAML generated from "kumactl install demo" has a bug in their MeshHTTPRoute resources - // causing the kuma.io/service tag fail to support changing app namespace - demoAppYAML = strings.Replace(demoAppYAML, - "demo-app-gateway_kuma-demo_svc", - fmt.Sprintf("demo-app-gateway_%s_svc", TestNamespace), -1) - + demoAppYAML, err := generateDemoAppYAML(cluster.GetKumactlOptions(), TestNamespace, Config.KumaNamespace) Expect(err).ToNot(HaveOccurred()) Expect(cluster.Install(YamlK8s(demoAppYAML))).To(Succeed())