diff --git a/apis/projectcontour/v1alpha1/contourconfig.go b/apis/projectcontour/v1alpha1/contourconfig.go index d9d9ce65cb4..c1b3cc93a3a 100644 --- a/apis/projectcontour/v1alpha1/contourconfig.go +++ b/apis/projectcontour/v1alpha1/contourconfig.go @@ -88,7 +88,7 @@ type ContourConfigurationSpec struct { // GlobalOutlierDetection defines the configuration for outlier detection on all services. // If defined, this will be used as the default for all services. // +optional - GlobalOutlierDetection *contour_api_v1.OutlierDetection `json:"outlierDetection,omitempty"` + GlobalOutlierDetection *contour_v1.OutlierDetection `json:"outlierDetection,omitempty"` // FeatureFlags defines toggle to enable new contour features. // Available toggles are: diff --git a/internal/dag/httpproxy_processor.go b/internal/dag/httpproxy_processor.go index e6c9f2cf2e8..438d4f73f1b 100644 --- a/internal/dag/httpproxy_processor.go +++ b/internal/dag/httpproxy_processor.go @@ -114,7 +114,7 @@ type HTTPProxyProcessor struct { SetSourceMetadataOnRoutes bool // GlobalOutlierDetection defines route-service's Global Outlier Detection configuration. - GlobalOutlierDetection *contour_api_v1.OutlierDetection + GlobalOutlierDetection *contour_v1.OutlierDetection // GlobalCircuitBreakerDefaults defines global circuit breaker defaults. GlobalCircuitBreakerDefaults *contour_v1alpha1.GlobalCircuitBreakerDefaults @@ -997,7 +997,7 @@ func (p *HTTPProxyProcessor) computeRoutes( outlierDetection, err := outlierDetectionPolicy(p.GlobalOutlierDetection, service.OutlierDetection) if err != nil { - validCond.AddErrorf(contour_api_v1.ConditionTypeOutlierDetectionError, "OutlierDetectionInvalid", + validCond.AddErrorf(contour_v1.ConditionTypeOutlierDetectionError, "OutlierDetectionInvalid", "%s on outlier detection", err) return nil } diff --git a/internal/dag/policy.go b/internal/dag/policy.go index 7ffc6335809..45b59af1d46 100644 --- a/internal/dag/policy.go +++ b/internal/dag/policy.go @@ -833,7 +833,7 @@ func serviceCircuitBreakerPolicy(s *Service, cb *contour_v1alpha1.GlobalCircuitB return s } -func mergeOutlierDetectionPolicy(globalOutlierDetection, serviceOutlierDetection *contour_api_v1.OutlierDetection) *contour_api_v1.OutlierDetection { +func mergeOutlierDetectionPolicy(globalOutlierDetection, serviceOutlierDetection *contour_v1.OutlierDetection) *contour_v1.OutlierDetection { if serviceOutlierDetection == nil { if globalOutlierDetection == nil || globalOutlierDetection.Disabled { return nil @@ -848,7 +848,7 @@ func mergeOutlierDetectionPolicy(globalOutlierDetection, serviceOutlierDetection return serviceOutlierDetection } -func outlierDetectionPolicy(globalOutlierDetection, serviceOutlierDetection *contour_api_v1.OutlierDetection) (*OutlierDetectionPolicy, error) { +func outlierDetectionPolicy(globalOutlierDetection, serviceOutlierDetection *contour_v1.OutlierDetection) (*OutlierDetectionPolicy, error) { outlierDetection := mergeOutlierDetectionPolicy(globalOutlierDetection, serviceOutlierDetection) if outlierDetection == nil { @@ -860,7 +860,7 @@ func outlierDetectionPolicy(globalOutlierDetection, serviceOutlierDetection *con } var err error - out.Interval, err = time.ParseDuration(ref.Val(outlierDetection.Interval, "10s")) + out.Interval, err = time.ParseDuration(ptr.Deref(outlierDetection.Interval, "10s")) if err != nil { return nil, fmt.Errorf("error parsing interval: %w", err) } @@ -868,7 +868,7 @@ func outlierDetectionPolicy(globalOutlierDetection, serviceOutlierDetection *con return nil, fmt.Errorf("interval must be greater than 0s") } - out.BaseEjectionTime, err = time.ParseDuration(ref.Val(outlierDetection.BaseEjectionTime, "30s")) + out.BaseEjectionTime, err = time.ParseDuration(ptr.Deref(outlierDetection.BaseEjectionTime, "30s")) if err != nil { return nil, fmt.Errorf("error parsing baseEjectionTime: %w", err) } @@ -876,7 +876,7 @@ func outlierDetectionPolicy(globalOutlierDetection, serviceOutlierDetection *con return nil, fmt.Errorf("baseEjectionTime must be greater than 0s") } - out.MaxEjectionTime, err = time.ParseDuration(ref.Val(outlierDetection.MaxEjectionTime, "300s")) + out.MaxEjectionTime, err = time.ParseDuration(ptr.Deref(outlierDetection.MaxEjectionTime, "300s")) if err != nil { return nil, fmt.Errorf("error parsing maxEjectionTime: %w", err) } @@ -884,13 +884,13 @@ func outlierDetectionPolicy(globalOutlierDetection, serviceOutlierDetection *con return nil, fmt.Errorf("maxEjectionTime cannot be smaller than baseEjectionTime") } - out.ConsecutiveServerErrors = ref.Val(outlierDetection.ConsecutiveServerErrors, 5) + out.ConsecutiveServerErrors = ptr.Deref(outlierDetection.ConsecutiveServerErrors, 5) - out.ConsecutiveLocalOriginFailure = ref.Val(outlierDetection.ConsecutiveLocalOriginFailure, 5) + out.ConsecutiveLocalOriginFailure = ptr.Deref(outlierDetection.ConsecutiveLocalOriginFailure, 5) - out.MaxEjectionPercent = ref.Val(outlierDetection.MaxEjectionPercent, 10) + out.MaxEjectionPercent = ptr.Deref(outlierDetection.MaxEjectionPercent, 10) - out.MaxEjectionTimeJitter, err = time.ParseDuration(ref.Val(outlierDetection.MaxEjectionTimeJitter, "0s")) + out.MaxEjectionTimeJitter, err = time.ParseDuration(ptr.Deref(outlierDetection.MaxEjectionTimeJitter, "0s")) if err != nil { return nil, fmt.Errorf("error parsing maxEjectionTimeJitter: %w", err) } diff --git a/internal/dag/policy_test.go b/internal/dag/policy_test.go index a8d2575035f..63268b60157 100644 --- a/internal/dag/policy_test.go +++ b/internal/dag/policy_test.go @@ -20,12 +20,12 @@ import ( "testing" "time" - "github.com/projectcontour/contour/internal/ref" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" networking_v1 "k8s.io/api/networking/v1" meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/utils/ptr" contour_v1 "github.com/projectcontour/contour/apis/projectcontour/v1" contour_v1alpha1 "github.com/projectcontour/contour/apis/projectcontour/v1alpha1" @@ -1381,18 +1381,18 @@ func TestMergeOutlierDetectionPolicy(t *testing.T) { }, "globalPolicy is not nil and globalPolicy is enabled and servicePolicy is not nil and servicePolicy is enabled": { globalPolicy: &contour_v1.OutlierDetection{ - ConsecutiveServerErrors: ref.To(uint32(5)), + ConsecutiveServerErrors: ptr.To(uint32(5)), }, servicePolicy: &contour_v1.OutlierDetection{ - ConsecutiveServerErrors: ref.To(uint32(10)), + ConsecutiveServerErrors: ptr.To(uint32(10)), }, want: &contour_v1.OutlierDetection{ - ConsecutiveServerErrors: ref.To(uint32(10)), + ConsecutiveServerErrors: ptr.To(uint32(10)), }, }, "globalPolicy is not nil and globalPolicy is enabled and servicePolicy is not nil and servicePolicy is disabled": { globalPolicy: &contour_v1.OutlierDetection{ - ConsecutiveServerErrors: ref.To(uint32(5)), + ConsecutiveServerErrors: ptr.To(uint32(5)), }, servicePolicy: &contour_v1.OutlierDetection{ Disabled: true, @@ -1404,10 +1404,10 @@ func TestMergeOutlierDetectionPolicy(t *testing.T) { Disabled: true, }, servicePolicy: &contour_v1.OutlierDetection{ - ConsecutiveServerErrors: ref.To(uint32(10)), + ConsecutiveServerErrors: ptr.To(uint32(10)), }, want: &contour_v1.OutlierDetection{ - ConsecutiveServerErrors: ref.To(uint32(10)), + ConsecutiveServerErrors: ptr.To(uint32(10)), }, }, } @@ -1444,27 +1444,27 @@ func TestOutlierDetectionPolicy(t *testing.T) { }, "interval no unit": { in: &contour_v1.OutlierDetection{ - Interval: ref.To("10"), + Interval: ptr.To("10"), }, want: nil, wantErr: true, }, "interval bad unit": { in: &contour_v1.OutlierDetection{ - Interval: ref.To("10f"), + Interval: ptr.To("10f"), }, want: nil, wantErr: true, }, "normal": { in: &contour_v1.OutlierDetection{ - ConsecutiveServerErrors: ref.To(uint32(5)), - Interval: ref.To("10s"), - BaseEjectionTime: ref.To("30s"), - MaxEjectionTime: ref.To("300s"), + ConsecutiveServerErrors: ptr.To(uint32(5)), + Interval: ptr.To("10s"), + BaseEjectionTime: ptr.To("30s"), + MaxEjectionTime: ptr.To("300s"), SplitExternalLocalOriginErrors: true, - ConsecutiveLocalOriginFailure: ref.To(uint32(3)), - MaxEjectionPercent: ref.To(uint32(50)), + ConsecutiveLocalOriginFailure: ptr.To(uint32(3)), + MaxEjectionPercent: ptr.To(uint32(50)), }, want: &OutlierDetectionPolicy{ ConsecutiveServerErrors: 5, diff --git a/internal/envoy/v3/cluster.go b/internal/envoy/v3/cluster.go index c0c23f7d609..58a3a3856f2 100644 --- a/internal/envoy/v3/cluster.go +++ b/internal/envoy/v3/cluster.go @@ -383,8 +383,8 @@ func slowStartConfig(slowStartConfig *dag.SlowStartConfig) *envoy_config_cluster } } -func outlierDetection(policy *dag.OutlierDetectionPolicy) *envoy_cluster_v3.OutlierDetection { - out := &envoy_cluster_v3.OutlierDetection{ +func outlierDetection(policy *dag.OutlierDetectionPolicy) *envoy_config_cluster_v3.OutlierDetection { + out := &envoy_config_cluster_v3.OutlierDetection{ EnforcingConsecutive_5Xx: protobuf.UInt32Zero(), EnforcingSuccessRate: protobuf.UInt32Zero(), EnforcingConsecutiveGatewayFailure: protobuf.UInt32Zero(), diff --git a/internal/envoy/v3/cluster_test.go b/internal/envoy/v3/cluster_test.go index 353212d43a6..0fcda3ad3f1 100644 --- a/internal/envoy/v3/cluster_test.go +++ b/internal/envoy/v3/cluster_test.go @@ -849,15 +849,15 @@ func TestCluster(t *testing.T) { MaxEjectionTimeJitter: 0, }, }, - want: &envoy_cluster_v3.Cluster{ + want: &envoy_config_cluster_v3.Cluster{ Name: "default/kuard/443/e08d8f1af7", AltStatName: "default_kuard_443", - ClusterDiscoveryType: ClusterDiscoveryType(envoy_cluster_v3.Cluster_EDS), - EdsClusterConfig: &envoy_cluster_v3.Cluster_EdsClusterConfig{ + ClusterDiscoveryType: ClusterDiscoveryType(envoy_config_cluster_v3.Cluster_EDS), + EdsClusterConfig: &envoy_config_cluster_v3.Cluster_EdsClusterConfig{ EdsConfig: ConfigSource("contour"), ServiceName: "default/kuard/http", }, - OutlierDetection: &envoy_cluster_v3.OutlierDetection{ + OutlierDetection: &envoy_config_cluster_v3.OutlierDetection{ EnforcingConsecutive_5Xx: protobuf.UInt32Zero(), EnforcingSuccessRate: protobuf.UInt32Zero(), EnforcingConsecutiveGatewayFailure: protobuf.UInt32Zero(), @@ -886,15 +886,15 @@ func TestCluster(t *testing.T) { MaxEjectionTimeJitter: 0, }, }, - want: &envoy_cluster_v3.Cluster{ + want: &envoy_config_cluster_v3.Cluster{ Name: "default/kuard/443/447b5c0802", AltStatName: "default_kuard_443", - ClusterDiscoveryType: ClusterDiscoveryType(envoy_cluster_v3.Cluster_EDS), - EdsClusterConfig: &envoy_cluster_v3.Cluster_EdsClusterConfig{ + ClusterDiscoveryType: ClusterDiscoveryType(envoy_config_cluster_v3.Cluster_EDS), + EdsClusterConfig: &envoy_config_cluster_v3.Cluster_EdsClusterConfig{ EdsConfig: ConfigSource("contour"), ServiceName: "default/kuard/http", }, - OutlierDetection: &envoy_cluster_v3.OutlierDetection{ + OutlierDetection: &envoy_config_cluster_v3.OutlierDetection{ EnforcingConsecutive_5Xx: protobuf.UInt32OrNil(100), EnforcingSuccessRate: protobuf.UInt32Zero(), EnforcingConsecutiveGatewayFailure: protobuf.UInt32Zero(), diff --git a/pkg/config/parameters.go b/pkg/config/parameters.go index 49a6ab3d9d0..d46ed11b2dd 100644 --- a/pkg/config/parameters.go +++ b/pkg/config/parameters.go @@ -708,7 +708,7 @@ type Parameters struct { // GlobalOutlierDetection defines the configuration for outlier detection on all services. // If defined, this will be used as the default for all services. - GlobalOutlierDetection *contour_api_v1.OutlierDetection `yaml:"outlierDetection,omitempty"` + GlobalOutlierDetection *contour_v1.OutlierDetection `yaml:"outlierDetection,omitempty"` // FeatureFlags defines toggle to enable new contour features. // available toggles are