Skip to content

Commit

Permalink
Moving Helloworld from multicluster test to sampleapps
Browse files Browse the repository at this point in the history
  • Loading branch information
fjglira committed Nov 20, 2024
1 parent 1e578fa commit 5a1685f
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 51 deletions.
2 changes: 1 addition & 1 deletion tests/e2e/controlplane/control_plane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ spec:
IstioVersion: version,
Clusters: []kubectl.Kubectl{k},
}
Expect(sampleapps.DeploySampleApp(cfg)).To(Succeed(), "Error deploying sample pod")
Expect(sampleapps.DeploySamplePod(cfg)).To(Succeed(), "Error deploying sample pod")
Success("sample deployed")
})

Expand Down
51 changes: 19 additions & 32 deletions tests/e2e/multicluster/multicluster_multiprimary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
"github.com/istio-ecosystem/sail-operator/tests/e2e/util/common"
. "github.com/istio-ecosystem/sail-operator/tests/e2e/util/gomega"
"github.com/istio-ecosystem/sail-operator/tests/e2e/util/istioctl"
"github.com/istio-ecosystem/sail-operator/tests/e2e/util/kubectl"
"github.com/istio-ecosystem/sail-operator/tests/e2e/util/sampleapps"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -198,16 +200,30 @@ spec:

