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

Commit

Permalink
chore(cds): expose bug in getLocalServiceCluster via test
Browse files Browse the repository at this point in the history
* This test shows that etLocalServiceCluster returns unnecessary duplicate endpoints
If there are multiple replicas of a Pod sitting behind the same service,
there should only be one xds LbEndpoint programmed for the local cluster per port
specified in the Kubernetes Service spec and it should look like the following:
0.0.0.0:<port>.
* If you increase the replica count to 2 for bookbuyer in the demo, you'll
see an additional 18 entries in the local clusters list

Signed-off-by: Michelle Noorali <minooral@microsoft.com>
  • Loading branch information
Michelle Noorali committed Feb 8, 2021
1 parent 4ecb124 commit c3ced5d
Showing 1 changed file with 96 additions and 4 deletions.
100 changes: 96 additions & 4 deletions pkg/envoy/cds/cluster_test.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
package cds

import (
"net"
"testing"

xds_cluster "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"

xds_core "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
xds_endpoint "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/wrappers"
tassert "github.com/stretchr/testify/assert"

"github.com/openservicemesh/osm/pkg/catalog"
"github.com/openservicemesh/osm/pkg/configurator"
"github.com/openservicemesh/osm/pkg/constants"
"github.com/openservicemesh/osm/pkg/endpoint"
"github.com/openservicemesh/osm/pkg/envoy"
"github.com/openservicemesh/osm/pkg/service"
"github.com/openservicemesh/osm/pkg/tests"
)

func TestGetUpstreamServiceCluster(t *testing.T) {
assert := tassert.New(t)

mockCtrl := gomock.NewController(GinkgoT())
mockCtrl := gomock.NewController(t)
mockConfigurator := configurator.NewMockConfigurator(mockCtrl)
downstreamSvc := tests.BookbuyerService
upstreamSvc := tests.BookstoreV1Service
Expand Down Expand Up @@ -56,3 +63,88 @@ func TestGetUpstreamServiceCluster(t *testing.T) {
})
}
}

func TestGetLocalServiceCluster(t *testing.T) {
assert := tassert.New(t)

clusterName := "bookbuyer-local"
proxyService := service.MeshService{
Name: "bookbuyer",
Namespace: "bookbuyer-ns",
}

mockCtrl := gomock.NewController(t)
mockCatalog := catalog.NewMockMeshCataloger(mockCtrl)

testCases := []struct {
name string
endpoints []endpoint.Endpoint
expectedLocalityLbEndpoints []*xds_endpoint.LocalityLbEndpoints
expectedLbPolicy xds_cluster.Cluster_LbPolicy
expectedProtocolSelection xds_cluster.Cluster_ClusterProtocolSelection
}{
{
name: "when service returns one endpoint",
endpoints: []endpoint.Endpoint{tests.Endpoint},
expectedLocalityLbEndpoints: []*xds_endpoint.LocalityLbEndpoints{
{
Locality: &xds_core.Locality{
Zone: "zone",
},
LbEndpoints: []*xds_endpoint.LbEndpoint{{
HostIdentifier: &xds_endpoint.LbEndpoint_Endpoint{
Endpoint: &xds_endpoint.Endpoint{
Address: envoy.GetAddress(constants.WildcardIPAddr, uint32(tests.ServicePort)),
},
},
LoadBalancingWeight: &wrappers.UInt32Value{
Value: constants.ClusterWeightAcceptAll, // Local cluster accepts all traffic
},
}},
},
},
},
{
name: "when service returns two endpoints with same port",
endpoints: []endpoint.Endpoint{tests.Endpoint, {
IP: net.ParseIP("1.2.3.4"),
Port: endpoint.Port(tests.ServicePort),
}},
expectedLocalityLbEndpoints: []*xds_endpoint.LocalityLbEndpoints{
{
Locality: &xds_core.Locality{
Zone: "zone",
},
LbEndpoints: []*xds_endpoint.LbEndpoint{{
HostIdentifier: &xds_endpoint.LbEndpoint_Endpoint{
Endpoint: &xds_endpoint.Endpoint{
Address: envoy.GetAddress(constants.WildcardIPAddr, uint32(tests.ServicePort)),
},
},
LoadBalancingWeight: &wrappers.UInt32Value{
Value: constants.ClusterWeightAcceptAll, // Local cluster accepts all traffic
},
}},
},
},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
mockCatalog.EXPECT().ListEndpointsForService(proxyService).Return(tc.endpoints, nil).Times(1)
cluster, err := getLocalServiceCluster(mockCatalog, proxyService, clusterName)
assert.Nil(err)
assert.Equal(clusterName, cluster.Name)
assert.Equal(clusterName, cluster.AltStatName)
assert.Equal(ptypes.DurationProto(clusterConnectTimeout), cluster.ConnectTimeout)
assert.Equal(xds_cluster.Cluster_ROUND_ROBIN, cluster.LbPolicy)
assert.Equal(&xds_cluster.Cluster_Type{Type: xds_cluster.Cluster_STRICT_DNS}, cluster.ClusterDiscoveryType)
assert.Equal(true, cluster.RespectDnsTtl)
assert.Equal(xds_cluster.Cluster_V4_ONLY, cluster.DnsLookupFamily)
assert.Equal(xds_cluster.Cluster_USE_DOWNSTREAM_PROTOCOL, cluster.ProtocolSelection)
assert.Equal(len(tc.expectedLocalityLbEndpoints), len(cluster.LoadAssignment.Endpoints))
//assert.Equal(tc.expectedLocalityLbEndpoints, cluster.LoadAssignment.Endpoints)
})
}
}

0 comments on commit c3ced5d

Please sign in to comment.