Skip to content

Commit

Permalink
conflict resolution
Browse files Browse the repository at this point in the history
Signed-off-by: yangyang <[email protected]>
  • Loading branch information
yangyy93 committed Mar 25, 2024
1 parent a556f32 commit 3a2f324
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion apis/projectcontour/v1alpha1/contourconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions internal/dag/httpproxy_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Check warning on line 1002 in internal/dag/httpproxy_processor.go

View check run for this annotation

Codecov / codecov/patch

internal/dag/httpproxy_processor.go#L1000-L1002

Added lines #L1000 - L1002 were not covered by tests
}
Expand Down
18 changes: 9 additions & 9 deletions internal/dag/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -860,37 +860,37 @@ 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)
}
if out.Interval == 0 {
return nil, fmt.Errorf("interval must be greater than 0s")

Check warning on line 868 in internal/dag/policy.go

View check run for this annotation

Codecov / codecov/patch

internal/dag/policy.go#L868

Added line #L868 was not covered by tests
}

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)

Check warning on line 873 in internal/dag/policy.go

View check run for this annotation

Codecov / codecov/patch

internal/dag/policy.go#L873

Added line #L873 was not covered by tests
}
if out.BaseEjectionTime == 0 {
return nil, fmt.Errorf("baseEjectionTime must be greater than 0s")

Check warning on line 876 in internal/dag/policy.go

View check run for this annotation

Codecov / codecov/patch

internal/dag/policy.go#L876

Added line #L876 was not covered by tests
}

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)

Check warning on line 881 in internal/dag/policy.go

View check run for this annotation

Codecov / codecov/patch

internal/dag/policy.go#L881

Added line #L881 was not covered by tests
}
if out.MaxEjectionTime < out.BaseEjectionTime {
return nil, fmt.Errorf("maxEjectionTime cannot be smaller than baseEjectionTime")

Check warning on line 884 in internal/dag/policy.go

View check run for this annotation

Codecov / codecov/patch

internal/dag/policy.go#L884

Added line #L884 was not covered by tests
}

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)

Check warning on line 895 in internal/dag/policy.go

View check run for this annotation

Codecov / codecov/patch

internal/dag/policy.go#L895

Added line #L895 was not covered by tests
}
Expand Down
30 changes: 15 additions & 15 deletions internal/dag/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -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)),
},
},
}
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions internal/envoy/v3/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
16 changes: 8 additions & 8 deletions internal/envoy/v3/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3a2f324

Please sign in to comment.