Skip to content

Commit

Permalink
Merge pull request openservicemesh#3598 from steeling/feature/catalog…
Browse files Browse the repository at this point in the history
…-multi

feat(pkg/catalog):  Gateway gets all in-cluster services for ListAllowedOutbound
  • Loading branch information
snehachhabria authored Jun 22, 2021
2 parents c83b94b + 346ec28 commit 50d4426
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
14 changes: 14 additions & 0 deletions pkg/catalog/gateway.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package catalog

import (
"github.com/openservicemesh/osm/pkg/envoy"
"github.com/openservicemesh/osm/pkg/identity"
)

// isOSMGateway checks if the ServiceIdentity belongs to the MultiClusterGateway.
// Only used if MultiClusterMode is enabled.
func (mc *MeshCatalog) isOSMGateway(svcIdentity identity.ServiceIdentity) bool {
sa := svcIdentity.ToK8sServiceAccount()
return mc.configurator.GetFeatureFlags().EnableMulticlusterMode &&
envoy.ProxyKind(sa.Name) == envoy.KindGateway && sa.Namespace == mc.configurator.GetOSMNamespace()
}
3 changes: 3 additions & 0 deletions pkg/catalog/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
testclient "k8s.io/client-go/kubernetes/fake"

"github.com/openservicemesh/osm/pkg/apis/config/v1alpha1"
"github.com/openservicemesh/osm/pkg/certificate/providers/tresor"
"github.com/openservicemesh/osm/pkg/configurator"
"github.com/openservicemesh/osm/pkg/endpoint"
Expand All @@ -38,6 +39,8 @@ func newFakeMeshCatalogForRoutes(t *testing.T, testParams testParams) *MeshCatal
mockKubeController := k8s.NewMockController(mockCtrl)
mockIngressMonitor := ingress.NewMockMonitor(mockCtrl)
mockPolicyController := policy.NewMockController(mockCtrl)
mockConfigurator.EXPECT().GetFeatureFlags().Return(v1alpha1.FeatureFlags{EnableMulticlusterMode: true}).AnyTimes()
mockConfigurator.EXPECT().GetOSMNamespace().Return("osm-system").AnyTimes()

endpointProviders := []endpoint.Provider{
kube.NewFakeProvider(),
Expand Down
10 changes: 10 additions & 0 deletions pkg/catalog/outbound_traffic_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ func (mc *MeshCatalog) listOutboundTrafficPoliciesForTrafficSplits(sourceNamespa
// Note: ServiceIdentity must be in the format "name.namespace" [https://github.com/openservicemesh/osm/issues/3188]
func (mc *MeshCatalog) ListAllowedOutboundServicesForIdentity(serviceIdentity identity.ServiceIdentity) []service.MeshService {
ident := serviceIdentity.ToK8sServiceAccount()
if mc.isOSMGateway(serviceIdentity) {
var services []service.MeshService
for _, svc := range mc.listMeshServices() {
// The gateway can only forward to local services.
if svc.Local() {
services = append(services, svc)
}
}
return services
}
if mc.configurator.IsPermissiveTrafficPolicyMode() {
return mc.listMeshServices()
}
Expand Down
11 changes: 10 additions & 1 deletion pkg/catalog/outbound_traffic_policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/openservicemesh/osm/pkg/apis/config/v1alpha1"
"github.com/openservicemesh/osm/pkg/configurator"
"github.com/openservicemesh/osm/pkg/endpoint"
"github.com/openservicemesh/osm/pkg/identity"
Expand Down Expand Up @@ -334,7 +335,7 @@ func TestListOutboundTrafficPolicies(t *testing.T) {
mockConfigurator := configurator.NewMockConfigurator(mockCtrl)

mockEndpointProvider.EXPECT().GetID().Return("fake").AnyTimes()

mockConfigurator.EXPECT().GetFeatureFlags().Return(v1alpha1.FeatureFlags{EnableMulticlusterMode: true}).AnyTimes()
for _, ms := range tc.apexMeshServices {
apexK8sService := tests.NewServiceFixture(ms.Name, ms.Namespace, map[string]string{})
mockKubeController.EXPECT().GetService(ms).Return(apexK8sService).AnyTimes()
Expand Down Expand Up @@ -736,6 +737,12 @@ func TestListAllowedOutboundServicesForIdentity(t *testing.T) {
expectedList: []service.MeshService{tests.BookstoreV1Service, tests.BookstoreV2Service, tests.BookstoreApexService, tests.BookbuyerService},
permissiveMode: true,
},
{
name: "gateway",
svcIdentity: "gateway.osm-system.cluster.local",
expectedList: []service.MeshService{tests.BookstoreV1Service, tests.BookstoreV2Service, tests.BookstoreApexService, tests.BookbuyerService},
permissiveMode: true,
},
}

for _, tc := range testCases {
Expand Down Expand Up @@ -1318,6 +1325,8 @@ func TestListMeshServicesForIdentity(t *testing.T) {
mockMeshSpec := smi.NewMockMeshSpec(mockCtrl)
mockConfigurator := configurator.NewMockConfigurator(mockCtrl)
mockController := k8s.NewMockController(mockCtrl)
mockConfigurator.EXPECT().GetFeatureFlags().Return(v1alpha1.FeatureFlags{EnableMulticlusterMode: true}).AnyTimes()
mockConfigurator.EXPECT().GetOSMNamespace().Return("osm-system").AnyTimes()

mc := MeshCatalog{
meshSpec: mockMeshSpec,
Expand Down

0 comments on commit 50d4426

Please sign in to comment.