When("sample apps are deployed in both clusters", func() {
BeforeAll(func(ctx SpecContext) {
// Create the namespace
Expect(k1.CreateNamespace("sample")).To(Succeed(), "Namespace failed to be created")
Expect(k2.CreateNamespace("sample")).To(Succeed(), "Namespace failed to be created")

// Label the sample namespace
Expect(k1.Patch("namespace", "sample", "merge", `{"metadata":{"labels":{"istio-injection":"enabled"}}}`)).
To(Succeed(), "Error patching sample namespace")
Expect(k2.Patch("namespace", "sample", "merge", `{"metadata":{"labels":{"istio-injection":"enabled"}}}`)).
To(Succeed(), "Error patching sample namespace")

// Deploy the sample app in both clusters
deploySampleApp("sample", version)
sampleapps.DeployHelloWorld(sampleapps.DeployConfig{
Namespace: "sample",
IstioVersion: version,
Clusters: []kubectl.Kubectl{k1, k2},
})
Success("Sample app is deployed in both clusters")
})

It("updates the pods status to Ready", func(ctx SpecContext) {
samplePodsCluster1 := &corev1.PodList{}

Expect(clPrimary.List(ctx, samplePodsCluster1, client.InNamespace("sample"))).To(Succeed())
Expect(samplePodsCluster1.Items).ToNot(BeEmpty(), "No pods found in bookinfo namespace")
Expect(samplePodsCluster1.Items).ToNot(BeEmpty(), "No pods found in sample namespace")

for _, pod := range samplePodsCluster1.Items {
Eventually(common.GetObject).
Expand All @@ -217,7 +233,7 @@ spec:

samplePodsCluster2 := &corev1.PodList{}
Expect(clRemote.List(ctx, samplePodsCluster2, client.InNamespace("sample"))).To(Succeed())
Expect(samplePodsCluster2.Items).ToNot(BeEmpty(), "No pods found in bookinfo namespace")
Expect(samplePodsCluster2.Items).ToNot(BeEmpty(), "No pods found in sample namespace")

for _, pod := range samplePodsCluster2.Items {
Eventually(common.GetObject).
Expand Down Expand Up @@ -290,32 +306,3 @@ spec:
Expect(k2.WaitNamespaceDeleted(namespace)).To(Succeed())
})
})

// deploySampleApp deploys the sample app in the given cluster
func deploySampleApp(ns string, istioVersion supportedversion.VersionInfo) {
// Create the namespace
Expect(k1.CreateNamespace(ns)).To(Succeed(), "Namespace failed to be created")
Expect(k2.CreateNamespace(ns)).To(Succeed(), "Namespace failed to be created")

// Label the namespace
Expect(k1.Patch("namespace", ns, "merge", `{"metadata":{"labels":{"istio-injection":"enabled"}}}`)).
To(Succeed(), "Error patching sample namespace")
Expect(k2.Patch("namespace", ns, "merge", `{"metadata":{"labels":{"istio-injection":"enabled"}}}`)).
To(Succeed(), "Error patching sample namespace")

version := istioVersion.Version.String()
// Deploy the sample app from upstream URL in both clusters
if istioVersion.Name == "latest" {
version = "master"
}
helloWorldURL := fmt.Sprintf("https://raw.githubusercontent.com/istio/istio/%s/samples/helloworld/helloworld.yaml", version)
Expect(k1.WithNamespace(ns).ApplyWithLabels(helloWorldURL, "service=helloworld")).To(Succeed(), "Sample service deploy failed on Cluster #1")
Expect(k2.WithNamespace(ns).ApplyWithLabels(helloWorldURL, "service=helloworld")).To(Succeed(), "Sample service deploy failed on Cluster #2")

Expect(k1.WithNamespace(ns).ApplyWithLabels(helloWorldURL, "version=v1")).To(Succeed(), "Sample service deploy failed on Cluster #1")
Expect(k2.WithNamespace(ns).ApplyWithLabels(helloWorldURL, "version=v2")).To(Succeed(), "Sample service deploy failed on Cluster #2")

sleepURL := fmt.Sprintf("https://raw.githubusercontent.com/istio/istio/%s/samples/sleep/sleep.yaml", version)
Expect(k1.WithNamespace(ns).Apply(sleepURL)).To(Succeed(), "Sample sleep deploy failed on Cluster #1")
Expect(k2.WithNamespace(ns).Apply(sleepURL)).To(Succeed(), "Sample sleep deploy failed on Cluster #2")
}
22 changes: 19 additions & 3 deletions tests/e2e/multicluster/multicluster_primaryremote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
"github.com/istio-ecosystem/sail-operator/tests/e2e/util/common"
. "github.com/istio-ecosystem/sail-operator/tests/e2e/util/gomega"
"github.com/istio-ecosystem/sail-operator/tests/e2e/util/istioctl"
"github.com/istio-ecosystem/sail-operator/tests/e2e/util/kubectl"
"github.com/istio-ecosystem/sail-operator/tests/e2e/util/sampleapps"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -245,16 +247,30 @@ spec:

When("sample apps are deployed in both clusters", func() {
BeforeAll(func(ctx SpecContext) {
// Create the namespace
Expect(k1.CreateNamespace("sample")).To(Succeed(), "Namespace failed to be created")
Expect(k2.CreateNamespace("sample")).To(Succeed(), "Namespace failed to be created")

// Label the sample namespace
Expect(k1.Patch("namespace", "sample", "merge", `{"metadata":{"labels":{"istio-injection":"enabled"}}}`)).
To(Succeed(), "Error patching sample namespace")
Expect(k2.Patch("namespace", "sample", "merge", `{"metadata":{"labels":{"istio-injection":"enabled"}}}`)).
To(Succeed(), "Error patching sample namespace")

// Deploy the sample app in both clusters
deploySampleApp("sample", v)
sampleapps.DeployHelloWorld(sampleapps.DeployConfig{
Namespace: "sample",
IstioVersion: v,
Clusters: []kubectl.Kubectl{k1, k2},
})
Success("Sample app is deployed in both clusters")
})

It("updates the pods status to Ready", func(ctx SpecContext) {
samplePodsPrimary := &corev1.PodList{}

Expect(clPrimary.List(ctx, samplePodsPrimary, client.InNamespace("sample"))).To(Succeed())
Expect(samplePodsPrimary.Items).ToNot(BeEmpty(), "No pods found in bookinfo namespace")
Expect(samplePodsPrimary.Items).ToNot(BeEmpty(), "No pods found in sample namespace")

for _, pod := range samplePodsPrimary.Items {
Eventually(common.GetObject).
Expand All @@ -264,7 +280,7 @@ spec:

samplePodsRemote := &corev1.PodList{}
Expect(clRemote.List(ctx, samplePodsRemote, client.InNamespace("sample"))).To(Succeed())
Expect(samplePodsRemote.Items).ToNot(BeEmpty(), "No pods found in bookinfo namespace")
Expect(samplePodsRemote.Items).ToNot(BeEmpty(), "No pods found in sample namespace")

for _, pod := range samplePodsRemote.Items {
Eventually(common.GetObject).
Expand Down
69 changes: 54 additions & 15 deletions tests/e2e/util/sampleapps/sampleapps.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,75 @@ import (

"github.com/istio-ecosystem/sail-operator/pkg/test/util/supportedversion"
"github.com/istio-ecosystem/sail-operator/tests/e2e/util/kubectl"
. "github.com/onsi/gomega"
)

// Centralize here the installation and uninstallation of sample apps: hello-world, bookinfo, sleep
// TODO: Pull the yaml files from the repo and add the possibility to modify the images
// Centralize here the installation and uninstallation of sample apps: hello-world, sleep, etc
// TODO: Set a way to install the apps with custom images

const (
helloWorldURL = "https://raw.githubusercontent.com/istio/istio/%s/samples/helloworld/helloworld.yaml"
helloWorldBaseURL = "https://raw.githubusercontent.com/istio/istio/%s/samples/helloworld/helloworld.yaml"
sleepBaseURL = "https://raw.githubusercontent.com/istio/istio/%s/samples/sleep/sleep.yaml"
)

type DeployConfig struct {
Namespace string
IstioVersion supportedversion.VersionInfo
Clusters []kubectl.Kubectl
CustomRegistry string
Namespace string
IstioVersion supportedversion.VersionInfo
Clusters []kubectl.Kubectl
}

func setIstioVersion(version supportedversion.VersionInfo) string {
v := version.Version.String()
if version.Name == "latest" {
v = "master"
}

return v
}

// DeploySampleApp deploys helloworld pod without services in the given clusters. This is used only for testing sidecar injection.
func DeploySampleApp(cfg DeployConfig) error {
func DeploySamplePod(cfg DeployConfig) error {
for _, cluster := range cfg.Clusters {
// I need to save cfg.IstioVersion.Version as string to use it in the URL
version := cfg.IstioVersion.Version.String()
if cfg.IstioVersion.Name == "latest" {
version = "master"
}

err := cluster.WithNamespace(cfg.Namespace).ApplyWithLabels(fmt.Sprintf(helloWorldURL, version), "version=v1")
err := cluster.WithNamespace(cfg.Namespace).ApplyWithLabels(fmt.Sprintf(helloWorldBaseURL, setIstioVersion(cfg.IstioVersion)), "version=v1")
if err != nil {
return err
}
}

return nil
}

// DeployHelloWorld deploys helloworld app in the given clusters.
// Intended to be used in multicluster topology tests.
func DeployHelloWorld(cfg DeployConfig) {
helloWorldURL := fmt.Sprintf(helloWorldBaseURL, setIstioVersion(cfg.IstioVersion))
sleepURL := fmt.Sprintf(sleepBaseURL, setIstioVersion(cfg.IstioVersion))

// On Cluster 0, create a service for the helloworld app v1
Expect(cfg.Clusters[0].
WithNamespace(cfg.Namespace).
ApplyWithLabels(helloWorldURL, "service=helloworld")).
To(Succeed(), "Failed to deploy helloworld service")
Expect(cfg.Clusters[0].
WithNamespace(cfg.Namespace).
ApplyWithLabels(helloWorldURL, "version=v1")).
To(Succeed(), "Failed to deploy helloworld service")
Expect(cfg.Clusters[0].
WithNamespace(cfg.Namespace).
Apply(sleepURL)).
To(Succeed(), "Failed to deploy sleep service")

// On Cluster 1, create a service for the helloworld app v2
Expect(cfg.Clusters[1].
WithNamespace(cfg.Namespace).
ApplyWithLabels(helloWorldURL, "service=helloworld")).
To(Succeed(), "Failed to deploy helloworld service")
Expect(cfg.Clusters[1].
WithNamespace(cfg.Namespace).
ApplyWithLabels(helloWorldURL, "version=v2")).
To(Succeed(), "Failed to deploy helloworld service")
Expect(cfg.Clusters[1].
WithNamespace(cfg.Namespace).
Apply(sleepURL)).
To(Succeed(), "Failed to deploy sleep service")
}

0 comments on commit 5a1685f

Please sign in to comment.