diff --git a/pilot/pkg/networking/core/v1alpha3/cluster.go b/pilot/pkg/networking/core/v1alpha3/cluster.go index b7373238d88b..0b9df4e18661 100644 --- a/pilot/pkg/networking/core/v1alpha3/cluster.go +++ b/pilot/pkg/networking/core/v1alpha3/cluster.go @@ -787,6 +787,14 @@ func applyOutlierDetection(cluster *apiv2.Cluster, outlier *networking.OutlierDe } func applyLoadBalancer(cluster *apiv2.Cluster, lb *networking.LoadBalancerSettings) { + if cluster.OutlierDetection != nil { + // Locality weighted load balancing + cluster.CommonLbConfig = &apiv2.Cluster_CommonLbConfig{ + LocalityConfigSpecifier: &apiv2.Cluster_CommonLbConfig_LocalityWeightedLbConfig_{ + LocalityWeightedLbConfig: &apiv2.Cluster_CommonLbConfig_LocalityWeightedLbConfig{}, + }, + } + } if lb == nil { return } @@ -815,15 +823,6 @@ func applyLoadBalancer(cluster *apiv2.Cluster, lb *networking.LoadBalancerSettin }, } } - - if cluster.OutlierDetection != nil { - // Locality weighted load balancing - cluster.CommonLbConfig = &apiv2.Cluster_CommonLbConfig{ - LocalityConfigSpecifier: &apiv2.Cluster_CommonLbConfig_LocalityWeightedLbConfig_{ - LocalityWeightedLbConfig: &apiv2.Cluster_CommonLbConfig_LocalityWeightedLbConfig{}, - }, - } - } } func applyLocalityLBSetting( diff --git a/pilot/pkg/networking/core/v1alpha3/cluster_test.go b/pilot/pkg/networking/core/v1alpha3/cluster_test.go index 4eb9555a2c71..479cb4505df3 100644 --- a/pilot/pkg/networking/core/v1alpha3/cluster_test.go +++ b/pilot/pkg/networking/core/v1alpha3/cluster_test.go @@ -513,3 +513,22 @@ func TestConditionallyConvertToIstioMtls(t *testing.T) { }) } } + +func TestLocalityLB(t *testing.T) { + g := NewGomegaWithT(t) + + clusters, err := buildTestClusters("*.example.org", model.SidecarProxy, testMesh, + &networking.DestinationRule{ + Host: "*.example.org", + TrafficPolicy: &networking.TrafficPolicy{ + OutlierDetection: &networking.OutlierDetection{ + ConsecutiveErrors: 5, + }, + }, + }) + g.Expect(err).NotTo(HaveOccurred()) + + if clusters[0].CommonLbConfig == nil { + t.Errorf("CommonLbConfig should be set for cluster %+v", clusters[0]) + } +}