Skip to content

Commit

Permalink
Apply locality weighted lb config correctly (istio#12588)
Browse files Browse the repository at this point in the history
Previously, this value was not set if the load balancer config was nil.
However, it should actually set anytime outlier detection is enabled, so
that locality lb can behave correctly.
  • Loading branch information
howardjohn authored and Joshua Blatt committed Mar 20, 2019
1 parent 74198b4 commit 451e179
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
17 changes: 8 additions & 9 deletions pilot/pkg/networking/core/v1alpha3/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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(
Expand Down
19 changes: 19 additions & 0 deletions pilot/pkg/networking/core/v1alpha3/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}

0 comments on commit 451e179

Please sign in to comment.