mirror of https://github.com/status-im/consul.git
parent
a6d6164ba0
commit
c5cce63777
|
@ -37,7 +37,31 @@ import (
|
||||||
// - default/nsa
|
// - default/nsa
|
||||||
// - part1/nsa
|
// - part1/nsa
|
||||||
func TestBasicL4ExplicitDestinations(t *testing.T) {
|
func TestBasicL4ExplicitDestinations(t *testing.T) {
|
||||||
cfg := testBasicL4ExplicitDestinationsCreator{}.NewConfig(t)
|
|
||||||
|
tenancies := []*pbresource.Tenancy{
|
||||||
|
{
|
||||||
|
Partition: "default",
|
||||||
|
Namespace: "default",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if utils.IsEnterprise() {
|
||||||
|
tenancies = append(tenancies, &pbresource.Tenancy{
|
||||||
|
Partition: "part1",
|
||||||
|
Namespace: "default",
|
||||||
|
})
|
||||||
|
tenancies = append(tenancies, &pbresource.Tenancy{
|
||||||
|
Partition: "part1",
|
||||||
|
Namespace: "nsa",
|
||||||
|
})
|
||||||
|
tenancies = append(tenancies, &pbresource.Tenancy{
|
||||||
|
Partition: "default",
|
||||||
|
Namespace: "nsa",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg := testBasicL4ExplicitDestinationsCreator{
|
||||||
|
tenancies: tenancies,
|
||||||
|
}.NewConfig(t)
|
||||||
|
|
||||||
sp := sprawltest.Launch(t, cfg)
|
sp := sprawltest.Launch(t, cfg)
|
||||||
|
|
||||||
|
@ -55,13 +79,15 @@ func TestBasicL4ExplicitDestinations(t *testing.T) {
|
||||||
t.Log(topology.RenderRelationships(ships))
|
t.Log(topology.RenderRelationships(ships))
|
||||||
|
|
||||||
// Make sure things are in v2.
|
// Make sure things are in v2.
|
||||||
for _, name := range []string{
|
for _, ten := range tenancies {
|
||||||
"single-server",
|
for _, name := range []string{
|
||||||
"single-client",
|
"single-server",
|
||||||
"multi-server",
|
"single-client",
|
||||||
"multi-client",
|
"multi-server",
|
||||||
} {
|
"multi-client",
|
||||||
libassert.CatalogV2ServiceHasEndpointCount(t, clientV2, name, nil, 1)
|
} {
|
||||||
|
libassert.CatalogV2ServiceHasEndpointCount(t, clientV2, name, ten, 1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check relationships
|
// Check relationships
|
||||||
|
@ -81,7 +107,9 @@ func TestBasicL4ExplicitDestinations(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type testBasicL4ExplicitDestinationsCreator struct{}
|
type testBasicL4ExplicitDestinationsCreator struct {
|
||||||
|
tenancies []*pbresource.Tenancy
|
||||||
|
}
|
||||||
|
|
||||||
func (c testBasicL4ExplicitDestinationsCreator) NewConfig(t *testing.T) *topology.Config {
|
func (c testBasicL4ExplicitDestinationsCreator) NewConfig(t *testing.T) *topology.Config {
|
||||||
const clusterName = "dc1"
|
const clusterName = "dc1"
|
||||||
|
@ -100,11 +128,8 @@ func (c testBasicL4ExplicitDestinationsCreator) NewConfig(t *testing.T) *topolog
|
||||||
return fmt.Sprintf("%s-box%d", clusterName, lastNode)
|
return fmt.Sprintf("%s-box%d", clusterName, lastNode)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.topologyConfigAddNodes(t, cluster, nodeName, "default", "default")
|
for _, ten := range c.tenancies {
|
||||||
if cluster.Enterprise {
|
c.topologyConfigAddNodes(t, cluster, nodeName, ten)
|
||||||
c.topologyConfigAddNodes(t, cluster, nodeName, "part1", "default")
|
|
||||||
c.topologyConfigAddNodes(t, cluster, nodeName, "part1", "nsa")
|
|
||||||
c.topologyConfigAddNodes(t, cluster, nodeName, "default", "nsa")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return &topology.Config{
|
return &topology.Config{
|
||||||
|
@ -123,34 +148,28 @@ func (c testBasicL4ExplicitDestinationsCreator) topologyConfigAddNodes(
|
||||||
t *testing.T,
|
t *testing.T,
|
||||||
cluster *topology.Cluster,
|
cluster *topology.Cluster,
|
||||||
nodeName func() string,
|
nodeName func() string,
|
||||||
partition,
|
tenancy *pbresource.Tenancy,
|
||||||
namespace string,
|
|
||||||
) {
|
) {
|
||||||
clusterName := cluster.Name
|
clusterName := cluster.Name
|
||||||
|
tenancy.PeerName = "local"
|
||||||
|
|
||||||
newID := func(name string) topology.ID {
|
newID := func(name string, tenancy *pbresource.Tenancy) topology.ID {
|
||||||
return topology.ID{
|
return topology.ID{
|
||||||
Partition: partition,
|
Partition: tenancy.Partition,
|
||||||
Namespace: namespace,
|
Namespace: tenancy.Namespace,
|
||||||
Name: name,
|
Name: name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tenancy := &pbresource.Tenancy{
|
|
||||||
Partition: partition,
|
|
||||||
Namespace: namespace,
|
|
||||||
PeerName: "local",
|
|
||||||
}
|
|
||||||
|
|
||||||
singleportServerNode := &topology.Node{
|
singleportServerNode := &topology.Node{
|
||||||
Kind: topology.NodeKindDataplane,
|
Kind: topology.NodeKindDataplane,
|
||||||
Version: topology.NodeVersionV2,
|
Version: topology.NodeVersionV2,
|
||||||
Partition: partition,
|
Partition: tenancy.Partition,
|
||||||
Name: nodeName(),
|
Name: nodeName(),
|
||||||
Workloads: []*topology.Workload{
|
Workloads: []*topology.Workload{
|
||||||
topoutil.NewFortioWorkloadWithDefaults(
|
topoutil.NewFortioWorkloadWithDefaults(
|
||||||
clusterName,
|
clusterName,
|
||||||
newID("single-server"),
|
newID("single-server", tenancy),
|
||||||
topology.NodeVersionV2,
|
topology.NodeVersionV2,
|
||||||
func(wrk *topology.Workload) {
|
func(wrk *topology.Workload) {
|
||||||
wrk.WorkloadIdentity = "single-server-identity"
|
wrk.WorkloadIdentity = "single-server-identity"
|
||||||
|
@ -158,30 +177,42 @@ func (c testBasicL4ExplicitDestinationsCreator) topologyConfigAddNodes(
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
var singleportDestinations []*topology.Destination
|
||||||
|
for i, ten := range c.tenancies {
|
||||||
|
singleportDestinations = append(singleportDestinations, &topology.Destination{
|
||||||
|
ID: newID("single-server", ten),
|
||||||
|
PortName: "http",
|
||||||
|
LocalAddress: "0.0.0.0", // needed for an assertion
|
||||||
|
LocalPort: 5000 + i,
|
||||||
|
})
|
||||||
|
}
|
||||||
singleportClientNode := &topology.Node{
|
singleportClientNode := &topology.Node{
|
||||||
Kind: topology.NodeKindDataplane,
|
Kind: topology.NodeKindDataplane,
|
||||||
Version: topology.NodeVersionV2,
|
Version: topology.NodeVersionV2,
|
||||||
Partition: partition,
|
Partition: tenancy.Partition,
|
||||||
Name: nodeName(),
|
Name: nodeName(),
|
||||||
Workloads: []*topology.Workload{
|
Workloads: []*topology.Workload{
|
||||||
topoutil.NewFortioWorkloadWithDefaults(
|
topoutil.NewFortioWorkloadWithDefaults(
|
||||||
clusterName,
|
clusterName,
|
||||||
newID("single-client"),
|
newID("single-client", tenancy),
|
||||||
topology.NodeVersionV2,
|
topology.NodeVersionV2,
|
||||||
func(wrk *topology.Workload) {
|
func(wrk *topology.Workload) {
|
||||||
delete(wrk.Ports, "grpc") // v2 mode turns this on, so turn it off
|
delete(wrk.Ports, "grpc") // v2 mode turns this on, so turn it off
|
||||||
delete(wrk.Ports, "http2") // v2 mode turns this on, so turn it off
|
delete(wrk.Ports, "http2") // v2 mode turns this on, so turn it off
|
||||||
wrk.WorkloadIdentity = "single-client-identity"
|
wrk.WorkloadIdentity = "single-client-identity"
|
||||||
wrk.Destinations = []*topology.Destination{{
|
wrk.Destinations = singleportDestinations
|
||||||
ID: newID("single-server"),
|
|
||||||
PortName: "http",
|
|
||||||
LocalAddress: "0.0.0.0", // needed for an assertion
|
|
||||||
LocalPort: 5000,
|
|
||||||
}}
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
var sources []*pbauth.Source
|
||||||
|
for _, ten := range c.tenancies {
|
||||||
|
sources = append(sources, &pbauth.Source{
|
||||||
|
IdentityName: "single-client-identity",
|
||||||
|
Namespace: ten.Namespace,
|
||||||
|
Partition: ten.Partition,
|
||||||
|
})
|
||||||
|
}
|
||||||
singleportTrafficPerms := sprawltest.MustSetResourceData(t, &pbresource.Resource{
|
singleportTrafficPerms := sprawltest.MustSetResourceData(t, &pbresource.Resource{
|
||||||
Id: &pbresource.ID{
|
Id: &pbresource.ID{
|
||||||
Type: pbauth.TrafficPermissionsType,
|
Type: pbauth.TrafficPermissionsType,
|
||||||
|
@ -194,22 +225,19 @@ func (c testBasicL4ExplicitDestinationsCreator) topologyConfigAddNodes(
|
||||||
},
|
},
|
||||||
Action: pbauth.Action_ACTION_ALLOW,
|
Action: pbauth.Action_ACTION_ALLOW,
|
||||||
Permissions: []*pbauth.Permission{{
|
Permissions: []*pbauth.Permission{{
|
||||||
Sources: []*pbauth.Source{{
|
Sources: sources,
|
||||||
IdentityName: "single-client-identity",
|
|
||||||
Namespace: namespace,
|
|
||||||
}},
|
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
|
|
||||||
multiportServerNode := &topology.Node{
|
multiportServerNode := &topology.Node{
|
||||||
Kind: topology.NodeKindDataplane,
|
Kind: topology.NodeKindDataplane,
|
||||||
Version: topology.NodeVersionV2,
|
Version: topology.NodeVersionV2,
|
||||||
Partition: partition,
|
Partition: tenancy.Partition,
|
||||||
Name: nodeName(),
|
Name: nodeName(),
|
||||||
Workloads: []*topology.Workload{
|
Workloads: []*topology.Workload{
|
||||||
topoutil.NewFortioWorkloadWithDefaults(
|
topoutil.NewFortioWorkloadWithDefaults(
|
||||||
clusterName,
|
clusterName,
|
||||||
newID("multi-server"),
|
newID("multi-server", tenancy),
|
||||||
topology.NodeVersionV2,
|
topology.NodeVersionV2,
|
||||||
func(wrk *topology.Workload) {
|
func(wrk *topology.Workload) {
|
||||||
wrk.WorkloadIdentity = "multi-server-identity"
|
wrk.WorkloadIdentity = "multi-server-identity"
|
||||||
|
@ -217,36 +245,47 @@ func (c testBasicL4ExplicitDestinationsCreator) topologyConfigAddNodes(
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
var multiportDestinations []*topology.Destination
|
||||||
|
for i, ten := range c.tenancies {
|
||||||
|
multiportDestinations = append(multiportDestinations, &topology.Destination{
|
||||||
|
ID: newID("multi-server", ten),
|
||||||
|
PortName: "http",
|
||||||
|
LocalAddress: "0.0.0.0", // needed for an assertion
|
||||||
|
LocalPort: 5000 + 2*i,
|
||||||
|
})
|
||||||
|
multiportDestinations = append(multiportDestinations, &topology.Destination{
|
||||||
|
ID: newID("multi-server", ten),
|
||||||
|
PortName: "http2",
|
||||||
|
LocalAddress: "0.0.0.0", // needed for an assertion
|
||||||
|
LocalPort: 5000 + 2*i + 1,
|
||||||
|
})
|
||||||
|
}
|
||||||
multiportClientNode := &topology.Node{
|
multiportClientNode := &topology.Node{
|
||||||
Kind: topology.NodeKindDataplane,
|
Kind: topology.NodeKindDataplane,
|
||||||
Version: topology.NodeVersionV2,
|
Version: topology.NodeVersionV2,
|
||||||
Partition: partition,
|
Partition: tenancy.Partition,
|
||||||
Name: nodeName(),
|
Name: nodeName(),
|
||||||
Workloads: []*topology.Workload{
|
Workloads: []*topology.Workload{
|
||||||
topoutil.NewFortioWorkloadWithDefaults(
|
topoutil.NewFortioWorkloadWithDefaults(
|
||||||
clusterName,
|
clusterName,
|
||||||
newID("multi-client"),
|
newID("multi-client", tenancy),
|
||||||
topology.NodeVersionV2,
|
topology.NodeVersionV2,
|
||||||
func(wrk *topology.Workload) {
|
func(wrk *topology.Workload) {
|
||||||
wrk.WorkloadIdentity = "multi-client-identity"
|
wrk.WorkloadIdentity = "multi-client-identity"
|
||||||
wrk.Destinations = []*topology.Destination{
|
wrk.Destinations = multiportDestinations
|
||||||
{
|
|
||||||
ID: newID("multi-server"),
|
|
||||||
PortName: "http",
|
|
||||||
LocalAddress: "0.0.0.0", // needed for an assertion
|
|
||||||
LocalPort: 5000,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ID: newID("multi-server"),
|
|
||||||
PortName: "http2",
|
|
||||||
LocalAddress: "0.0.0.0", // needed for an assertion
|
|
||||||
LocalPort: 5001,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var multiportSources []*pbauth.Source
|
||||||
|
for _, ten := range c.tenancies {
|
||||||
|
multiportSources = append(multiportSources, &pbauth.Source{
|
||||||
|
IdentityName: "multi-client-identity",
|
||||||
|
Namespace: ten.Namespace,
|
||||||
|
Partition: ten.Partition,
|
||||||
|
})
|
||||||
|
}
|
||||||
multiportTrafficPerms := sprawltest.MustSetResourceData(t, &pbresource.Resource{
|
multiportTrafficPerms := sprawltest.MustSetResourceData(t, &pbresource.Resource{
|
||||||
Id: &pbresource.ID{
|
Id: &pbresource.ID{
|
||||||
Type: pbauth.TrafficPermissionsType,
|
Type: pbauth.TrafficPermissionsType,
|
||||||
|
@ -259,10 +298,7 @@ func (c testBasicL4ExplicitDestinationsCreator) topologyConfigAddNodes(
|
||||||
},
|
},
|
||||||
Action: pbauth.Action_ACTION_ALLOW,
|
Action: pbauth.Action_ACTION_ALLOW,
|
||||||
Permissions: []*pbauth.Permission{{
|
Permissions: []*pbauth.Permission{{
|
||||||
Sources: []*pbauth.Source{{
|
Sources: multiportSources,
|
||||||
IdentityName: "multi-client-identity",
|
|
||||||
Namespace: namespace,
|
|
||||||
}},
|
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue