Browse Source

update l7expplicit dest test to test cross tenancy (#19834)

pull/19837/head
aahel 12 months ago committed by GitHub
parent
commit
334de1460c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 125
      test-integ/catalogv2/explicit_destinations_l7_test.go

125
test-integ/catalogv2/explicit_destinations_l7_test.go

@ -20,7 +20,29 @@ import (
) )
func TestSplitterFeaturesL7ExplicitDestinations(t *testing.T) { func TestSplitterFeaturesL7ExplicitDestinations(t *testing.T) {
cfg := testSplitterFeaturesL7ExplicitDestinationsCreator{}.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 := testSplitterFeaturesL7ExplicitDestinationsCreator{
tenancies: tenancies,
}.NewConfig(t)
sp := sprawltest.Launch(t, cfg) sp := sprawltest.Launch(t, cfg)
@ -37,11 +59,13 @@ func TestSplitterFeaturesL7ExplicitDestinations(t *testing.T) {
t.Log(topology.RenderRelationships(ships)) t.Log(topology.RenderRelationships(ships))
for _, tenancy := range tenancies {
// Make sure things are in v2. // Make sure things are in v2.
libassert.CatalogV2ServiceHasEndpointCount(t, clientV2, "static-client", nil, 1) libassert.CatalogV2ServiceHasEndpointCount(t, clientV2, "static-client", tenancy, 1)
libassert.CatalogV2ServiceHasEndpointCount(t, clientV2, "static-server-v1", nil, 1) libassert.CatalogV2ServiceHasEndpointCount(t, clientV2, "static-server-v1", tenancy, 1)
libassert.CatalogV2ServiceHasEndpointCount(t, clientV2, "static-server-v2", nil, 1) libassert.CatalogV2ServiceHasEndpointCount(t, clientV2, "static-server-v2", tenancy, 1)
libassert.CatalogV2ServiceHasEndpointCount(t, clientV2, "static-server", nil, 0) libassert.CatalogV2ServiceHasEndpointCount(t, clientV2, "static-server", tenancy, 0)
}
// Check relationships // Check relationships
for _, ship := range ships { for _, ship := range ships {
@ -87,7 +111,9 @@ func TestSplitterFeaturesL7ExplicitDestinations(t *testing.T) {
} }
} }
type testSplitterFeaturesL7ExplicitDestinationsCreator struct{} type testSplitterFeaturesL7ExplicitDestinationsCreator struct {
tenancies []*pbresource.Tenancy
}
func (c testSplitterFeaturesL7ExplicitDestinationsCreator) NewConfig(t *testing.T) *topology.Config { func (c testSplitterFeaturesL7ExplicitDestinationsCreator) NewConfig(t *testing.T) *topology.Config {
const clusterName = "dc1" const clusterName = "dc1"
@ -106,11 +132,8 @@ func (c testSplitterFeaturesL7ExplicitDestinationsCreator) NewConfig(t *testing.
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{
@ -129,34 +152,33 @@ func (c testSplitterFeaturesL7ExplicitDestinationsCreator) topologyConfigAddNode
t *testing.T, t *testing.T,
cluster *topology.Cluster, cluster *topology.Cluster,
nodeName func() string, nodeName func() string,
partition, currentTenancy *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{ tenancy := &pbresource.Tenancy{
Partition: partition, Partition: currentTenancy.Partition,
Namespace: namespace, Namespace: currentTenancy.Namespace,
PeerName: "local", PeerName: "local",
} }
v1ServerNode := &topology.Node{ v1ServerNode := &topology.Node{
Kind: topology.NodeKindDataplane, Kind: topology.NodeKindDataplane,
Version: topology.NodeVersionV2, Version: topology.NodeVersionV2,
Partition: partition, Partition: currentTenancy.Partition,
Name: nodeName(), Name: nodeName(),
Workloads: []*topology.Workload{ Workloads: []*topology.Workload{
topoutil.NewBlankspaceWorkloadWithDefaults( topoutil.NewBlankspaceWorkloadWithDefaults(
clusterName, clusterName,
newID("static-server-v1"), newID("static-server-v1", tenancy),
topology.NodeVersionV2, topology.NodeVersionV2,
func(wrk *topology.Workload) { func(wrk *topology.Workload) {
wrk.Meta = map[string]string{ wrk.Meta = map[string]string{
@ -170,12 +192,12 @@ func (c testSplitterFeaturesL7ExplicitDestinationsCreator) topologyConfigAddNode
v2ServerNode := &topology.Node{ v2ServerNode := &topology.Node{
Kind: topology.NodeKindDataplane, Kind: topology.NodeKindDataplane,
Version: topology.NodeVersionV2, Version: topology.NodeVersionV2,
Partition: partition, Partition: currentTenancy.Partition,
Name: nodeName(), Name: nodeName(),
Workloads: []*topology.Workload{ Workloads: []*topology.Workload{
topoutil.NewBlankspaceWorkloadWithDefaults( topoutil.NewBlankspaceWorkloadWithDefaults(
clusterName, clusterName,
newID("static-server-v2"), newID("static-server-v2", tenancy),
topology.NodeVersionV2, topology.NodeVersionV2,
func(wrk *topology.Workload) { func(wrk *topology.Workload) {
wrk.Meta = map[string]string{ wrk.Meta = map[string]string{
@ -189,45 +211,59 @@ func (c testSplitterFeaturesL7ExplicitDestinationsCreator) topologyConfigAddNode
clientNode := &topology.Node{ clientNode := &topology.Node{
Kind: topology.NodeKindDataplane, Kind: topology.NodeKindDataplane,
Version: topology.NodeVersionV2, Version: topology.NodeVersionV2,
Partition: partition, Partition: currentTenancy.Partition,
Name: nodeName(), Name: nodeName(),
Workloads: []*topology.Workload{ Workloads: []*topology.Workload{
topoutil.NewBlankspaceWorkloadWithDefaults( topoutil.NewBlankspaceWorkloadWithDefaults(
clusterName, clusterName,
newID("static-client"), newID("static-client", tenancy),
topology.NodeVersionV2, topology.NodeVersionV2,
func(wrk *topology.Workload) { func(wrk *topology.Workload) {
wrk.Destinations = []*topology.Destination{ for i, tenancy := range c.tenancies {
{ wrk.Destinations = append(wrk.Destinations, &topology.Destination{
ID: newID("static-server"),
ID: newID("static-server", tenancy),
PortName: "http", PortName: "http",
LocalAddress: "0.0.0.0", // needed for an assertion LocalAddress: "0.0.0.0", // needed for an assertion
LocalPort: 5000, LocalPort: 5000 + (i * 4),
}, },
{ &topology.Destination{
ID: newID("static-server"),
ID: newID("static-server", tenancy),
PortName: "http2", PortName: "http2",
LocalAddress: "0.0.0.0", // needed for an assertion LocalAddress: "0.0.0.0", // needed for an assertion
LocalPort: 5001, LocalPort: 5001 + (i * 4),
}, },
{ &topology.Destination{
ID: newID("static-server"),
ID: newID("static-server", tenancy),
PortName: "grpc", PortName: "grpc",
LocalAddress: "0.0.0.0", // needed for an assertion LocalAddress: "0.0.0.0", // needed for an assertion
LocalPort: 5002, LocalPort: 5002 + (i * 4),
}, },
{ &topology.Destination{
ID: newID("static-server"),
ID: newID("static-server", tenancy),
PortName: "tcp", PortName: "tcp",
LocalAddress: "0.0.0.0", // needed for an assertion LocalAddress: "0.0.0.0", // needed for an assertion
LocalPort: 5003, LocalPort: 5003 + (i * 4),
}, },
)
} }
}, },
), ),
}, },
} }
var sources []*pbauth.Source
for _, ten := range c.tenancies {
sources = append(sources, &pbauth.Source{
IdentityName: "static-client",
Namespace: ten.Namespace,
Partition: ten.Partition,
})
}
v1TrafficPerms := sprawltest.MustSetResourceData(t, &pbresource.Resource{ v1TrafficPerms := sprawltest.MustSetResourceData(t, &pbresource.Resource{
Id: &pbresource.ID{ Id: &pbresource.ID{
Type: pbauth.TrafficPermissionsType, Type: pbauth.TrafficPermissionsType,
@ -240,12 +276,10 @@ func (c testSplitterFeaturesL7ExplicitDestinationsCreator) topologyConfigAddNode
}, },
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,
}},
}}, }},
}) })
v2TrafficPerms := sprawltest.MustSetResourceData(t, &pbresource.Resource{ v2TrafficPerms := sprawltest.MustSetResourceData(t, &pbresource.Resource{
Id: &pbresource.ID{ Id: &pbresource.ID{
Type: pbauth.TrafficPermissionsType, Type: pbauth.TrafficPermissionsType,
@ -258,10 +292,7 @@ func (c testSplitterFeaturesL7ExplicitDestinationsCreator) topologyConfigAddNode
}, },
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,
}},
}}, }},
}) })
@ -350,6 +381,7 @@ func (c testSplitterFeaturesL7ExplicitDestinationsCreator) topologyConfigAddNode
}, },
}}, }},
}) })
grpcServerRoute := sprawltest.MustSetResourceData(t, &pbresource.Resource{ grpcServerRoute := sprawltest.MustSetResourceData(t, &pbresource.Resource{
Id: &pbresource.ID{ Id: &pbresource.ID{
Type: pbmesh.GRPCRouteType, Type: pbmesh.GRPCRouteType,
@ -390,6 +422,7 @@ func (c testSplitterFeaturesL7ExplicitDestinationsCreator) topologyConfigAddNode
}, },
}}, }},
}) })
tcpServerRoute := sprawltest.MustSetResourceData(t, &pbresource.Resource{ tcpServerRoute := sprawltest.MustSetResourceData(t, &pbresource.Resource{
Id: &pbresource.ID{ Id: &pbresource.ID{
Type: pbmesh.TCPRouteType, Type: pbmesh.TCPRouteType,
@ -442,7 +475,7 @@ func (c testSplitterFeaturesL7ExplicitDestinationsCreator) topologyConfigAddNode
v1TrafficPerms, v1TrafficPerms,
v2TrafficPerms, v2TrafficPerms,
httpServerRoute, httpServerRoute,
tcpServerRoute,
grpcServerRoute, grpcServerRoute,
tcpServerRoute,
) )
} }

Loading…
Cancel
Save