Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1587,7 +1587,7 @@ In this setup there is an external control plane cluster (`cluster1`) and a remo
kubectl wait --context "${CTX_CLUSTER1}" --for=condition=Ready istios/external-istiod --timeout=3m
```

8. Create the Istio resources to route traffic from the ingress gateway to the external control plane.
8. Create the `Gateway` and `VirtualService` resources to route traffic from the ingress gateway to the external control plane.

```sh
kubectl apply --context "${CTX_CLUSTER1}" -f - <<EOF
Expand Down
56 changes: 51 additions & 5 deletions tests/e2e/multicluster/common.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build e2e

// Copyright Istio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -16,21 +18,65 @@ package multicluster

import (
"fmt"
"strings"
"text/template"
"time"

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

// ClusterDeployment represents a cluster along with its sample app version.
type ClusterDeployment struct {
Kubectl kubectl.Kubectl
AppVersion string
}

// deploySampleApp deploys the sample apps (helloworld and sleep) in the given cluster.
func deploySampleApp(k kubectl.Kubectl, ns string, istioVersion istioversion.VersionInfo, appVersion string) {
helloWorldYAML := common.GetSampleYAML(istioVersion, "helloworld")
Expect(k.WithNamespace(ns).ApplyWithLabels(helloWorldYAML, "service=helloworld")).To(Succeed(), "Sample service deploy failed on Cluster")
Expect(k.WithNamespace(ns).ApplyWithLabels(helloWorldYAML, "version="+appVersion)).To(Succeed(), "Sample service deploy failed on Cluster")

sleepYAML := common.GetSampleYAML(istioVersion, "sleep")
Expect(k.WithNamespace(ns).Apply(sleepYAML)).To(Succeed(), "Sample sleep deploy failed on Cluster")
}

// deploySampleAppToClusters deploys the sample app to all provided clusters.
func deploySampleAppToClusters(ns string, istioVersion istioversion.VersionInfo, clusters []ClusterDeployment) {
for _, cd := range clusters {
deploySampleApp(cd.Kubectl, ns, istioVersion, cd.AppVersion)
}
}

// verifyResponsesAreReceivedFromBothClusters checks that when the sleep pod in the sample namespace
// sends a request to the helloworld service, it receives responses from both v1 and v2 versions,
// which are deployed in different clusters
func verifyResponsesAreReceivedFromBothClusters(k kubectl.Kubectl, clusterName string) {
expectedVersions := []string{"v1", "v2"}
// sends a request to the helloworld service, it receives responses from expectedVersions,
// which can be either "v1" or "v2" on on different clusters.
func verifyResponsesAreReceivedFromExpectedVersions(k kubectl.Kubectl, expectedVersions ...string) {
if len(expectedVersions) == 0 {
expectedVersions = []string{"v1", "v2"}
}
for _, v := range expectedVersions {
Eventually(k.WithNamespace("sample").Exec, 10*time.Second, 10*time.Millisecond).
WithArguments("deploy/sleep", "sleep", "curl -sS helloworld.sample:5000/hello").
Should(ContainSubstring(fmt.Sprintf("Hello version: %s", v)),
fmt.Sprintf("sleep pod in %s did not receive any response from %s", clusterName, v))
fmt.Sprintf("sleep pod in %s did not receive any response from %s", k.ClusterName, v))
}
}

// genTemplate takes a YAML string with go template annotations and a structure
// that fills in those annotations and outputs a YAML string with that structure
// applied to the template.
// Example: version: {{ .Version }} | {Version: "1.2.3"} --> version: Version: "1.2.3"
// Any errors will fail the test.
func genTemplate(manifestTmpl string, values any) string {
tmpl, err := template.New("manifest-template").Parse(manifestTmpl)
Expect(err).ToNot(HaveOccurred(),
"template is likely either malformed YAML or the values do not match what is expected")

var b strings.Builder
Expect(tmpl.Execute(&b, values)).To(Succeed())
return b.String()
}
Loading