From 978c3faff0e83526f224664cdcd482a7ccccd9d2 Mon Sep 17 00:00:00 2001 From: Semir Patel Date: Tue, 17 Jan 2023 13:26:44 -0600 Subject: [PATCH 1/7] Add MaxEjectionPercent and BaseEjectionTime to servicedefaults --- .../consul/templates/crd-servicedefaults.yaml | 12 ++++++++++ .../api/v1alpha1/servicedefaults_types.go | 10 ++++++++ .../v1alpha1/servicedefaults_types_test.go | 24 +++++++++++++++++++ .../api/v1alpha1/zz_generated.deepcopy.go | 11 +++++++++ .../consul.hashicorp.com_servicedefaults.yaml | 24 +++++++++++++++++++ control-plane/go.mod | 3 +++ 6 files changed, 84 insertions(+) diff --git a/charts/consul/templates/crd-servicedefaults.yaml b/charts/consul/templates/crd-servicedefaults.yaml index 128884c454..f9aadbb284 100644 --- a/charts/consul/templates/crd-servicedefaults.yaml +++ b/charts/consul/templates/crd-servicedefaults.yaml @@ -373,6 +373,12 @@ spec: how upstream proxy instances will be monitored for removal from the load balancing pool. properties: + baseEjectionTime: + description: The base time that a host is ejected for. The + real time is equal to the base time multiplied by the number + of times the host has been ejected and is capped by + max_ejection_time (Default 300s). Defaults to 30s. + type: string enforcing_consecutive_5xx: description: EnforcingConsecutive5xx is the % chance that a host will be actually ejected when an outlier @@ -385,6 +391,12 @@ spec: sweeps. Each sweep may remove hosts or return hosts to the pool. type: string + maxEjectionPercent: + description: The maximum % of an upstream cluster that + can be ejected due to outlier detection. Defaults to + 10% but will eject at least one host regardless of the value. + format: int32 + type: integer maxFailures: description: MaxFailures is the count of consecutive failures that results in a host being removed from diff --git a/control-plane/api/v1alpha1/servicedefaults_types.go b/control-plane/api/v1alpha1/servicedefaults_types.go index 2682f6a28a..a4ef16190e 100644 --- a/control-plane/api/v1alpha1/servicedefaults_types.go +++ b/control-plane/api/v1alpha1/servicedefaults_types.go @@ -4,6 +4,7 @@ import ( "fmt" "net" "strings" + "time" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" @@ -178,6 +179,13 @@ type PassiveHealthCheck struct { // when an outlier status is detected through consecutive 5xx. // This setting can be used to disable ejection or to ramp it up slowly. EnforcingConsecutive5xx *uint32 `json:"enforcing_consecutive_5xx,omitempty"` + // The maximum % of an upstream cluster that can be ejected due to outlier detection. + // Defaults to 10% but will eject at least one host regardless of the value. + MaxEjectionPercent *uint32 `json:",omitempty" alias:"max_ejection_percent"` + // The base time that a host is ejected for. The real time is equal to the base time + // multiplied by the number of times the host has been ejected and is capped by + // max_ejection_time (Default 300s). Defaults to 30000ms or 30s. + BaseEjectionTime *time.Duration `json:",omitempty" alias:"base_ejection_time"` } type ServiceDefaultsDestination struct { @@ -426,6 +434,8 @@ func (in *PassiveHealthCheck) toConsul() *capi.PassiveHealthCheck { Interval: in.Interval.Duration, MaxFailures: in.MaxFailures, EnforcingConsecutive5xx: in.EnforcingConsecutive5xx, + MaxEjectionPercent: in.MaxEjectionPercent, + BaseEjectionTime: in.BaseEjectionTime, } } diff --git a/control-plane/api/v1alpha1/servicedefaults_types_test.go b/control-plane/api/v1alpha1/servicedefaults_types_test.go index fb29cf15cc..db3dbf4fb8 100644 --- a/control-plane/api/v1alpha1/servicedefaults_types_test.go +++ b/control-plane/api/v1alpha1/servicedefaults_types_test.go @@ -86,6 +86,8 @@ func TestServiceDefaults_ToConsul(t *testing.T) { }, MaxFailures: uint32(20), EnforcingConsecutive5xx: pointer.Uint32(100), + MaxEjectionPercent: pointer.Uint32(10), + BaseEjectionTime: pointer.Duration(10 * time.Second), }, MeshGateway: MeshGateway{ Mode: "local", @@ -111,6 +113,8 @@ func TestServiceDefaults_ToConsul(t *testing.T) { }, MaxFailures: uint32(10), EnforcingConsecutive5xx: pointer.Uint32(60), + MaxEjectionPercent: pointer.Uint32(20), + BaseEjectionTime: pointer.Duration(20 * time.Second), }, MeshGateway: MeshGateway{ Mode: "remote", @@ -135,6 +139,8 @@ func TestServiceDefaults_ToConsul(t *testing.T) { }, MaxFailures: uint32(10), EnforcingConsecutive5xx: pointer.Uint32(60), + MaxEjectionPercent: pointer.Uint32(30), + BaseEjectionTime: pointer.Duration(30 * time.Second), }, MeshGateway: MeshGateway{ Mode: "remote", @@ -211,6 +217,8 @@ func TestServiceDefaults_ToConsul(t *testing.T) { Interval: 2 * time.Second, MaxFailures: uint32(20), EnforcingConsecutive5xx: pointer.Uint32(100), + MaxEjectionPercent: pointer.Uint32(10), + BaseEjectionTime: pointer.Duration(10 * time.Second), }, MeshGateway: capi.MeshGatewayConfig{ Mode: "local", @@ -234,6 +242,8 @@ func TestServiceDefaults_ToConsul(t *testing.T) { Interval: 2 * time.Second, MaxFailures: uint32(10), EnforcingConsecutive5xx: pointer.Uint32(60), + MaxEjectionPercent: pointer.Uint32(20), + BaseEjectionTime: pointer.Duration(20 * time.Second), }, MeshGateway: capi.MeshGatewayConfig{ Mode: "remote", @@ -256,6 +266,8 @@ func TestServiceDefaults_ToConsul(t *testing.T) { Interval: 2 * time.Second, MaxFailures: uint32(10), EnforcingConsecutive5xx: pointer.Uint32(60), + MaxEjectionPercent: pointer.Uint32(30), + BaseEjectionTime: pointer.Duration(30 * time.Second), }, MeshGateway: capi.MeshGatewayConfig{ Mode: "remote", @@ -382,6 +394,8 @@ func TestServiceDefaults_MatchesConsul(t *testing.T) { }, MaxFailures: uint32(20), EnforcingConsecutive5xx: pointer.Uint32(100), + MaxEjectionPercent: pointer.Uint32(10), + BaseEjectionTime: pointer.Duration(10 * time.Second), }, MeshGateway: MeshGateway{ Mode: "local", @@ -406,6 +420,8 @@ func TestServiceDefaults_MatchesConsul(t *testing.T) { }, MaxFailures: uint32(10), EnforcingConsecutive5xx: pointer.Uint32(60), + MaxEjectionPercent: pointer.Uint32(20), + BaseEjectionTime: pointer.Duration(20 * time.Second), }, MeshGateway: MeshGateway{ Mode: "remote", @@ -429,6 +445,8 @@ func TestServiceDefaults_MatchesConsul(t *testing.T) { }, MaxFailures: uint32(10), EnforcingConsecutive5xx: pointer.Uint32(60), + MaxEjectionPercent: pointer.Uint32(30), + BaseEjectionTime: pointer.Duration(30 * time.Second), }, MeshGateway: MeshGateway{ Mode: "remote", @@ -500,6 +518,8 @@ func TestServiceDefaults_MatchesConsul(t *testing.T) { Interval: 2 * time.Second, MaxFailures: uint32(20), EnforcingConsecutive5xx: pointer.Uint32(100), + MaxEjectionPercent: pointer.Uint32(10), + BaseEjectionTime: pointer.Duration(10 * time.Second), }, MeshGateway: capi.MeshGatewayConfig{ Mode: "local", @@ -522,6 +542,8 @@ func TestServiceDefaults_MatchesConsul(t *testing.T) { Interval: 2 * time.Second, MaxFailures: uint32(10), EnforcingConsecutive5xx: pointer.Uint32(60), + MaxEjectionPercent: pointer.Uint32(20), + BaseEjectionTime: pointer.Duration(20 * time.Second), }, MeshGateway: capi.MeshGatewayConfig{ Mode: "remote", @@ -543,6 +565,8 @@ func TestServiceDefaults_MatchesConsul(t *testing.T) { Interval: 2 * time.Second, MaxFailures: uint32(10), EnforcingConsecutive5xx: pointer.Uint32(60), + MaxEjectionPercent: pointer.Uint32(30), + BaseEjectionTime: pointer.Duration(30 * time.Second), }, MeshGateway: capi.MeshGatewayConfig{ Mode: "remote", diff --git a/control-plane/api/v1alpha1/zz_generated.deepcopy.go b/control-plane/api/v1alpha1/zz_generated.deepcopy.go index d12db29d14..3cd585fdb7 100644 --- a/control-plane/api/v1alpha1/zz_generated.deepcopy.go +++ b/control-plane/api/v1alpha1/zz_generated.deepcopy.go @@ -8,6 +8,7 @@ package v1alpha1 import ( "encoding/json" runtime "k8s.io/apimachinery/pkg/runtime" + timex "time" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -904,6 +905,16 @@ func (in *PassiveHealthCheck) DeepCopyInto(out *PassiveHealthCheck) { *out = new(uint32) **out = **in } + if in.MaxEjectionPercent != nil { + in, out := &in.MaxEjectionPercent, &out.MaxEjectionPercent + *out = new(uint32) + **out = **in + } + if in.BaseEjectionTime != nil { + in, out := &in.BaseEjectionTime, &out.BaseEjectionTime + *out = new(timex.Duration) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PassiveHealthCheck. diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_servicedefaults.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_servicedefaults.yaml index 8b05eeb025..2e2160df86 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_servicedefaults.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_servicedefaults.yaml @@ -267,6 +267,12 @@ spec: upstream proxy instances will be monitored for removal from the load balancing pool. properties: + baseEjectionTime: + description: The base time that a host is ejected for. The + real time is equal to the base time multiplied by the number + of times the host has been ejected and is capped by + max_ejection_time (Default 300s). Defaults to 30s. + type: string enforcing_consecutive_5xx: description: EnforcingConsecutive5xx is the % chance that a host will be actually ejected when an outlier status @@ -278,6 +284,12 @@ spec: description: Interval between health check analysis sweeps. Each sweep may remove hosts or return hosts to the pool. type: string + maxEjectionPercent: + description: The maximum % of an upstream cluster that + can be ejected due to outlier detection. Defaults to + 10% but will eject at least one host regardless of the value. + format: int32 + type: integer maxFailures: description: MaxFailures is the count of consecutive failures that results in a host being removed from the pool. @@ -366,6 +378,12 @@ spec: how upstream proxy instances will be monitored for removal from the load balancing pool. properties: + baseEjectionTime: + description: The base time that a host is ejected for. The + real time is equal to the base time multiplied by the number + of times the host has been ejected and is capped by + max_ejection_time (Default 300s). Defaults to 30s. + type: string enforcing_consecutive_5xx: description: EnforcingConsecutive5xx is the % chance that a host will be actually ejected when an outlier @@ -378,6 +396,12 @@ spec: sweeps. Each sweep may remove hosts or return hosts to the pool. type: string + maxEjectionPercent: + description: The maximum % of an upstream cluster that + can be ejected due to outlier detection. Defaults to + 10% but will eject at least one host regardless of the value. + format: int32 + type: integer maxFailures: description: MaxFailures is the count of consecutive failures that results in a host being removed from diff --git a/control-plane/go.mod b/control-plane/go.mod index 2cd0300557..490e125cf4 100644 --- a/control-plane/go.mod +++ b/control-plane/go.mod @@ -137,3 +137,6 @@ require ( replace github.com/hashicorp/consul/sdk => github.com/hashicorp/consul/sdk v0.4.1-0.20221021205723-cc843c4be892 go 1.19 + +replace github.com/hashicorp/consul/api => github.com/hashicorp/consul 07d54ee65d554620733216daf764fc53168a5563 +replace github.com/hashicorp/consul/api/watch => github.com/hashicorp/consul 07d54ee65d554620733216daf764fc53168a5563 \ No newline at end of file From d911b27886973d031837bb8ab65b56691d77f156 Mon Sep 17 00:00:00 2001 From: Semir Patel Date: Wed, 18 Jan 2023 10:46:26 -0600 Subject: [PATCH 2/7] test with sister branch in consul repo --- control-plane/go.mod | 5 +---- control-plane/go.sum | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/control-plane/go.mod b/control-plane/go.mod index 490e125cf4..5fea486315 100644 --- a/control-plane/go.mod +++ b/control-plane/go.mod @@ -10,7 +10,7 @@ require ( github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 github.com/hashicorp/consul-k8s/control-plane/cni v0.0.0-20220831174802-b8af65262de8 github.com/hashicorp/consul-server-connection-manager v0.1.0 - github.com/hashicorp/consul/api v1.10.1-0.20230106171340-8d923c178919 + github.com/hashicorp/consul/api v1.10.1-0.20230113220858-07d54ee65d55 github.com/hashicorp/consul/sdk v0.13.0 github.com/hashicorp/go-discover v0.0.0-20200812215701-c4b85f6ed31f github.com/hashicorp/go-hclog v1.2.2 @@ -137,6 +137,3 @@ require ( replace github.com/hashicorp/consul/sdk => github.com/hashicorp/consul/sdk v0.4.1-0.20221021205723-cc843c4be892 go 1.19 - -replace github.com/hashicorp/consul/api => github.com/hashicorp/consul 07d54ee65d554620733216daf764fc53168a5563 -replace github.com/hashicorp/consul/api/watch => github.com/hashicorp/consul 07d54ee65d554620733216daf764fc53168a5563 \ No newline at end of file diff --git a/control-plane/go.sum b/control-plane/go.sum index 7542ac12d9..a6afea8bc0 100644 --- a/control-plane/go.sum +++ b/control-plane/go.sum @@ -346,8 +346,8 @@ github.com/hashicorp/consul-k8s/control-plane/cni v0.0.0-20220831174802-b8af6526 github.com/hashicorp/consul-server-connection-manager v0.1.0 h1:XCweGvMHzra88rYv2zxwwuUOjBUdcQmNKVrnQmt/muo= github.com/hashicorp/consul-server-connection-manager v0.1.0/go.mod h1:XVVlO+Yk7aiRpspiHZkrrFVn9BJIiOPnQIzqytPxGaU= github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= -github.com/hashicorp/consul/api v1.10.1-0.20230106171340-8d923c178919 h1:8aVegJMSv7PIAAa1zqQQ0CT4TKv+Nf7I4rhE6+uDa1U= -github.com/hashicorp/consul/api v1.10.1-0.20230106171340-8d923c178919/go.mod h1:c1u8FzGHcavbEtRW/p1YditvfMgn4QsKNgz2rnCDF7c= +github.com/hashicorp/consul/api v1.10.1-0.20230113220858-07d54ee65d55 h1:jzJkr9m3jzwr0uvsow0u8QhEp2PYcV+NqqQ/kETAgW4= +github.com/hashicorp/consul/api v1.10.1-0.20230113220858-07d54ee65d55/go.mod h1:c1u8FzGHcavbEtRW/p1YditvfMgn4QsKNgz2rnCDF7c= github.com/hashicorp/consul/proto-public v0.1.0 h1:O0LSmCqydZi363hsqc6n2v5sMz3usQMXZF6ziK3SzXU= github.com/hashicorp/consul/proto-public v0.1.0/go.mod h1:vs2KkuWwtjkIgA5ezp4YKPzQp4GitV+q/+PvksrA92k= github.com/hashicorp/consul/sdk v0.4.1-0.20221021205723-cc843c4be892 h1:jw0NwPmNPr5CxAU04hACdj61JSaJBKZ0FdBo+kwfNp4= From cc80b2b7b2fa4b36513ead24c032b95f1d7df92c Mon Sep 17 00:00:00 2001 From: Semir Patel Date: Wed, 18 Jan 2023 14:57:03 -0600 Subject: [PATCH 3/7] missed one --- charts/consul/templates/crd-servicedefaults.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/charts/consul/templates/crd-servicedefaults.yaml b/charts/consul/templates/crd-servicedefaults.yaml index f9aadbb284..5acbbb90ec 100644 --- a/charts/consul/templates/crd-servicedefaults.yaml +++ b/charts/consul/templates/crd-servicedefaults.yaml @@ -274,6 +274,12 @@ spec: upstream proxy instances will be monitored for removal from the load balancing pool. properties: + baseEjectionTime: + description: The base time that a host is ejected for. The + real time is equal to the base time multiplied by the number + of times the host has been ejected and is capped by + max_ejection_time (Default 300s). Defaults to 30s. + type: string enforcing_consecutive_5xx: description: EnforcingConsecutive5xx is the % chance that a host will be actually ejected when an outlier status @@ -285,6 +291,12 @@ spec: description: Interval between health check analysis sweeps. Each sweep may remove hosts or return hosts to the pool. type: string + maxEjectionPercent: + description: The maximum % of an upstream cluster that + can be ejected due to outlier detection. Defaults to + 10% but will eject at least one host regardless of the value. + format: int32 + type: integer maxFailures: description: MaxFailures is the count of consecutive failures that results in a host being removed from the pool. From 45be44330909648a0ecef63e39fb11770aff3c8a Mon Sep 17 00:00:00 2001 From: Maliz Date: Thu, 13 Apr 2023 15:15:20 -0700 Subject: [PATCH 4/7] fix tag names --- control-plane/api/v1alpha1/servicedefaults_types.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/control-plane/api/v1alpha1/servicedefaults_types.go b/control-plane/api/v1alpha1/servicedefaults_types.go index a4ef16190e..e1e2192863 100644 --- a/control-plane/api/v1alpha1/servicedefaults_types.go +++ b/control-plane/api/v1alpha1/servicedefaults_types.go @@ -181,11 +181,11 @@ type PassiveHealthCheck struct { EnforcingConsecutive5xx *uint32 `json:"enforcing_consecutive_5xx,omitempty"` // The maximum % of an upstream cluster that can be ejected due to outlier detection. // Defaults to 10% but will eject at least one host regardless of the value. - MaxEjectionPercent *uint32 `json:",omitempty" alias:"max_ejection_percent"` + MaxEjectionPercent *uint32 `json:",omitempty" alias:"maxEjectionPercent"` // The base time that a host is ejected for. The real time is equal to the base time // multiplied by the number of times the host has been ejected and is capped by // max_ejection_time (Default 300s). Defaults to 30000ms or 30s. - BaseEjectionTime *time.Duration `json:",omitempty" alias:"base_ejection_time"` + BaseEjectionTime *time.Duration `json:",omitempty" alias:"baseEjectionTime"` } type ServiceDefaultsDestination struct { From cf9f0af168db5c04a4066a7c44615d641ac34616 Mon Sep 17 00:00:00 2001 From: Maliz Date: Tue, 18 Apr 2023 11:32:56 -0700 Subject: [PATCH 5/7] fix json tags and duration type --- .../fixtures/bases/crds-oss/servicedefaults.yaml | 2 ++ control-plane/api/v1alpha1/servicedefaults_types.go | 12 +++++------- control-plane/api/v1alpha1/zz_generated.deepcopy.go | 7 +------ 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/acceptance/tests/fixtures/bases/crds-oss/servicedefaults.yaml b/acceptance/tests/fixtures/bases/crds-oss/servicedefaults.yaml index 33bc0e5096..33f3aab0b2 100644 --- a/acceptance/tests/fixtures/bases/crds-oss/servicedefaults.yaml +++ b/acceptance/tests/fixtures/bases/crds-oss/servicedefaults.yaml @@ -19,6 +19,8 @@ spec: interval: 1s maxFailures: 10 enforcing_consecutive_5xx: 60 + maxEjectionPercent: 100 + baseEjectionTime: 20s - name: "bar" limits: maxConnections: 5 diff --git a/control-plane/api/v1alpha1/servicedefaults_types.go b/control-plane/api/v1alpha1/servicedefaults_types.go index e1e2192863..14c5ba3a85 100644 --- a/control-plane/api/v1alpha1/servicedefaults_types.go +++ b/control-plane/api/v1alpha1/servicedefaults_types.go @@ -2,10 +2,6 @@ package v1alpha1 import ( "fmt" - "net" - "strings" - "time" - "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/hashicorp/consul-k8s/control-plane/api/common" @@ -16,6 +12,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/validation/field" + "net" + "strings" ) const ( @@ -181,11 +179,11 @@ type PassiveHealthCheck struct { EnforcingConsecutive5xx *uint32 `json:"enforcing_consecutive_5xx,omitempty"` // The maximum % of an upstream cluster that can be ejected due to outlier detection. // Defaults to 10% but will eject at least one host regardless of the value. - MaxEjectionPercent *uint32 `json:",omitempty" alias:"maxEjectionPercent"` + MaxEjectionPercent *uint32 `json:"maxEjectionPercent,omitempty"` // The base time that a host is ejected for. The real time is equal to the base time // multiplied by the number of times the host has been ejected and is capped by // max_ejection_time (Default 300s). Defaults to 30000ms or 30s. - BaseEjectionTime *time.Duration `json:",omitempty" alias:"baseEjectionTime"` + BaseEjectionTime *metav1.Duration `json:"baseEjectionTime,omitempty"` } type ServiceDefaultsDestination struct { @@ -435,7 +433,7 @@ func (in *PassiveHealthCheck) toConsul() *capi.PassiveHealthCheck { MaxFailures: in.MaxFailures, EnforcingConsecutive5xx: in.EnforcingConsecutive5xx, MaxEjectionPercent: in.MaxEjectionPercent, - BaseEjectionTime: in.BaseEjectionTime, + BaseEjectionTime: &in.BaseEjectionTime.Duration, } } diff --git a/control-plane/api/v1alpha1/zz_generated.deepcopy.go b/control-plane/api/v1alpha1/zz_generated.deepcopy.go index 3cd585fdb7..e69c84ee61 100644 --- a/control-plane/api/v1alpha1/zz_generated.deepcopy.go +++ b/control-plane/api/v1alpha1/zz_generated.deepcopy.go @@ -8,7 +8,6 @@ package v1alpha1 import ( "encoding/json" runtime "k8s.io/apimachinery/pkg/runtime" - timex "time" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -910,11 +909,7 @@ func (in *PassiveHealthCheck) DeepCopyInto(out *PassiveHealthCheck) { *out = new(uint32) **out = **in } - if in.BaseEjectionTime != nil { - in, out := &in.BaseEjectionTime, &out.BaseEjectionTime - *out = new(timex.Duration) - **out = **in - } + out.BaseEjectionTime = in.BaseEjectionTime } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PassiveHealthCheck. From 7755dd68778cd2dc43918a5569de0acf57a58cdf Mon Sep 17 00:00:00 2001 From: Maliz Date: Thu, 27 Apr 2023 10:12:09 -0700 Subject: [PATCH 6/7] update test --- .../v1alpha1/servicedefaults_types_test.go | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/control-plane/api/v1alpha1/servicedefaults_types_test.go b/control-plane/api/v1alpha1/servicedefaults_types_test.go index 15054088ce..3201529e4e 100644 --- a/control-plane/api/v1alpha1/servicedefaults_types_test.go +++ b/control-plane/api/v1alpha1/servicedefaults_types_test.go @@ -91,7 +91,9 @@ func TestServiceDefaults_ToConsul(t *testing.T) { MaxFailures: uint32(20), EnforcingConsecutive5xx: pointer.Uint32(100), MaxEjectionPercent: pointer.Uint32(10), - BaseEjectionTime: pointer.Duration(10 * time.Second), + BaseEjectionTime: &metav1.Duration{ + Duration: 10 * time.Second, + }, }, MeshGateway: MeshGateway{ Mode: "local", @@ -118,7 +120,9 @@ func TestServiceDefaults_ToConsul(t *testing.T) { MaxFailures: uint32(10), EnforcingConsecutive5xx: pointer.Uint32(60), MaxEjectionPercent: pointer.Uint32(20), - BaseEjectionTime: pointer.Duration(20 * time.Second), + BaseEjectionTime: &metav1.Duration{ + Duration: 20 * time.Second, + }, }, MeshGateway: MeshGateway{ Mode: "remote", @@ -144,7 +148,9 @@ func TestServiceDefaults_ToConsul(t *testing.T) { MaxFailures: uint32(10), EnforcingConsecutive5xx: pointer.Uint32(60), MaxEjectionPercent: pointer.Uint32(30), - BaseEjectionTime: pointer.Duration(30 * time.Second), + BaseEjectionTime: &metav1.Duration{ + Duration: 30 * time.Second, + }, }, MeshGateway: MeshGateway{ Mode: "remote", @@ -399,7 +405,9 @@ func TestServiceDefaults_MatchesConsul(t *testing.T) { MaxFailures: uint32(20), EnforcingConsecutive5xx: pointer.Uint32(100), MaxEjectionPercent: pointer.Uint32(10), - BaseEjectionTime: pointer.Duration(10 * time.Second), + BaseEjectionTime: &metav1.Duration{ + Duration: 10 * time.Second, + }, }, MeshGateway: MeshGateway{ Mode: "local", @@ -425,7 +433,9 @@ func TestServiceDefaults_MatchesConsul(t *testing.T) { MaxFailures: uint32(10), EnforcingConsecutive5xx: pointer.Uint32(60), MaxEjectionPercent: pointer.Uint32(20), - BaseEjectionTime: pointer.Duration(20 * time.Second), + BaseEjectionTime: &metav1.Duration{ + Duration: 20 * time.Second, + }, }, MeshGateway: MeshGateway{ Mode: "remote", @@ -450,7 +460,9 @@ func TestServiceDefaults_MatchesConsul(t *testing.T) { MaxFailures: uint32(10), EnforcingConsecutive5xx: pointer.Uint32(60), MaxEjectionPercent: pointer.Uint32(30), - BaseEjectionTime: pointer.Duration(30 * time.Second), + BaseEjectionTime: &metav1.Duration{ + Duration: 30 * time.Second, + }, }, MeshGateway: MeshGateway{ Mode: "remote", From 65b891166fb4bb0aae8c81f3516c925a34b6c67f Mon Sep 17 00:00:00 2001 From: Maliz Date: Mon, 1 May 2023 11:14:35 -0700 Subject: [PATCH 7/7] generate yaml files and fix imports --- .../templates/crd-exportedservices.yaml | 3 ++- .../consul/templates/crd-servicedefaults.yaml | 26 +++++++++++-------- .../api/v1alpha1/servicedefaults_types.go | 10 ++++--- .../api/v1alpha1/zz_generated.deepcopy.go | 7 ++++- ...consul.hashicorp.com_exportedservices.yaml | 3 ++- .../consul.hashicorp.com_servicedefaults.yaml | 26 +++++++++++-------- 6 files changed, 46 insertions(+), 29 deletions(-) diff --git a/charts/consul/templates/crd-exportedservices.yaml b/charts/consul/templates/crd-exportedservices.yaml index 073e081d0c..591500cb12 100644 --- a/charts/consul/templates/crd-exportedservices.yaml +++ b/charts/consul/templates/crd-exportedservices.yaml @@ -76,7 +76,8 @@ spec: the service to. type: string peer: - description: Peer is the name of the peer to export the service to. + description: Peer is the name of the peer to export the + service to. type: string samenessGroup: description: SamenessGroup is the name of the sameness diff --git a/charts/consul/templates/crd-servicedefaults.yaml b/charts/consul/templates/crd-servicedefaults.yaml index 10699d4378..320ef31508 100644 --- a/charts/consul/templates/crd-servicedefaults.yaml +++ b/charts/consul/templates/crd-servicedefaults.yaml @@ -275,10 +275,11 @@ spec: the load balancing pool. properties: baseEjectionTime: - description: The base time that a host is ejected for. The - real time is equal to the base time multiplied by the number - of times the host has been ejected and is capped by - max_ejection_time (Default 300s). Defaults to 30s. + description: The base time that a host is ejected for. + The real time is equal to the base time multiplied by + the number of times the host has been ejected and is + capped by max_ejection_time (Default 300s). Defaults + to 30000ms or 30s. type: string enforcing_consecutive_5xx: description: EnforcingConsecutive5xx is the % chance that @@ -294,7 +295,8 @@ spec: maxEjectionPercent: description: The maximum % of an upstream cluster that can be ejected due to outlier detection. Defaults to - 10% but will eject at least one host regardless of the value. + 10% but will eject at least one host regardless of the + value. format: int32 type: integer maxFailures: @@ -390,10 +392,11 @@ spec: from the load balancing pool. properties: baseEjectionTime: - description: The base time that a host is ejected for. The - real time is equal to the base time multiplied by the number - of times the host has been ejected and is capped by - max_ejection_time (Default 300s). Defaults to 30s. + description: The base time that a host is ejected for. + The real time is equal to the base time multiplied + by the number of times the host has been ejected and + is capped by max_ejection_time (Default 300s). Defaults + to 30000ms or 30s. type: string enforcing_consecutive_5xx: description: EnforcingConsecutive5xx is the % chance @@ -409,8 +412,9 @@ spec: type: string maxEjectionPercent: description: The maximum % of an upstream cluster that - can be ejected due to outlier detection. Defaults to - 10% but will eject at least one host regardless of the value. + can be ejected due to outlier detection. Defaults + to 10% but will eject at least one host regardless + of the value. format: int32 type: integer maxFailures: diff --git a/control-plane/api/v1alpha1/servicedefaults_types.go b/control-plane/api/v1alpha1/servicedefaults_types.go index 6e92c85a62..13455c4c8f 100644 --- a/control-plane/api/v1alpha1/servicedefaults_types.go +++ b/control-plane/api/v1alpha1/servicedefaults_types.go @@ -5,18 +5,20 @@ package v1alpha1 import ( "fmt" + "net" + "strings" + "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/hashicorp/consul-k8s/control-plane/api/common" - capi "github.com/hashicorp/consul/api" "github.com/miekg/dns" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/validation/field" - "net" - "strings" + + "github.com/hashicorp/consul-k8s/control-plane/api/common" + capi "github.com/hashicorp/consul/api" ) const ( diff --git a/control-plane/api/v1alpha1/zz_generated.deepcopy.go b/control-plane/api/v1alpha1/zz_generated.deepcopy.go index d92ddabe52..cedd78a1e5 100644 --- a/control-plane/api/v1alpha1/zz_generated.deepcopy.go +++ b/control-plane/api/v1alpha1/zz_generated.deepcopy.go @@ -7,6 +7,7 @@ package v1alpha1 import ( "encoding/json" + "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -929,7 +930,11 @@ func (in *PassiveHealthCheck) DeepCopyInto(out *PassiveHealthCheck) { *out = new(uint32) **out = **in } - out.BaseEjectionTime = in.BaseEjectionTime + if in.BaseEjectionTime != nil { + in, out := &in.BaseEjectionTime, &out.BaseEjectionTime + *out = new(v1.Duration) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PassiveHealthCheck. diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_exportedservices.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_exportedservices.yaml index 84e523f50c..0b6b969856 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_exportedservices.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_exportedservices.yaml @@ -72,7 +72,8 @@ spec: the service to. type: string peer: - description: Peer is the name of the peer to export the service to. + description: Peer is the name of the peer to export the + service to. type: string samenessGroup: description: SamenessGroup is the name of the sameness diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_servicedefaults.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_servicedefaults.yaml index 6eae65f5e0..8009b3816b 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_servicedefaults.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_servicedefaults.yaml @@ -271,10 +271,11 @@ spec: the load balancing pool. properties: baseEjectionTime: - description: The base time that a host is ejected for. The - real time is equal to the base time multiplied by the number - of times the host has been ejected and is capped by - max_ejection_time (Default 300s). Defaults to 30s. + description: The base time that a host is ejected for. + The real time is equal to the base time multiplied by + the number of times the host has been ejected and is + capped by max_ejection_time (Default 300s). Defaults + to 30000ms or 30s. type: string enforcing_consecutive_5xx: description: EnforcingConsecutive5xx is the % chance that @@ -290,7 +291,8 @@ spec: maxEjectionPercent: description: The maximum % of an upstream cluster that can be ejected due to outlier detection. Defaults to - 10% but will eject at least one host regardless of the value. + 10% but will eject at least one host regardless of the + value. format: int32 type: integer maxFailures: @@ -386,10 +388,11 @@ spec: from the load balancing pool. properties: baseEjectionTime: - description: The base time that a host is ejected for. The - real time is equal to the base time multiplied by the number - of times the host has been ejected and is capped by - max_ejection_time (Default 300s). Defaults to 30s. + description: The base time that a host is ejected for. + The real time is equal to the base time multiplied + by the number of times the host has been ejected and + is capped by max_ejection_time (Default 300s). Defaults + to 30000ms or 30s. type: string enforcing_consecutive_5xx: description: EnforcingConsecutive5xx is the % chance @@ -405,8 +408,9 @@ spec: type: string maxEjectionPercent: description: The maximum % of an upstream cluster that - can be ejected due to outlier detection. Defaults to - 10% but will eject at least one host regardless of the value. + can be ejected due to outlier detection. Defaults + to 10% but will eject at least one host regardless + of the value. format: int32 type: integer maxFailures: