Skip to content

Commit

Permalink
fixed flake with peering test
Browse files Browse the repository at this point in the history
- added cluster creation in parallel to speed up test
  • Loading branch information
wilkermichael committed Dec 7, 2023
1 parent e95d662 commit 757e724
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 118 deletions.
86 changes: 52 additions & 34 deletions acceptance/tests/peering/peering_connect_namespaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"
"strconv"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -116,50 +117,67 @@ func TestPeering_ConnectNamespaces(t *testing.T) {
"dns.enableRedirection": strconv.FormatBool(cfg.EnableTransparentProxy),
}

staticServerPeerHelmValues := map[string]string{
"global.datacenter": staticServerPeer,
}
var wg sync.WaitGroup
releaseName := helpers.RandomName()

if !cfg.UseKind {
staticServerPeerHelmValues["server.replicas"] = "3"
}
var staticServerPeerCluster *consul.HelmCluster
wg.Add(1)
go func() {
staticServerPeerHelmValues := map[string]string{
"global.datacenter": staticServerPeer,
}

// On Kind, there are no load balancers but since all clusters
// share the same node network (docker bridge), we can use
// a NodePort service so that we can access node(s) in a different Kind cluster.
if cfg.UseKind {
staticServerPeerHelmValues["server.exposeGossipAndRPCPorts"] = "true"
staticServerPeerHelmValues["meshGateway.service.type"] = "NodePort"
staticServerPeerHelmValues["meshGateway.service.nodePort"] = "30100"
}
if !cfg.UseKind {
staticServerPeerHelmValues["server.replicas"] = "3"
}

releaseName := helpers.RandomName()
// On Kind, there are no load balancers but since all clusters
// share the same node network (docker bridge), we can use
// a NodePort service so that we can access node(s) in a different Kind cluster.
if cfg.UseKind {
staticServerPeerHelmValues["server.exposeGossipAndRPCPorts"] = "true"
staticServerPeerHelmValues["meshGateway.service.type"] = "NodePort"
staticServerPeerHelmValues["meshGateway.service.nodePort"] = "30100"
}

helpers.MergeMaps(staticServerPeerHelmValues, commonHelmValues)
helpers.MergeMaps(staticServerPeerHelmValues, commonHelmValues)

// Install the first peer where static-server will be deployed in the static-server kubernetes context.
staticServerPeerCluster := consul.NewHelmCluster(t, staticServerPeerHelmValues, staticServerPeerClusterContext, cfg, releaseName)
staticServerPeerCluster.Create(t)
// Install the first peer where static-server will be deployed in the static-server kubernetes context.
staticServerPeerCluster = consul.NewHelmCluster(t, staticServerPeerHelmValues, staticServerPeerClusterContext, cfg, releaseName)
staticServerPeerCluster.Create(t)

staticClientPeerHelmValues := map[string]string{
"global.datacenter": staticClientPeer,
}
wg.Done()
}()

if !cfg.UseKind {
staticClientPeerHelmValues["server.replicas"] = "3"
}
var staticClientPeerCluster *consul.HelmCluster
wg.Add(1)
go func() {
staticClientPeerHelmValues := map[string]string{
"global.datacenter": staticClientPeer,
}

if cfg.UseKind {
staticClientPeerHelmValues["server.exposeGossipAndRPCPorts"] = "true"
staticClientPeerHelmValues["meshGateway.service.type"] = "NodePort"
staticClientPeerHelmValues["meshGateway.service.nodePort"] = "30100"
}
if !cfg.UseKind {
staticClientPeerHelmValues["server.replicas"] = "3"
}

if cfg.UseKind {
staticClientPeerHelmValues["server.exposeGossipAndRPCPorts"] = "true"
staticClientPeerHelmValues["meshGateway.service.type"] = "NodePort"
staticClientPeerHelmValues["meshGateway.service.nodePort"] = "30100"
}

helpers.MergeMaps(staticClientPeerHelmValues, commonHelmValues)

// Install the second peer where static-client will be deployed in the static-client kubernetes context.
staticClientPeerCluster := consul.NewHelmCluster(t, staticClientPeerHelmValues, staticClientPeerClusterContext, cfg, releaseName)
staticClientPeerCluster.Create(t)

helpers.MergeMaps(staticClientPeerHelmValues, commonHelmValues)
wg.Done()
}()

