Skip to content

Commit

Permalink
ref(pkg/catalog): clean up some unused funcs
Browse files Browse the repository at this point in the history
part of openservicemesh#2397

Signed-off-by: Michelle Noorali <minooral@microsoft.com>
  • Loading branch information
Michelle Noorali committed Feb 26, 2021
1 parent c91b033 commit 69545b2
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 199 deletions.
8 changes: 1 addition & 7 deletions DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ would require:

In the previous section, we proposed implementation of the `StreamAggregatedResources` method. This provides
connected Envoy proxies with a list of clusters, mapping of service name to list of routable IP addresses, list of permitted routes, listeners and secrets for CDS, EDS, RDS, LDS and SDS respectively.
The `ListEndpointsForService`, `ListTrafficPolicies` methods will be provided by the OSM component, which we refer to
The `ListEndpointsForService` method will be provided by the OSM component, which we refer to
as the **Mesh Catalog** in this document.

The Mesh Catalog will have access to the `MeshSpec`, `CertificateManager`, and the list of `EndpointsProvider`s.
Expand All @@ -302,12 +302,6 @@ type MeshCataloger interface {
// GetSMISpec returns the SMI spec
GetSMISpec() smi.MeshSpec
// ListTrafficPolicies returns all the traffic policies for a given service that Envoy proxy should be aware of.
ListTrafficPolicies(service.MeshService) ([]trafficpolicy.TrafficTarget, error)
// ListAllowedInboundServices lists the inbound services allowed to connect to the given service.
ListAllowedInboundServices(service.MeshService) ([]service.MeshService, error)
// ListAllowedInboundServiceAccounts lists the downstream service accounts that can connect to the given service account
ListAllowedInboundServiceAccounts(service.K8sServiceAccount) ([]service.K8sServiceAccount, error)
Expand Down
6 changes: 0 additions & 6 deletions docs/content/docs/design_concepts/interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ type MeshCataloger interface {
// GetSMISpec returns the SMI spec
GetSMISpec() smi.MeshSpec

// ListTrafficPolicies returns all the traffic policies for a given service that Envoy proxy should be aware of.
ListTrafficPolicies(service.MeshService) ([]trafficpolicy.TrafficTarget, error)

// ListAllowedInboundServices lists the inbound services allowed to connect to the given service.
ListAllowedInboundServices(service.MeshService) ([]service.MeshService, error)

// ListAllowedInboundServiceAccounts lists the downstream service accounts that can connect to the given service account
ListAllowedInboundServiceAccounts(service.K8sServiceAccount) ([]service.K8sServiceAccount, error)

Expand Down
30 changes: 0 additions & 30 deletions pkg/catalog/mock_catalog_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 0 additions & 75 deletions pkg/catalog/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,81 +150,6 @@ func (mc *MeshCatalog) listInboundPoliciesForTrafficSplits(upstreamIdentity serv
return inboundPolicies
}

// ListTrafficPolicies returns all the traffic policies for a given service that Envoy proxy should be aware of.
func (mc *MeshCatalog) ListTrafficPolicies(service service.MeshService) ([]trafficpolicy.TrafficTarget, error) {
log.Trace().Msgf("Listing traffic policies for service: %s", service)

if mc.configurator.IsPermissiveTrafficPolicyMode() {
// Build traffic policies from service discovery for allow-all policy
trafficPolicies := mc.buildAllowAllTrafficPolicies(service)
return trafficPolicies, nil
}

// Build traffic policies from SMI
allRoutes, err := mc.getHTTPPathsPerRoute()
if err != nil {
log.Error().Err(err).Msgf("Error getting all paths per route while working on service %s", service)
return nil, err
}

allTrafficPolicies, err := getTrafficPoliciesForService(mc, allRoutes, service)
if err != nil {
log.Error().Err(err).Msgf("Could not get all traffic policies")
return nil, err
}
return allTrafficPolicies, nil
}

// This function returns the list of connected services.
// This is a bimodal function:
// - it could list services that are allowed to connect to the given service (inbound)
// - it could list services that the given service can connect to (outbound)
func (mc *MeshCatalog) getAllowedDirectionalServices(svc service.MeshService, directn trafficDirection) ([]service.MeshService, error) {
allTrafficPolicies, err := mc.ListTrafficPolicies(svc)
if err != nil {
log.Error().Err(err).Msg("Failed listing traffic routes")
return nil, err
}

allowedServicesSet := mapset.NewSet()

for _, policy := range allTrafficPolicies {
if directn == inbound {
// we are looking for services that can connect to the given service
if policy.Destination.Equals(svc) {
allowedServicesSet.Add(policy.Source)
}
}

if directn == outbound {
// we are looking for services the given svc can connect to
if policy.Source.Equals(svc) {
allowedServicesSet.Add(policy.Destination)
}
}
}

// Convert the set of interfaces to a list of namespaced services
var allowedServices []service.MeshService
for svc := range allowedServicesSet.Iter() {
allowedServices = append(allowedServices, svc.(service.MeshService))
}

msg := map[trafficDirection]string{
inbound: "Allowed inbound services for destination service %q: %+v",
outbound: "Allowed outbound services from source %q: %+v",
}[directn]

log.Debug().Msgf(msg, svc, allowedServices)

return allowedServices, nil
}

// ListAllowedInboundServices lists the inbound services allowed to connect to the given service.
func (mc *MeshCatalog) ListAllowedInboundServices(destinationService service.MeshService) ([]service.MeshService, error) {
return mc.getAllowedDirectionalServices(destinationService, inbound)
}

// ListAllowedOutboundServicesForIdentity list the services the given service account is allowed to initiate outbound connections to
func (mc *MeshCatalog) ListAllowedOutboundServicesForIdentity(identity service.K8sServiceAccount) []service.MeshService {
if mc.configurator.IsPermissiveTrafficPolicyMode() {
Expand Down
43 changes: 0 additions & 43 deletions pkg/catalog/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,38 +698,6 @@ func TestRoutesFromRules(t *testing.T) {
}
}

func TestListTrafficPolicies(t *testing.T) {
assert := tassert.New(t)

type listTrafficPoliciesTest struct {
input service.MeshService
output []trafficpolicy.TrafficTarget
}

listTrafficPoliciesTests := []listTrafficPoliciesTest{
{
input: tests.BookstoreV1Service,
output: []trafficpolicy.TrafficTarget{tests.BookstoreV1TrafficPolicy},
},
{
input: tests.BookstoreV2Service,
output: []trafficpolicy.TrafficTarget{tests.BookstoreV2TrafficPolicy},
},
{
input: tests.BookbuyerService,
output: []trafficpolicy.TrafficTarget{tests.BookstoreV1TrafficPolicy, tests.BookstoreV2TrafficPolicy, tests.BookstoreApexTrafficPolicy},
},
}

mc := newFakeMeshCatalog()

for _, test := range listTrafficPoliciesTests {
trafficTargets, err := mc.ListTrafficPolicies(test.input)
assert.Nil(err)
assert.ElementsMatch(trafficTargets, test.output)
}
}

func TestGetTrafficPoliciesForService(t *testing.T) {
assert := tassert.New(t)

Expand Down Expand Up @@ -820,17 +788,6 @@ func TestGetTrafficSpecName(t *testing.T) {
assert.Equal(actual, expected)
}

func TestListAllowedInboundServices(t *testing.T) {
assert := tassert.New(t)

mc := newFakeMeshCatalog()

actualList, err := mc.ListAllowedInboundServices(tests.BookstoreV1Service)
assert.Nil(err)
expectedList := []service.MeshService{tests.BookbuyerService}
assert.ElementsMatch(actualList, expectedList)
}

func TestBuildAllowPolicyForSourceToDest(t *testing.T) {
assert := tassert.New(t)

Expand Down
8 changes: 1 addition & 7 deletions pkg/catalog/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,12 @@ type MeshCataloger interface {
// GetSMISpec returns the SMI spec
GetSMISpec() smi.MeshSpec

// ListTrafficPolicies returns all the traffic policies for a given service that Envoy proxy should be aware of.
ListTrafficPolicies(service.MeshService) ([]trafficpolicy.TrafficTarget, error)

// ListInboundTrafficPolicies returns all inbound traffic policies related to the given service account and upstream services
// ListInboundTrafficPolicies returns all inbound traffic policies related to the given service account and inbound services
ListInboundTrafficPolicies(service.K8sServiceAccount, []service.MeshService) []*trafficpolicy.InboundTrafficPolicy

// ListOutboundTrafficPolicies returns all outbound traffic policies related to the given service account
ListOutboundTrafficPolicies(service.K8sServiceAccount) []*trafficpolicy.OutboundTrafficPolicy

// ListAllowedInboundServices lists the inbound services allowed to connect to the given service.
ListAllowedInboundServices(service.MeshService) ([]service.MeshService, error)

// ListAllowedOutboundServicesForIdentity list the services the given service account is allowed to initiate outbound connections to
ListAllowedOutboundServicesForIdentity(service.K8sServiceAccount) []service.MeshService

Expand Down
31 changes: 0 additions & 31 deletions pkg/envoy/route/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,6 @@ import (
"github.com/openservicemesh/osm/pkg/trafficpolicy"
)

// Direction is a type to signify the direction associated with a route
type Direction int

const (
// OutboundRoute is the direction for an outbound route
OutboundRoute Direction = iota

// InboundRoute is the direction for an inbound route
InboundRoute
)

const (
//InboundRouteConfigName is the name of the route config that the envoy will identify
InboundRouteConfigName = "RDS_Inbound"

//OutboundRouteConfigName is the name of the route config that the envoy will identify
OutboundRouteConfigName = "RDS_Outbound"

// inboundVirtualHost is the name of the virtual host on the inbound route configuration
inboundVirtualHost = "inbound_virtual-host"

// outboundVirtualHost is the name of the virtual host on the outbound route configuration
outboundVirtualHost = "outbound_virtual-host"

// MethodHeaderKey is the key of the header for HTTP methods
MethodHeaderKey = ":method"

// httpHostHeader is the name of the HTTP host header
httpHostHeader = "host"
)

//UpdateRouteConfiguration constructs the Envoy construct necessary for TrafficTarget implementation
func UpdateRouteConfiguration(domainRoutesMap map[string]map[string]trafficpolicy.RouteWeightedClusters, routeConfig *xds_route.RouteConfiguration, direction Direction, proxy *envoy.Proxy) {
var virtualHostPrefix string
Expand Down
31 changes: 31 additions & 0 deletions pkg/envoy/route/route_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,37 @@ import (
"github.com/openservicemesh/osm/pkg/trafficpolicy"
)

// Direction is a type to signify the direction associated with a route
type Direction int

const (
// OutboundRoute is the direction for an outbound route
OutboundRoute Direction = iota

// InboundRoute is the direction for an inbound route
InboundRoute
)

const (
//InboundRouteConfigName is the name of the route config that the envoy will identify
InboundRouteConfigName = "RDS_Inbound"

//OutboundRouteConfigName is the name of the route config that the envoy will identify
OutboundRouteConfigName = "RDS_Outbound"

// inboundVirtualHost is the name of the virtual host on the inbound route configuration
inboundVirtualHost = "inbound_virtual-host"

// outboundVirtualHost is the name of the virtual host on the outbound route configuration
outboundVirtualHost = "outbound_virtual-host"

// MethodHeaderKey is the key of the header for HTTP methods
MethodHeaderKey = ":method"

// httpHostHeader is the name of the HTTP host header
httpHostHeader = "host"
)

// BuildRouteConfiguration constructs the Envoy constructs ([]*xds_route.RouteConfiguration) for implementing inbound and outbound routes
func BuildRouteConfiguration(inbound []*trafficpolicy.InboundTrafficPolicy, outbound []*trafficpolicy.OutboundTrafficPolicy, proxy *envoy.Proxy) []*xds_route.RouteConfiguration {
routeConfiguration := []*xds_route.RouteConfiguration{}
Expand Down

0 comments on commit 69545b2

Please sign in to comment.