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

#2091 filter out split service from weighted cluster in route config #2110

Merged
merged 2 commits into from
Nov 30, 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
15 changes: 15 additions & 0 deletions pkg/envoy/rds/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
xds_route "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
xds_discovery "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
"github.com/golang/protobuf/ptypes"
split "github.com/servicemeshinterface/smi-sdk-go/pkg/apis/split/v1alpha2"

"github.com/openservicemesh/osm/pkg/catalog"
"github.com/openservicemesh/osm/pkg/certificate"
Expand Down Expand Up @@ -37,6 +38,7 @@ func NewResponse(catalog catalog.MeshCataloger, proxy *envoy.Proxy, _ *xds_disco
TypeUrl: string(envoy.TypeRDS),
}

allTrafficSplits, _, _, _, _ := catalog.ListSMIPolicies()
var routeConfiguration []*xds_route.RouteConfiguration
outboundRouteConfig := route.NewRouteConfigurationStub(route.OutboundRouteConfigName)
inboundRouteConfig := route.NewRouteConfigurationStub(route.InboundRouteConfigName)
Expand All @@ -48,6 +50,10 @@ func NewResponse(catalog catalog.MeshCataloger, proxy *envoy.Proxy, _ *xds_disco
isDestinationService := trafficPolicy.Destination.Equals(proxyServiceName)
svc := trafficPolicy.Destination
hostnames, err := catalog.GetResolvableHostnamesForUpstreamService(proxyServiceName, svc)
//filter out traffic split service, reference to pkg/catalog/xds_certificates.go:74
if isTrafficSplitService(svc, allTrafficSplits) {
continue
}
if err != nil {
log.Error().Err(err).Msg("Failed listing domains")
return nil, err
Expand Down Expand Up @@ -92,6 +98,15 @@ func NewResponse(catalog catalog.MeshCataloger, proxy *envoy.Proxy, _ *xds_disco
return resp, nil
}

func isTrafficSplitService(svc service.MeshService, allTrafficSplits []*split.TrafficSplit) bool {
for _, split := range allTrafficSplits {
if split.Namespace == svc.Namespace && split.Spec.Service == svc.Name {
return true
}
}
return false
}

func aggregateRoutesByHost(routesPerHost map[string]map[string]trafficpolicy.RouteWeightedClusters, routePolicy trafficpolicy.HTTPRoute, weightedCluster service.WeightedCluster, hostname string) {
host := kubernetes.GetServiceFromHostname(hostname)
_, exists := routesPerHost[host]
Expand Down
18 changes: 18 additions & 0 deletions pkg/envoy/rds/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

set "github.com/deckarep/golang-set"
"github.com/golang/mock/gomock"
split "github.com/servicemeshinterface/smi-sdk-go/pkg/apis/split/v1alpha2"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -59,6 +60,23 @@ var _ = Describe("Construct RoutePolicyWeightedClusters object", func() {
})
})

var _ = Describe("IsTrafficSplitService", func() {
svc := tests.BookstoreApexService
Context("Check if a mesh service is root service of TrafficSplit", func() {
It("Returns true", func() {
allTrafficSplits := []*split.TrafficSplit{&tests.TrafficSplit}
Expect(isTrafficSplitService(svc, allTrafficSplits)).To(Equal(true))
})

It("Return false", func() {
mutation := tests.TrafficSplit
mutation.Spec.Service = mutation.Spec.Service + "-mutation"
allTrafficSplits := []*split.TrafficSplit{&mutation}
Expect(isTrafficSplitService(svc, allTrafficSplits)).To(Equal(false))
})
})
})

var _ = Describe("AggregateRoutesByDomain", func() {
domainRoutesMap := make(map[string]map[string]trafficpolicy.RouteWeightedClusters)
weightedClustersMap := set.NewSet()
Expand Down