Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(e2e): mesh service connectivity #10571

Merged
merged 2 commits into from
Jun 20, 2024
Merged
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
186 changes: 186 additions & 0 deletions test/e2e_env/multizone/meshservice/connectivity.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
package meshservice

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

. "github.com/kumahq/kuma/test/framework"
"github.com/kumahq/kuma/test/framework/client"
"github.com/kumahq/kuma/test/framework/deployments/democlient"
"github.com/kumahq/kuma/test/framework/deployments/testserver"
"github.com/kumahq/kuma/test/framework/envs/multizone"
)

func Connectivity() {
namespace := "msconnectivity"
meshName := "msconnectivity"

BeforeAll(func() {
Expect(NewClusterSetup().
Install(MTLSMeshUniversal(meshName)).
Install(MeshTrafficPermissionAllowAllUniversal(meshName)).
Install(YamlUniversal(`
type: HostnameGenerator
name: kube-msconnectivity
spec:
template: '{{ .DisplayName }}.{{ .Namespace }}.{{ .Zone }}.k8s.msconnectivity'
selector:
meshService:
matchLabels:
kuma.io/origin: global
kuma.io/env: kubernetes
`)).
Install(YamlUniversal(`
type: HostnameGenerator
name: uni-msconnectivity
spec:
template: '{{ .DisplayName }}.{{ .Zone }}.universal.msconnectivity'
selector:
meshService:
matchLabels:
kuma.io/origin: global
kuma.io/env: universal
`)).
Setup(multizone.Global)).To(Succeed())
Expect(WaitForMesh(meshName, multizone.Zones())).To(Succeed())

kubeServiceYAML := `
apiVersion: kuma.io/v1alpha1
kind: MeshService
metadata:
name: test-server
namespace: msconnectivity
labels:
kuma.io/origin: zone
kuma.io/mesh: msconnectivity
kuma.io/env: kubernetes
spec:
selector:
dataplaneTags:
app: test-server
k8s.kuma.io/namespace: msconnectivity
ports:
- port: 80
targetPort: 80
appProtocol: http
`

err := NewClusterSetup().
Install(NamespaceWithSidecarInjection(namespace)).
Install(testserver.Install(
testserver.WithNamespace(namespace),
testserver.WithMesh(meshName),
testserver.WithEchoArgs("echo", "--instance", "kube-test-server-1"),
)).
Install(YamlK8s(kubeServiceYAML)).
Install(democlient.Install(democlient.WithNamespace(namespace), democlient.WithMesh(meshName))).
Setup(multizone.KubeZone1)
Expect(err).ToNot(HaveOccurred())

err = NewClusterSetup().
Install(NamespaceWithSidecarInjection(namespace)).
Install(testserver.Install(
testserver.WithNamespace(namespace),
testserver.WithMesh(meshName),
testserver.WithEchoArgs("echo", "--instance", "kube-test-server-2"),
)).
Install(YamlK8s(kubeServiceYAML)).
Setup(multizone.KubeZone2)
Expect(err).ToNot(HaveOccurred())

uniServiceYAML := `
type: MeshService
name: test-server
mesh: msconnectivity
labels:
kuma.io/origin: zone
kuma.io/env: universal
spec:
selector:
dataplaneTags:
kuma.io/service: test-server
ports:
- port: 80
targetPort: 80
appProtocol: http
`

err = NewClusterSetup().
Install(DemoClientUniversal("uni-demo-client", meshName, WithTransparentProxy(true))).
Setup(multizone.UniZone1)
Expect(err).ToNot(HaveOccurred())

err = NewClusterSetup().
Install(TestServerUniversal("test-server", meshName, WithArgs([]string{"echo", "--instance", "uni-test-server"}))).
Install(YamlUniversal(uniServiceYAML)).
Setup(multizone.UniZone2)
Expect(err).ToNot(HaveOccurred())
})

AfterEachFailure(func() {
DebugUniversal(multizone.Global, meshName)
DebugUniversal(multizone.UniZone1, meshName)
DebugUniversal(multizone.UniZone2, meshName)
DebugKube(multizone.KubeZone1, meshName, namespace)
DebugKube(multizone.KubeZone2, meshName, namespace)
})

E2EAfterAll(func() {
Expect(multizone.KubeZone1.TriggerDeleteNamespace(namespace)).To(Succeed())
Expect(multizone.KubeZone2.TriggerDeleteNamespace(namespace)).To(Succeed())
Expect(multizone.UniZone1.DeleteMeshApps(meshName)).To(Succeed())
Expect(multizone.UniZone2.DeleteMeshApps(meshName)).To(Succeed())
Expect(multizone.Global.DeleteMesh(meshName)).To(Succeed())
})

type testCase struct {
address string
expectedInstance string
}

DescribeTable("client from Kubernetes",
func(given testCase) {
Eventually(func(g Gomega) {
response, err := client.CollectEchoResponse(multizone.KubeZone1, "demo-client", given.address,
client.FromKubernetesPod(meshName, "demo-client"),
)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(response.Instance).To(Equal(given.expectedInstance))
}, "30s", "1s").Should(Succeed())
},
Entry("should access service in the same Kubernetes cluster", testCase{
address: "http://test-server.msconnectivity.svc.cluster.local:80",
expectedInstance: "kube-test-server-1",
}),
Entry("should access service in another Kubernetes cluster", testCase{
address: "http://test-server.msconnectivity.kuma-2.k8s.msconnectivity:80",
expectedInstance: "kube-test-server-2",
}),
Entry("should access service in another Universal cluster", testCase{
address: "http://test-server.kuma-5.universal.msconnectivity:80",
expectedInstance: "uni-test-server",
}),
)

DescribeTable("client from Universal",
func(given testCase) {
Eventually(func(g Gomega) {
response, err := client.CollectEchoResponse(multizone.UniZone1, "uni-demo-client", given.address)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(response.Instance).To(Equal(given.expectedInstance))
}, "30s", "1s").Should(Succeed())
},
Entry("should access service in another Kubernetes cluster 1", testCase{
address: "http://test-server.msconnectivity.kuma-1.k8s.msconnectivity:80",
expectedInstance: "kube-test-server-1",
}),
Entry("should access service in another Kubernetes cluster 2", testCase{
address: "http://test-server.msconnectivity.kuma-2.k8s.msconnectivity:80",
expectedInstance: "kube-test-server-2",
}),
Entry("should access service in another Universal cluster", testCase{
address: "http://test-server.kuma-5.universal.msconnectivity:80",
expectedInstance: "uni-test-server",
}),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ import (
"github.com/kumahq/kuma/pkg/core/resources/model/rest"
"github.com/kumahq/kuma/pkg/kds/hash"
. "github.com/kumahq/kuma/test/framework"
"github.com/kumahq/kuma/test/framework/client"
"github.com/kumahq/kuma/test/framework/deployments/democlient"
"github.com/kumahq/kuma/test/framework/envs/multizone"
)

func MeshService() {
func Sync() {
meshName := "meshservice"
namespace := "meshservice"

Expand Down Expand Up @@ -152,58 +151,6 @@ spec:
}, "30s", "1s").Should(Succeed())
})

