Skip to content

Commit f4e5a4c

Browse files
kumahq[bot]lukidzi
andauthored
test(e2e): allocate new port for ZoneIngress in different cluster (backport of #16290) (#16385)
Automatic cherry-pick of #16290 for branch release-2.12 Generated by [action](https://github.com/kumahq/kuma/actions/runs/24889901845) cherry-picked commit 5ccb167 ⚠️ ⚠️ ⚠️ Conflicts happened when cherry-picking! ⚠️ ⚠️ ⚠️ ``` On branch release-2.12 Your branch is up to date with 'origin/release-2.12'. You are currently cherry-picking commit 5ccb167. (fix conflicts and run "git cherry-pick --continue") (use "git cherry-pick --skip" to skip this patch) (use "git cherry-pick --abort" to cancel the cherry-pick operation) Changes to be committed: modified: test/e2e_env/multizone/connectivity/available_services.go Unmerged paths: (use "git add <file>..." to mark resolution) both modified: test/framework/setup.go ``` > Changelog: skip --------- Signed-off-by: Lukasz Dziedziak <lukidzi@gmail.com> Co-authored-by: Lukasz Dziedziak <lukidzi@gmail.com>
1 parent 2bbbed0 commit f4e5a4c

2 files changed

Lines changed: 33 additions & 23 deletions

File tree

test/e2e_env/multizone/connectivity/available_services.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func AvailableServices() {
2222
meshName := "available-services"
2323

2424
var statefulCluster *UniversalCluster
25+
var ingress1Port, ingress2Port int
2526

2627
BeforeAll(func() {
2728
Expect(NewClusterSetup().
@@ -35,6 +36,8 @@ func AvailableServices() {
3536
Setup(multizone.UniZone1)
3637
Expect(err).ToNot(HaveOccurred())
3738

39+
ingress1Port = AllocateIngressPort()
40+
ingress2Port = AllocateIngressPort()
3841
statefulCluster = NewUniversalCluster(NewTestingT(), statefulClusterName, Silent)
3942
Expect(postgres.Install(statefulClusterName)(statefulCluster)).To(Succeed())
4043
err = NewClusterSetup().
@@ -44,8 +47,8 @@ func AvailableServices() {
4447
WithPostgres(postgres.From(statefulCluster, statefulClusterName).GetEnvVars()),
4548
WithEnv("KUMA_METRICS_DATAPLANE_IDLE_TIMEOUT", "10s"),
4649
)).
47-
Install(MultipleIngressUniversal(UniversalZoneIngressPort, multizone.Global.GetKuma().GenerateZoneIngressToken)).
48-
Install(MultipleIngressUniversal(UniversalZoneIngressPort+1, multizone.Global.GetKuma().GenerateZoneIngressToken)).
50+
Install(MultipleIngressUniversal(ingress1Port, fmt.Sprintf("%s-%d", AppIngress, ingress1Port), multizone.Global.GetKuma().GenerateZoneIngressToken)).
51+
Install(MultipleIngressUniversal(ingress2Port, fmt.Sprintf("%s-%d", AppIngress, ingress2Port), multizone.Global.GetKuma().GenerateZoneIngressToken)).
4952
Install(TestServerUniversal("test-server", meshName, WithArgs([]string{"echo", "--instance", "uni-test-server"}))).
5053
Setup(statefulCluster)
5154
Expect(err).ToNot(HaveOccurred())
@@ -81,19 +84,19 @@ func AvailableServices() {
8184
kumactl := statefulCluster.GetKumactlOptions()
8285

8386
Consistently(func(g Gomega) {
84-
ingress := getIngress(g, kumactl, UniversalZoneIngressPort)
87+
ingress := getIngress(g, kumactl, ingress1Port)
8588
g.Expect(ingress.GetAvailableServices()).To(HaveLen(1))
8689
}).Should(Succeed())
8790

8891
Consistently(func(g Gomega) {
89-
ingress := getIngress(g, kumactl, UniversalZoneIngressPort+1)
92+
ingress := getIngress(g, kumactl, ingress2Port)
9093
g.Expect(ingress.GetAvailableServices()).To(HaveLen(1))
9194
}).Should(Succeed())
9295

9396
// Kill ingress
9497
Expect(statefulCluster.GetApp(AppModeCP).KillMainApp()).To(Succeed())
9598
// Kill CP
96-
Expect(statefulCluster.DeleteApp(fmt.Sprintf("%s-%d", AppIngress, UniversalZoneIngressPort))).To(Succeed())
99+
Expect(statefulCluster.DeleteApp(fmt.Sprintf("%s-%d", AppIngress, ingress1Port))).To(Succeed())
97100
// Bring back CP
98101
Expect(statefulCluster.GetApp(AppModeCP).StartMainApp()).To(Succeed())
99102
// Kill app
@@ -103,12 +106,12 @@ func AvailableServices() {
103106
}).Should(Succeed())
104107

105108
Eventually(func(g Gomega) {
106-
ingress := getIngress(g, kumactl, UniversalZoneIngressPort+1)
109+
ingress := getIngress(g, kumactl, ingress2Port)
107110
g.Expect(ingress.GetAvailableServices()).To(BeEmpty())
108111
}, "30s", "3s").Should(Succeed())
109112

110113
Eventually(func(g Gomega) {
111-
ingress := getIngress(g, kumactl, UniversalZoneIngressPort)
114+
ingress := getIngress(g, kumactl, ingress1Port)
112115
g.Expect(ingress.GetAvailableServices()).To(BeEmpty())
113116
}, "30s", "3s").Should(Succeed())
114117
})

test/framework/setup.go

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"path/filepath"
99
"strings"
10+
"sync/atomic"
1011
"time"
1112

1213
"github.com/gruntwork-io/terratest/modules/k8s"
@@ -665,7 +666,7 @@ func universalZoneProxyRelatedResource(
665666
tokenProvider func(zone string) (string, error),
666667
dpName string,
667668
appType AppMode,
668-
resourceManifestFunc func(address string, port int) string,
669+
resourceManifestFunc func(address string) string,
669670
concurrency int,
670671
) func(cluster Cluster) error {
671672
return func(cluster Cluster) error {
@@ -696,8 +697,7 @@ func universalZoneProxyRelatedResource(
696697

697698
uniCluster.apps[dpName] = app
698699
publicAddress := app.GetIP()
699-
dpYAML := resourceManifestFunc(publicAddress, UniversalZoneIngressPort)
700-
700+
dpYAML := resourceManifestFunc(publicAddress)
701701
token, err := tokenProvider(uniCluster.name)
702702
if err != nil {
703703
return err
@@ -714,21 +714,28 @@ func universalZoneProxyRelatedResource(
714714
}
715715
}
716716

717-
func IngressUniversal(tokenProvider func(zone string) (string, error), opt ...AppDeploymentOption) InstallFunc {
718-
manifestFunc := func(address string, port int) string {
719-
return fmt.Sprintf(ZoneIngress, AppIngress, address, UniversalZoneIngressPort, port)
720-
}
717+
// ingressPortAllocator hands out unique advertised ports for universal ZoneIngress
718+
// instances so that no two ingresses share the same IP:port when running in a
719+
// Docker/k3d environment where all zones resolve to the same host address.
720+
var ingressPortAllocator atomic.Int32
721721

722-
var opts appDeploymentOptions
723-
opts.apply(opt...)
722+
func init() {
723+
ingressPortAllocator.Store(int32(UniversalZoneIngressPort) - 1)
724+
}
724725

725-
return universalZoneProxyRelatedResource(tokenProvider, AppIngress, AppIngress, manifestFunc, opts.concurrency)
726+
// AllocateIngressPort returns the next unique advertised port for a universal
727+
// ZoneIngress. It is safe to call from multiple goroutines.
728+
func AllocateIngressPort() int {
729+
return int(ingressPortAllocator.Add(1))
730+
}
731+
732+
func IngressUniversal(tokenProvider func(zone string) (string, error), opt ...AppDeploymentOption) InstallFunc {
733+
return MultipleIngressUniversal(AllocateIngressPort(), AppIngress, tokenProvider, opt...)
726734
}
727735

728-
func MultipleIngressUniversal(advertisedPort int, tokenProvider func(zone string) (string, error), opt ...AppDeploymentOption) InstallFunc {
729-
name := fmt.Sprintf("%s-%d", AppIngress, advertisedPort)
730-
manifestFunc := func(address string, port int) string {
731-
return fmt.Sprintf(ZoneIngress, name, address, advertisedPort, port)
736+
func MultipleIngressUniversal(advertisedPort int, name string, tokenProvider func(zone string) (string, error), opt ...AppDeploymentOption) InstallFunc {
737+
manifestFunc := func(address string) string {
738+
return fmt.Sprintf(ZoneIngress, name, address, advertisedPort, advertisedPort)
732739
}
733740

734741
var opts appDeploymentOptions
@@ -738,8 +745,8 @@ func MultipleIngressUniversal(advertisedPort int, tokenProvider func(zone string
738745
}
739746

740747
func EgressUniversal(tokenProvider func(zone string) (string, error), opt ...AppDeploymentOption) InstallFunc {
741-
manifestFunc := func(_ string, port int) string {
742-
return fmt.Sprintf(ZoneEgress, port)
748+
manifestFunc := func(_ string) string {
749+
return fmt.Sprintf(ZoneEgress, UniversalZoneIngressPort)
743750
}
744751

745752
var opts appDeploymentOptions

0 commit comments

Comments
 (0)