Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
ref: method renaming for cataloger endpoint methods
Browse files Browse the repository at this point in the history
Signed-off-by: Allen Leigh <[email protected]>
  • Loading branch information
allenlsy committed Jul 8, 2021
1 parent 78d4e97 commit 715a29e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
10 changes: 3 additions & 7 deletions pkg/catalog/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func (mc *MeshCatalog) GetResolvableServiceEndpoints(svc service.MeshService) ([
return endpoints, nil
}

// ListEndpointsForServiceIdentity returns only those endpoints for a allowed outbound service accounts
// for the given downstream identity
// ListEndpointsForServiceIdentity returns a list of endpoints that belongs to an upstream service accounts
// from the given downstream identity's perspective
// Note: ServiceIdentity must be in the format "name.namespace" [https://github.com/openservicemesh/osm/issues/3188]
func (mc *MeshCatalog) ListEndpointsForServiceIdentity(downstreamIdentity identity.ServiceIdentity, upstreamSvc service.MeshService) ([]endpoint.Endpoint, error) {
outboundEndpoints, err := mc.listEndpointsForService(upstreamSvc)
Expand All @@ -52,9 +52,8 @@ func (mc *MeshCatalog) ListEndpointsForServiceIdentity(downstreamIdentity identi
ipStr := ep.IP.String()
outboundEndpointsSet[ipStr] = append(outboundEndpointsSet[ipStr], ep)
}
log.Info().Msgf("outbound endpoints: %v", outboundEndpointsSet)

destSvcIdentities, err := mc.ListAllowedOutboundServiceIdentities(downstreamIdentity)
destSvcIdentities, err := mc.ListOutboundServiceIdentities(downstreamIdentity)
if err != nil {
log.Error().Err(err).Msgf("Error looking up outbound service accounts for downstream identity %s", downstreamIdentity)
return nil, err
Expand All @@ -64,14 +63,11 @@ func (mc *MeshCatalog) ListEndpointsForServiceIdentity(downstreamIdentity identi
// i.e. only those interseting endpoints are taken into cosideration
var allowedEndpoints []endpoint.Endpoint
for _, destSvcIdentity := range destSvcIdentities {
log.Info().Msgf("ups svc endpoints: %v, %v", destSvcIdentity, mc.listEndpointsForServiceIdentity(destSvcIdentity))

for _, ep := range mc.listEndpointsForServiceIdentity(destSvcIdentity) {
epIPStr := ep.IP.String()
// check if endpoint IP is allowed
if _, ok := outboundEndpointsSet[epIPStr]; ok {
// add all allowed endpoints on the pod to result list
// TODO(allenlsy): only allow endpoint with matching port
allowedEndpoints = append(allowedEndpoints, outboundEndpointsSet[epIPStr]...)
}
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/catalog/traffictarget.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ const (
httpRouteGroupKind = "HTTPRouteGroup"
)

// ListAllowedInboundServiceIdentities lists the downstream service identities that can connect to the given upstream service account
// ListInboundServiceIdentities lists the downstream service identities that can connect to the given upstream service account
// Note: ServiceIdentity must be in the format "name.namespace" [https://github.com/openservicemesh/osm/issues/3188]
func (mc *MeshCatalog) ListAllowedInboundServiceIdentities(upstream identity.ServiceIdentity) ([]identity.ServiceIdentity, error) {
func (mc *MeshCatalog) ListInboundServiceIdentities(upstream identity.ServiceIdentity) ([]identity.ServiceIdentity, error) {
return mc.getAllowedDirectionalServiceAccounts(upstream, inbound)
}

// ListAllowedOutboundServiceIdentities lists the upstream service identities the given downstream service account can connect to
// ListOutboundServiceIdentities lists the upstream service identities the given downstream service account can connect to
// Note: ServiceIdentity must be in the format "name.namespace" [https://github.com/openservicemesh/osm/issues/3188]
func (mc *MeshCatalog) ListAllowedOutboundServiceIdentities(downstream identity.ServiceIdentity) ([]identity.ServiceIdentity, error) {
func (mc *MeshCatalog) ListOutboundServiceIdentities(downstream identity.ServiceIdentity) ([]identity.ServiceIdentity, error) {
return mc.getAllowedDirectionalServiceAccounts(downstream, outbound)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/catalog/traffictarget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func TestListAllowedInboundServiceIdentities(t *testing.T) {
// Mock TrafficTargets returned by MeshSpec, should return all TrafficTargets relevant for this test
mockMeshSpec.EXPECT().ListTrafficTargets().Return(tc.trafficTargets).Times(1)

actual, err := meshCatalog.ListAllowedInboundServiceIdentities(tc.serviceIdentity)
actual, err := meshCatalog.ListInboundServiceIdentities(tc.serviceIdentity)
assert.Equal(err != nil, tc.expectError)
assert.ElementsMatch(actual, tc.expectedInboundServiceIdentities)
})
Expand Down Expand Up @@ -372,7 +372,7 @@ func TestListAllowedOutboundServiceIdentities(t *testing.T) {
// Mock TrafficTargets returned by MeshSpec, should return all TrafficTargets relevant for this test
mockMeshSpec.EXPECT().ListTrafficTargets().Return(tc.trafficTargets).Times(1)

actual, err := meshCatalog.ListAllowedOutboundServiceIdentities(tc.serviceIdentity)
actual, err := meshCatalog.ListOutboundServiceIdentities(tc.serviceIdentity)
assert.Equal(err != nil, tc.expectError)
assert.ElementsMatch(actual, tc.expectedOutboundServiceIdentities)
})
Expand Down

0 comments on commit 715a29e

Please sign in to comment.