// Install the second peer where static-client will be deployed in the static-client kubernetes context.
staticClientPeerCluster := consul.NewHelmCluster(t, staticClientPeerHelmValues, staticClientPeerClusterContext, cfg, releaseName)
staticClientPeerCluster.Create(t)
// Wait for the clusters to start up
logger.Log(t, "waiting for clusters to start up . . .")
wg.Wait()

// Create Mesh resource to use mesh gateways.
logger.Log(t, "creating mesh config")
Expand Down
102 changes: 60 additions & 42 deletions acceptance/tests/peering/peering_connect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"
"strconv"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -46,10 +47,10 @@ func TestPeering_Connect(t *testing.T) {
name string
ACLsEnabled bool
}{
{
"default installation",
false,
},
//{
// "default installation",
// false,
//},
{
"secure installation",
true,
Expand All @@ -61,6 +62,7 @@ func TestPeering_Connect(t *testing.T) {
staticServerPeerClusterContext := env.DefaultContext(t)
staticClientPeerClusterContext := env.Context(t, 1)

// Create Clusters starting with our first cluster
commonHelmValues := map[string]string{
"global.peering.enabled": "true",

Expand All @@ -78,53 +80,69 @@ func TestPeering_Connect(t *testing.T) {
"dns.enableRedirection": strconv.FormatBool(cfg.EnableTransparentProxy),
}

staticServerPeerHelmValues := map[string]string{
"global.datacenter": staticServerPeer,
"terminatingGateways.enabled": "true",
"terminatingGateways.gateways[0].name": "terminating-gateway",
"terminatingGateways.gateways[0].replicas": "1",
}
var wg sync.WaitGroup
releaseName := helpers.RandomName()

if !cfg.UseKind {
staticServerPeerHelmValues["server.replicas"] = "3"
}
var staticServerPeerCluster *consul.HelmCluster
wg.Add(1)
go func() {
staticServerPeerHelmValues := map[string]string{
"global.datacenter": staticServerPeer,
"terminatingGateways.enabled": "true",
"terminatingGateways.gateways[0].name": "terminating-gateway",
"terminatingGateways.gateways[0].replicas": "1",
}

// On Kind, there are no load balancers but since all clusters
// share the same node network (docker bridge), we can use
// a NodePort service so that we can access node(s) in a different Kind cluster.
if cfg.UseKind {
staticServerPeerHelmValues["server.exposeGossipAndRPCPorts"] = "true"
staticServerPeerHelmValues["meshGateway.service.type"] = "NodePort"
staticServerPeerHelmValues["meshGateway.service.nodePort"] = "30100"
}
if !cfg.UseKind {
staticServerPeerHelmValues["server.replicas"] = "3"
}

releaseName := helpers.RandomName()
// On Kind, there are no load balancers but since all clusters
// share the same node network (docker bridge), we can use
// a NodePort service so that we can access node(s) in a different Kind cluster.
if cfg.UseKind {
staticServerPeerHelmValues["server.exposeGossipAndRPCPorts"] = "true"
staticServerPeerHelmValues["meshGateway.service.type"] = "NodePort"
staticServerPeerHelmValues["meshGateway.service.nodePort"] = "30100"
}

helpers.MergeMaps(staticServerPeerHelmValues, commonHelmValues)
helpers.MergeMaps(staticServerPeerHelmValues, commonHelmValues)

// Install the first peer where static-server will be deployed in the static-server kubernetes context.
staticServerPeerCluster := consul.NewHelmCluster(t, staticServerPeerHelmValues, staticServerPeerClusterContext, cfg, releaseName)
staticServerPeerCluster.Create(t)
// Install the first peer where static-server will be deployed in the static-server kubernetes context.
staticServerPeerCluster = consul.NewHelmCluster(t, staticServerPeerHelmValues, staticServerPeerClusterContext, cfg, releaseName)
staticServerPeerCluster.Create(t)
wg.Done()
}()

staticClientPeerHelmValues := map[string]string{
"global.datacenter": staticClientPeer,
}
var staticClientPeerCluster *consul.HelmCluster
wg.Add(1)
go func() {
// Create a second cluster to be peered with
staticClientPeerHelmValues := map[string]string{
"global.datacenter": staticClientPeer,
}

if !cfg.UseKind {
staticClientPeerHelmValues["server.replicas"] = "3"
}
if !cfg.UseKind {
staticClientPeerHelmValues["server.replicas"] = "3"
}

if cfg.UseKind {
staticClientPeerHelmValues["server.exposeGossipAndRPCPorts"] = "true"
staticClientPeerHelmValues["meshGateway.service.type"] = "NodePort"
staticClientPeerHelmValues["meshGateway.service.nodePort"] = "30100"
}
if cfg.UseKind {
staticClientPeerHelmValues["server.exposeGossipAndRPCPorts"] = "true"
staticClientPeerHelmValues["meshGateway.service.type"] = "NodePort"
staticClientPeerHelmValues["meshGateway.service.nodePort"] = "30100"
}

helpers.MergeMaps(staticClientPeerHelmValues, commonHelmValues)

helpers.MergeMaps(staticClientPeerHelmValues, commonHelmValues)
// Install the second peer where static-client will be deployed in the static-client kubernetes context.
staticClientPeerCluster = consul.NewHelmCluster(t, staticClientPeerHelmValues, staticClientPeerClusterContext, cfg, releaseName)
staticClientPeerCluster.Create(t)
wg.Done()
}()

// Install the second peer where static-client will be deployed in the static-client kubernetes context.
staticClientPeerCluster := consul.NewHelmCluster(t, staticClientPeerHelmValues, staticClientPeerClusterContext, cfg, releaseName)
staticClientPeerCluster.Create(t)
// Wait for the clusters to start up
logger.Log(t, "waiting for clusters to start up . . .")
wg.Wait()

// Create Mesh resource to use mesh gateways.
logger.Log(t, "creating mesh config")
Expand Down Expand Up @@ -350,7 +368,7 @@ func TestPeering_Connect(t *testing.T) {
// If ACLs are enabled, test that deny intentions prevent connections.
if c.ACLsEnabled {
logger.Log(t, "testing intentions prevent connections through the terminating gateway")
k8s.CheckStaticServerConnectionFailing(t, staticClientOpts, staticClientName, externalServerHostnameURL)
k8s.CheckStaticServerHTTPConnectionFailing(t, staticClientOpts, staticClientName, externalServerHostnameURL)

logger.Log(t, "adding intentions to allow traffic from client ==> server")
terminatinggateway.AddIntention(t, staticServerPeerClient, staticClientPeer, "", staticClientName, "", externalServerHostnameID)
Expand Down
100 changes: 58 additions & 42 deletions acceptance/tests/peering/peering_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package peering
import (
"context"
"fmt"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -63,50 +64,65 @@ func TestPeering_Gateway(t *testing.T) {
"dns.enabled": "true",
}

staticServerPeerHelmValues := map[string]string{
"global.datacenter": staticServerPeer,
}

if !cfg.UseKind {
staticServerPeerHelmValues["server.replicas"] = "3"
}

// On Kind, there are no load balancers but since all clusters
// share the same node network (docker bridge), we can use
// a NodePort service so that we can access node(s) in a different Kind cluster.
if cfg.UseKind {
staticServerPeerHelmValues["server.exposeGossipAndRPCPorts"] = "true"
staticServerPeerHelmValues["meshGateway.service.type"] = "NodePort"
staticServerPeerHelmValues["meshGateway.service.nodePort"] = "30100"
}

var wg sync.WaitGroup
releaseName := helpers.RandomName()

helpers.MergeMaps(staticServerPeerHelmValues, commonHelmValues)

// Install the first peer where static-server will be deployed in the static-server kubernetes context.
staticServerPeerCluster := consul.NewHelmCluster(t, staticServerPeerHelmValues, staticServerPeerClusterContext, cfg, releaseName)
staticServerPeerCluster.Create(t)

staticClientPeerHelmValues := map[string]string{
"global.datacenter": staticClientPeer,
}

if !cfg.UseKind {
staticClientPeerHelmValues["server.replicas"] = "3"
}

if cfg.UseKind {
staticClientPeerHelmValues["server.exposeGossipAndRPCPorts"] = "true"
staticClientPeerHelmValues["meshGateway.service.type"] = "NodePort"
staticClientPeerHelmValues["meshGateway.service.nodePort"] = "30100"
}

helpers.MergeMaps(staticClientPeerHelmValues, commonHelmValues)

// Install the second peer where static-client will be deployed in the static-client kubernetes context.
staticClientPeerCluster := consul.NewHelmCluster(t, staticClientPeerHelmValues, staticClientPeerClusterContext, cfg, releaseName)
staticClientPeerCluster.Create(t)
var staticServerPeerCluster *consul.HelmCluster
wg.Add(1)
go func() {
staticServerPeerHelmValues := map[string]string{
"global.datacenter": staticServerPeer,
}

if !cfg.UseKind {
staticServerPeerHelmValues["server.replicas"] = "3"
}

// On Kind, there are no load balancers but since all clusters
// share the same node network (docker bridge), we can use
// a NodePort service so that we can access node(s) in a different Kind cluster.
if cfg.UseKind {
staticServerPeerHelmValues["server.exposeGossipAndRPCPorts"] = "true"
staticServerPeerHelmValues["meshGateway.service.type"] = "NodePort"
staticServerPeerHelmValues["meshGateway.service.nodePort"] = "30100"
}

helpers.MergeMaps(staticServerPeerHelmValues, commonHelmValues)

// Install the first peer where static-server will be deployed in the static-server kubernetes context.
staticServerPeerCluster = consul.NewHelmCluster(t, staticServerPeerHelmValues, staticServerPeerClusterContext, cfg, releaseName)
staticServerPeerCluster.Create(t)
wg.Done()
}()

var staticClientPeerCluster *consul.HelmCluster
wg.Add(1)
go func() {
staticClientPeerHelmValues := map[string]string{
"global.datacenter": staticClientPeer,
}

if !cfg.UseKind {
staticClientPeerHelmValues["server.replicas"] = "3"
}

if cfg.UseKind {
staticClientPeerHelmValues["server.exposeGossipAndRPCPorts"] = "true"
staticClientPeerHelmValues["meshGateway.service.type"] = "NodePort"
staticClientPeerHelmValues["meshGateway.service.nodePort"] = "30100"
}

helpers.MergeMaps(staticClientPeerHelmValues, commonHelmValues)

// Install the second peer where static-client will be deployed in the static-client kubernetes context.
staticClientPeerCluster = consul.NewHelmCluster(t, staticClientPeerHelmValues, staticClientPeerClusterContext, cfg, releaseName)
staticClientPeerCluster.Create(t)
wg.Done()
}()

// Wait for the clusters to start up
logger.Log(t, "waiting for clusters to start up . . .")
wg.Wait()

// Create Mesh resource to use mesh gateways.
logger.Log(t, "creating mesh config")
Expand Down

0 comments on commit 757e724

Please sign in to comment.