mirror of https://github.com/status-im/consul.git
parent
123bc95e1a
commit
3443db7885
|
@ -37,7 +37,28 @@ import (
|
||||||
// - default/nsa
|
// - default/nsa
|
||||||
// - part1/nsa
|
// - part1/nsa
|
||||||
func TestBasicL4ImplicitDestinations(t *testing.T) {
|
func TestBasicL4ImplicitDestinations(t *testing.T) {
|
||||||
cfg := testBasicL4ImplicitDestinationsCreator{}.NewConfig(t)
|
tenancies := []*pbresource.Tenancy{{
|
||||||
|
Namespace: "default",
|
||||||
|
Partition: "default",
|
||||||
|
}}
|
||||||
|
if utils.IsEnterprise() {
|
||||||
|
tenancies = append(tenancies, &pbresource.Tenancy{
|
||||||
|
Namespace: "default",
|
||||||
|
Partition: "nsa",
|
||||||
|
})
|
||||||
|
tenancies = append(tenancies, &pbresource.Tenancy{
|
||||||
|
Namespace: "part1",
|
||||||
|
Partition: "default",
|
||||||
|
})
|
||||||
|
tenancies = append(tenancies, &pbresource.Tenancy{
|
||||||
|
Namespace: "part1",
|
||||||
|
Partition: "nsa",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg := testBasicL4ImplicitDestinationsCreator{
|
||||||
|
tenancies: tenancies,
|
||||||
|
}.NewConfig(t)
|
||||||
|
|
||||||
sp := sprawltest.Launch(t, cfg)
|
sp := sprawltest.Launch(t, cfg)
|
||||||
|
|
||||||
|
@ -55,11 +76,13 @@ func TestBasicL4ImplicitDestinations(t *testing.T) {
|
||||||
t.Log(topology.RenderRelationships(ships))
|
t.Log(topology.RenderRelationships(ships))
|
||||||
|
|
||||||
// Make sure things are truly in v2 not v1.
|
// Make sure things are truly in v2 not v1.
|
||||||
for _, name := range []string{
|
for _, tenancy := range tenancies {
|
||||||
"static-server",
|
for _, name := range []string{
|
||||||
"static-client",
|
"static-server",
|
||||||
} {
|
"static-client",
|
||||||
libassert.CatalogV2ServiceHasEndpointCount(t, clientV2, name, nil, 1)
|
} {
|
||||||
|
libassert.CatalogV2ServiceHasEndpointCount(t, clientV2, name, tenancy, 1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check relationships
|
// Check relationships
|
||||||
|
@ -81,7 +104,9 @@ func TestBasicL4ImplicitDestinations(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type testBasicL4ImplicitDestinationsCreator struct{}
|
type testBasicL4ImplicitDestinationsCreator struct {
|
||||||
|
tenancies []*pbresource.Tenancy
|
||||||
|
}
|
||||||
|
|
||||||
func (c testBasicL4ImplicitDestinationsCreator) NewConfig(t *testing.T) *topology.Config {
|
func (c testBasicL4ImplicitDestinationsCreator) NewConfig(t *testing.T) *topology.Config {
|
||||||
const clusterName = "dc1"
|
const clusterName = "dc1"
|
||||||
|
@ -100,11 +125,8 @@ func (c testBasicL4ImplicitDestinationsCreator) 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 i := range c.tenancies {
|
||||||
if cluster.Enterprise {
|
c.topologyConfigAddNodes(t, cluster, nodeName, c.tenancies[i])
|
||||||
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 +145,27 @@ func (c testBasicL4ImplicitDestinationsCreator) 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
|
||||||
|
|
||||||
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",
|
|
||||||
}
|
|
||||||
|
|
||||||
serverNode := &topology.Node{
|
serverNode := &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("static-server"),
|
newID("static-server", tenancy),
|
||||||
topology.NodeVersionV2,
|
topology.NodeVersionV2,
|
||||||
func(wrk *topology.Workload) {
|
func(wrk *topology.Workload) {
|
||||||
wrk.EnableTransparentProxy = true
|
wrk.EnableTransparentProxy = true
|
||||||
|
@ -158,32 +173,50 @@ func (c testBasicL4ImplicitDestinationsCreator) topologyConfigAddNodes(
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var impliedDestinations []*topology.Destination
|
||||||
|
for _, ten := range c.tenancies {
|
||||||
|
// For now we include all services in the same partition as implicit upstreams.
|
||||||
|
if tenancy.Partition != ten.Partition {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
impliedDestinations = append(impliedDestinations, &topology.Destination{
|
||||||
|
ID: newID("static-server", ten),
|
||||||
|
PortName: "http",
|
||||||
|
})
|
||||||
|
impliedDestinations = append(impliedDestinations, &topology.Destination{
|
||||||
|
ID: newID("static-server", ten),
|
||||||
|
PortName: "http2",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
clientNode := &topology.Node{
|
clientNode := &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("static-client"),
|
newID("static-client", tenancy),
|
||||||
topology.NodeVersionV2,
|
topology.NodeVersionV2,
|
||||||
func(wrk *topology.Workload) {
|
func(wrk *topology.Workload) {
|
||||||
wrk.EnableTransparentProxy = true
|
wrk.EnableTransparentProxy = true
|
||||||
wrk.ImpliedDestinations = []*topology.Destination{
|
wrk.ImpliedDestinations = impliedDestinations
|
||||||
{
|
|
||||||
ID: newID("static-server"),
|
|
||||||
PortName: "http",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ID: newID("static-server"),
|
|
||||||
PortName: "http2",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var sources []*pbauth.Source
|
||||||
|
for _, ten := range c.tenancies {
|
||||||
|
sources = append(sources, &pbauth.Source{
|
||||||
|
IdentityName: "static-client",
|
||||||
|
Namespace: ten.Namespace,
|
||||||
|
Partition: ten.Partition,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
trafficPerms := sprawltest.MustSetResourceData(t, &pbresource.Resource{
|
trafficPerms := sprawltest.MustSetResourceData(t, &pbresource.Resource{
|
||||||
Id: &pbresource.ID{
|
Id: &pbresource.ID{
|
||||||
Type: pbauth.TrafficPermissionsType,
|
Type: pbauth.TrafficPermissionsType,
|
||||||
|
@ -196,10 +229,7 @@ func (c testBasicL4ImplicitDestinationsCreator) topologyConfigAddNodes(
|
||||||
},
|
},
|
||||||
Action: pbauth.Action_ACTION_ALLOW,
|
Action: pbauth.Action_ACTION_ALLOW,
|
||||||
Permissions: []*pbauth.Permission{{
|
Permissions: []*pbauth.Permission{{
|
||||||
Sources: []*pbauth.Source{{
|
Sources: sources,
|
||||||
IdentityName: "static-client",
|
|
||||||
Namespace: namespace,
|
|
||||||
}},
|
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue