diff --git a/pkg/catalog/helpers_test.go b/pkg/catalog/helpers_test.go index 120851139a..ae8d6d0061 100644 --- a/pkg/catalog/helpers_test.go +++ b/pkg/catalog/helpers_test.go @@ -130,7 +130,7 @@ func newFakeMeshCatalogForRoutes(t *testing.T, testParams testParams) *MeshCatal mockConfigurator.EXPECT().IsPermissiveTrafficPolicyMode().Return(testParams.permissiveMode).AnyTimes() - mockMeshSpec.EXPECT().ListTrafficTargets().Return([]*access.TrafficTarget{&tests.TrafficTarget}).AnyTimes() + mockMeshSpec.EXPECT().ListTrafficTargets().Return([]*access.TrafficTarget{&tests.TrafficTarget, &tests.BookstoreV2TrafficTarget}).AnyTimes() mockMeshSpec.EXPECT().ListHTTPTrafficSpecs().Return([]*specs.HTTPRouteGroup{&tests.HTTPRouteGroup}).AnyTimes() return NewMeshCatalog(mockKubeController, kubeClient, mockMeshSpec, certManager, diff --git a/pkg/catalog/routes_test.go b/pkg/catalog/routes_test.go index 6342232415..8e47023a30 100644 --- a/pkg/catalog/routes_test.go +++ b/pkg/catalog/routes_test.go @@ -845,7 +845,6 @@ func TestListTrafficTargetPermutations(t *testing.T) { expected := []string{ utils.GetTrafficTargetName(tests.TrafficTargetName, tests.BookbuyerService, tests.BookstoreV1Service), - utils.GetTrafficTargetName(tests.TrafficTargetName, tests.BookbuyerService, tests.BookstoreV2Service), utils.GetTrafficTargetName(tests.TrafficTargetName, tests.BookbuyerService, tests.BookstoreApexService), } assert.ElementsMatch(actualTargetNames, expected) @@ -1556,26 +1555,6 @@ func TestListPoliciesFromTrafficTargets(t *testing.T) { }, }, }, - { - Name: "bookstore-v2.default", - Hostnames: tests.BookstoreV2Hostnames, - Rules: []*trafficpolicy.Rule{ - { - Route: trafficpolicy.RouteWeightedClusters{ - HTTPRouteMatch: tests.BookstoreBuyHTTPRoute, - WeightedClusters: mapset.NewSet(tests.BookstoreV2DefaultWeightedCluster), - }, - AllowedServiceAccounts: mapset.NewSet(tests.BookbuyerServiceAccount), - }, - { - Route: trafficpolicy.RouteWeightedClusters{ - HTTPRouteMatch: tests.BookstoreSellHTTPRoute, - WeightedClusters: mapset.NewSet(tests.BookstoreV2DefaultWeightedCluster), - }, - AllowedServiceAccounts: mapset.NewSet(tests.BookbuyerServiceAccount), - }, - }, - }, { Name: "bookstore-apex.default", Hostnames: tests.BookstoreApexHostnames, diff --git a/pkg/endpoint/providers/kube/fake.go b/pkg/endpoint/providers/kube/fake.go index be55375b60..15160f0898 100644 --- a/pkg/endpoint/providers/kube/fake.go +++ b/pkg/endpoint/providers/kube/fake.go @@ -20,8 +20,9 @@ func NewFakeProvider() endpoint.Provider { tests.BookstoreApexService.String(): {tests.Endpoint}, }, services: map[service.K8sServiceAccount][]service.MeshService{ - tests.BookstoreServiceAccount: {tests.BookstoreV1Service, tests.BookstoreV2Service, tests.BookstoreApexService}, - tests.BookbuyerServiceAccount: {tests.BookbuyerService}, + tests.BookstoreServiceAccount: {tests.BookstoreV1Service, tests.BookstoreApexService}, + tests.BookstoreV2ServiceAccount: {tests.BookstoreV2Service}, + tests.BookbuyerServiceAccount: {tests.BookbuyerService}, }, } } diff --git a/pkg/envoy/eds/response_test.go b/pkg/envoy/eds/response_test.go index 78bcb1916a..cdbf97eb34 100644 --- a/pkg/envoy/eds/response_test.go +++ b/pkg/envoy/eds/response_test.go @@ -4,7 +4,9 @@ import ( "fmt" "testing" + xds_endpoint "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3" "github.com/golang/mock/gomock" + "github.com/golang/protobuf/ptypes" tassert "github.com/stretchr/testify/assert" "k8s.io/client-go/kubernetes" testclient "k8s.io/client-go/kubernetes/fake" @@ -61,6 +63,19 @@ func TestEndpointConfiguration(t *testing.T) { assert.NotNil(proxy) actual, err := NewResponse(meshCatalog, proxy, nil, mockConfigurator, nil) - assert.Empty(err) + assert.Nil(err) assert.NotNil(actual) + + // There are 3 endpoints configured based on the configuration: + // 1. Bookstore + // 2. Bookstore-v1 + // 3. Bookstore-v2 + assert.Len(actual.Resources, 3) + + loadAssignment := xds_endpoint.ClusterLoadAssignment{} + + // validating an endpoint + err = ptypes.UnmarshalAny(actual.Resources[0], &loadAssignment) + assert.Nil(err) + assert.Len(loadAssignment.Endpoints, 1) } diff --git a/pkg/smi/fake.go b/pkg/smi/fake.go index 01aefec8d0..742fa73c7b 100644 --- a/pkg/smi/fake.go +++ b/pkg/smi/fake.go @@ -27,7 +27,7 @@ func NewFakeMeshSpecClient() MeshSpec { trafficSplits: []*split.TrafficSplit{&tests.TrafficSplit}, httpRouteGroups: []*spec.HTTPRouteGroup{&tests.HTTPRouteGroup}, tcpRoutes: []*spec.TCPRoute{&tests.TCPRoute}, - trafficTargets: []*access.TrafficTarget{&tests.TrafficTarget}, + trafficTargets: []*access.TrafficTarget{&tests.TrafficTarget, &tests.BookstoreV2TrafficTarget}, weightedServices: []service.WeightedService{tests.BookstoreV1WeightedService, tests.BookstoreV2WeightedService}, serviceAccounts: []service.K8sServiceAccount{ tests.BookstoreServiceAccount, diff --git a/pkg/tests/fixtures.go b/pkg/tests/fixtures.go index 4e0422ed38..a0abd3ff19 100644 --- a/pkg/tests/fixtures.go +++ b/pkg/tests/fixtures.go @@ -51,6 +51,8 @@ const ( BookstoreServiceAccountName = "bookstore" // BookbuyerServiceAccountName is the name of the bookbuyer service account BookbuyerServiceAccountName = "bookbuyer" + // BookstoreV2ServiceAccountName is the name of the bookstore-v2 service account + BookstoreV2ServiceAccountName = "bookstore-v2" // TrafficTargetName is the name of the traffic target SMI object. TrafficTargetName = "bookbuyer-access-bookstore" @@ -325,6 +327,35 @@ var ( }, } + // BookstoreV2TrafficTarget is a traffic target SMI object for bookstore-v2. + BookstoreV2TrafficTarget = access.TrafficTarget{ + TypeMeta: v1.TypeMeta{ + APIVersion: "access.smi-spec.io/v1alpha3", + Kind: "TrafficTarget", + }, + ObjectMeta: v1.ObjectMeta{ + Name: TrafficTargetName, + Namespace: "default", + }, + Spec: access.TrafficTargetSpec{ + Destination: access.IdentityBindingSubject{ + Kind: "Name", + Name: BookstoreV2ServiceAccountName, + Namespace: "default", + }, + Sources: []access.IdentityBindingSubject{{ + Kind: "Name", + Name: BookbuyerServiceAccountName, + Namespace: "default", + }}, + Rules: []access.TrafficTargetRule{{ + Kind: "HTTPRouteGroup", + Name: RouteGroupName, + Matches: []string{BuyBooksMatchName, SellBooksMatchName}, + }}, + }, + } + // RoutePolicyMap is a map of a key to a route policy SMI object. RoutePolicyMap = map[trafficpolicy.TrafficSpecName]map[trafficpolicy.TrafficSpecMatchName]trafficpolicy.HTTPRouteMatch{ trafficpolicy.TrafficSpecName(fmt.Sprintf("HTTPRouteGroup/%s/%s", Namespace, RouteGroupName)): { @@ -339,6 +370,12 @@ var ( Name: BookstoreServiceAccountName, } + // BookstoreV2ServiceAccount is a namespaced service account. + BookstoreV2ServiceAccount = service.K8sServiceAccount{ + Namespace: Namespace, + Name: BookstoreV2ServiceAccountName, + } + // BookbuyerServiceAccount is a namespaced bookbuyer account. BookbuyerServiceAccount = service.K8sServiceAccount{ Namespace: Namespace,