Skip to content

Commit

Permalink
test(kubernetes): fix incorrect namespace ref when generating demo YA…
Browse files Browse the repository at this point in the history
…ML (#40)

Signed-off-by: Jay Chen <[email protected]>
  • Loading branch information
jijiechen authored Jan 22, 2025
1 parent 3ab8498 commit df00f65
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
24 changes: 19 additions & 5 deletions test/kubernetes/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())

Expand Down Expand Up @@ -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
Expand Down
11 changes: 1 addition & 10 deletions test/kubernetes/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/pkg/errors"
"os"
"path/filepath"
"strings"
"time"

"github.com/kumahq/kuma/pkg/config/core"
Expand Down Expand Up @@ -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())

Expand Down

0 comments on commit df00f65

Please sign in to comment.