It("should connect cross-zone using MeshService from universal cluster", func() {
err := multizone.UniZone2.Install(YamlUniversal(`
type: HostnameGenerator
mesh: meshservice
name: basic-uni
labels:
kuma.io/origin: zone
spec:
template: '{{ label "kuma.io/display-name" }}.{{ label "kuma.io/zone" }}.ms.mesh'
selector:
meshService:
matchLabels:
kuma.io/display-name: backend
kuma.io/origin: global
`))
Expect(err).ToNot(HaveOccurred())

Eventually(func(g Gomega) {
response, err := client.CollectEchoResponse(multizone.UniZone2, "uni-demo-client", "backend.kuma-4.ms.mesh:80")
g.Expect(err).ToNot(HaveOccurred())
g.Expect(response.Instance).To(Equal("echo-v1"))
}, "30s", "1s").Should(Succeed())
})

It("should connect cross-zone using MeshService from kubernetes cluster", func() {
err := multizone.KubeZone2.Install(YamlK8s(`
apiVersion: kuma.io/v1alpha1
kind: HostnameGenerator
metadata:
name: basic-kube
labels:
kuma.io/mesh: meshservice
kuma.io/origin: zone
spec:
template: '{{ label "kuma.io/display-name" }}.{{ label "kuma.io/zone" }}.ms.mesh'
selector:
meshService:
matchLabels:
kuma.io/display-name: backend
kuma.io/origin: global
`))
Expect(err).ToNot(HaveOccurred())

Eventually(func(g Gomega) {
response, err := client.CollectEchoResponse(multizone.KubeZone2, "demo-client", "backend.kuma-4.ms.mesh:80",
client.FromKubernetesPod(meshName, "demo-client"),
)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(response.Instance).To(Equal("echo-v1"))
}, "30s", "1s").Should(Succeed())
})

It("should sync MeshServices with the same name in different zones without conflicts", func() {
// MeshServices are synced to global zone without conflict
Eventually(func(g Gomega) {
Expand Down
3 changes: 2 additions & 1 deletion test/e2e_env/multizone/multizone_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ var (
_ = Describe("Advanced LocalityAwareness with MeshLoadBalancingStrategy with Gateway", localityawarelb.LocalityAwareLBGateway, Ordered)
_ = Describe("Advanced LocalityAwareness with MeshLoadBalancingStrategy and Enabled Egress", localityawarelb.LocalityAwareLBEgress, Ordered)
_ = Describe("Defaults", defaults.Defaults, Ordered)
_ = Describe("MeshService", meshservice.MeshService, Ordered)
_ = Describe("MeshService Sync", meshservice.Sync, Ordered)
_ = Describe("MeshService Connectivity", meshservice.Connectivity, Ordered)
_ = Describe("Available services", connectivity.AvailableServices, Ordered)
)
Loading