diff --git a/pkg/envoy/cds/cluster.go b/pkg/envoy/cds/cluster.go index 059839a58c..6351a21ac6 100644 --- a/pkg/envoy/cds/cluster.go +++ b/pkg/envoy/cds/cluster.go @@ -394,7 +394,7 @@ func applyUpstreamTrafficSetting(upstreamTrafficSetting *policyv1alpha1.Upstream Thresholds: []*xds_cluster.CircuitBreakers_Thresholds{threshold}, } - if upstreamTrafficSetting == nil { + if upstreamTrafficSetting == nil || upstreamTrafficSetting.Spec.ConnectionSettings == nil { return } diff --git a/pkg/envoy/cds/cluster_test.go b/pkg/envoy/cds/cluster_test.go index d0026c992e..b0093092ac 100644 --- a/pkg/envoy/cds/cluster_test.go +++ b/pkg/envoy/cds/cluster_test.go @@ -91,6 +91,16 @@ func TestGetUpstreamServiceCluster(t *testing.T) { }, }, }, + { + name: "Cluster without circuit breaker but with valid UpstreamTrafficSetting should not error/panic", + clusterConfig: trafficpolicy.MeshClusterConfig{ + Name: "default/bookstore-v1_14001", + Service: upstreamSvc, + UpstreamTrafficSetting: &policyv1alpha1.UpstreamTrafficSetting{ + Spec: policyv1alpha1.UpstreamTrafficSettingSpec{}, + }, + }, + }, } for _, tc := range testCases { @@ -106,7 +116,7 @@ func TestGetUpstreamServiceCluster(t *testing.T) { assert.Nil(remoteCluster.HealthChecks) } - if tc.clusterConfig.UpstreamTrafficSetting != nil { + if tc.expectedCircuitBreakerThreshold != nil { assert.Equal(tc.expectedCircuitBreakerThreshold, remoteCluster.CircuitBreakers) } })