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

feat(mesh catalog): Return list of services for a given service account #1553

Merged
merged 1 commit into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ type MeshCataloger interface {
// UnregisterProxy unregisters an existing proxy from the service mesh catalog
UnregisterProxy(*envoy.Proxy)

// GetServiceForServiceAccount returns the service corresponding to a service account
GetServiceForServiceAccount(service.K8sServiceAccount) (service.MeshService, error)
// GetServicesForServiceAccount returns a list of services corresponding to a service account
GetServicesForServiceAccount(service.K8sServiceAccount) ([]service.MeshService, error)

// GetHostnamesForService returns the hostnames for a service
GetHostnamesForService(service service.MeshService) (string, error)
Expand Down
8 changes: 5 additions & 3 deletions pkg/catalog/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,28 +237,30 @@ func getTrafficPolicyPerRoute(mc *MeshCatalog, routePolicies map[trafficpolicy.T
Namespace: trafficTargets.Spec.Destination.Namespace,
Name: trafficTargets.Spec.Destination.Name,
}
destService, destErr := mc.GetServiceForServiceAccount(dstNamespacedServiceAcc)
destServiceList, destErr := mc.GetServicesForServiceAccount(dstNamespacedServiceAcc)
if destErr != nil {
log.Error().Msgf("TrafficTarget %s/%s could not get destination services for service account %s", trafficTargets.Namespace, trafficTargets.Name, dstNamespacedServiceAcc.String())
return nil, destErr
}
destService := destServiceList[0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be good to create an issue and reference it wherever these assumptions are being made.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated issue #1550


for _, trafficSources := range trafficTargets.Spec.Sources {
namespacedServiceAccount := service.K8sServiceAccount{
Namespace: trafficSources.Namespace,
Name: trafficSources.Name,
}

srcServices, srcErr := mc.GetServiceForServiceAccount(namespacedServiceAccount)
srcServiceList, srcErr := mc.GetServicesForServiceAccount(namespacedServiceAccount)
if srcErr != nil {
log.Error().Msgf("TrafficTarget %s/%s could not get source services for service account %s", trafficTargets.Namespace, trafficTargets.Name, fmt.Sprintf("%s/%s", trafficSources.Namespace, trafficSources.Name))
return nil, srcErr
}
srcService := srcServiceList[0]

trafficTarget := trafficpolicy.TrafficTarget{
Name: trafficTargets.Name,
Destination: destService,
Source: srcServices,
Source: srcService,
}

for _, trafficTargetSpecs := range trafficTargets.Spec.Rules {
Expand Down
20 changes: 15 additions & 5 deletions pkg/catalog/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,26 @@ import (
"github.com/openservicemesh/osm/pkg/service"
)

// GetServiceForServiceAccount returns a service corresponding to a service account
func (mc *MeshCatalog) GetServiceForServiceAccount(sa service.K8sServiceAccount) (service.MeshService, error) {
// GetServicesForServiceAccount returns a list of services corresponding to a service account
func (mc *MeshCatalog) GetServicesForServiceAccount(sa service.K8sServiceAccount) ([]service.MeshService, error) {
services := []service.MeshService{}
for _, provider := range mc.endpointsProviders {
// TODO (#88) : remove this provider check once we have figured out the service account story for azure vms
if provider.GetID() != constants.AzureProviderName {
log.Trace().Msgf("[%s] Looking for Services for Name=%s", provider.GetID(), sa)
service, err := provider.GetServiceForServiceAccount(sa)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will refactor provider functions (if needed) when Shashank merges his change

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

log.Trace().Msgf("[%s] Found service %s for Name=%s", provider.GetID(), service.String(), sa)
return service, err
if err != nil {
log.Warn().Msgf("Error getting services from provider %s: %s", provider.GetID(), err)
} else {
log.Trace().Msgf("[%s] Found service %s for Name=%s", provider.GetID(), service.String(), sa)
services = append(services, service)
}
}
}
return service.MeshService{}, errServiceNotFoundForAnyProvider

if len(services) == 0 {
return []service.MeshService{}, errServiceNotFoundForAnyProvider
}

return services, nil
}
4 changes: 2 additions & 2 deletions pkg/catalog/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ type MeshCataloger interface {
// UnregisterProxy unregisters an existing proxy from the service mesh catalog
UnregisterProxy(*envoy.Proxy)

// GetServiceForServiceAccount returns the service corresponding to a service account
GetServiceForServiceAccount(service.K8sServiceAccount) (service.MeshService, error)
// GetServicesForServiceAccount returns a list of services corresponding to a service account
GetServicesForServiceAccount(service.K8sServiceAccount) ([]service.MeshService, error)

// GetHostnamesForService returns the hostnames for a service
// TODO(ref: PR #1316): return a list of strings
Expand Down