From 1473d83d4c075c173b01f326f8bdd5c845f2a693 Mon Sep 17 00:00:00 2001 From: Ashwin Venkatesh Date: Fri, 19 May 2023 15:50:46 -0400 Subject: [PATCH 1/3] Fix json tags for added fields --- .changelog/2159.txt | 3 ++ .../consul/templates/crd-servicedefaults.yaml | 32 ++++++++++++++----- .../api/v1alpha1/servicedefaults_types.go | 11 +++---- .../api/v1alpha1/zz_generated.deepcopy.go | 7 +--- .../consul.hashicorp.com_servicedefaults.yaml | 30 +++++++++-------- 5 files changed, 50 insertions(+), 33 deletions(-) create mode 100644 .changelog/2159.txt diff --git a/.changelog/2159.txt b/.changelog/2159.txt new file mode 100644 index 0000000000..9b970bf3f4 --- /dev/null +++ b/.changelog/2159.txt @@ -0,0 +1,3 @@ +```release-note:bug +control-plane: fix issue with json tags of service defaults fields EnforcingConsecutive5xx, MaxEjectionPercent and BaseEjectionTime. +``` \ No newline at end of file diff --git a/charts/consul/templates/crd-servicedefaults.yaml b/charts/consul/templates/crd-servicedefaults.yaml index e0306333bd..3b5503eebe 100644 --- a/charts/consul/templates/crd-servicedefaults.yaml +++ b/charts/consul/templates/crd-servicedefaults.yaml @@ -252,7 +252,14 @@ spec: upstream proxy instances will be monitored for removal from the load balancing pool. properties: - enforcing_consecutive_5xx: + 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 30000ms or 30s. + type: string + enforcingConsecutive5xx: description: EnforcingConsecutive5xx is the % chance that a host will be actually ejected when an outlier status is detected through consecutive 5xx. This setting can @@ -263,6 +270,13 @@ 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. @@ -352,12 +366,13 @@ 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: + enforcingConsecutive5xx: description: EnforcingConsecutive5xx is the % chance that a host will be actually ejected when an outlier status is detected through consecutive 5xx. This setting @@ -371,8 +386,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 a5193e980f..335cc2257d 100644 --- a/control-plane/api/v1alpha1/servicedefaults_types.go +++ b/control-plane/api/v1alpha1/servicedefaults_types.go @@ -4,8 +4,7 @@ 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" @@ -172,14 +171,14 @@ type PassiveHealthCheck struct { // EnforcingConsecutive5xx is the % chance that a host will be actually ejected // 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"` + EnforcingConsecutive5xx *uint32 `json:"enforcingConsecutive5xx,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:"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:"base_ejection_time"` + BaseEjectionTime metav1.Duration `json:"baseEjectionTime,omitempty"` } type ServiceDefaultsDestination struct { @@ -422,7 +421,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 213164bc6b..d5230ffbef 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. @@ -854,11 +853,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. 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 769316397b..7324f0a296 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_servicedefaults.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_servicedefaults.yaml @@ -246,12 +246,13 @@ 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: + enforcingConsecutive5xx: description: EnforcingConsecutive5xx is the % chance that a host will be actually ejected when an outlier status is detected through consecutive 5xx. This setting can @@ -265,7 +266,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: @@ -357,12 +359,13 @@ 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: + enforcingConsecutive5xx: description: EnforcingConsecutive5xx is the % chance that a host will be actually ejected when an outlier status is detected through consecutive 5xx. This setting @@ -376,8 +379,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: From d7c4694d5b696cac5fa5a18734ea35d7399f6283 Mon Sep 17 00:00:00 2001 From: Maliz Date: Mon, 22 May 2023 12:46:35 -0700 Subject: [PATCH 2/3] update tests --- .../api/v1alpha1/servicedefaults_types.go | 4 ++-- .../v1alpha1/servicedefaults_types_test.go | 24 ++++++++++++++----- .../api/v1alpha1/zz_generated.deepcopy.go | 7 +++++- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/control-plane/api/v1alpha1/servicedefaults_types.go b/control-plane/api/v1alpha1/servicedefaults_types.go index 335cc2257d..c72e92a603 100644 --- a/control-plane/api/v1alpha1/servicedefaults_types.go +++ b/control-plane/api/v1alpha1/servicedefaults_types.go @@ -4,7 +4,7 @@ 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" @@ -178,7 +178,7 @@ type PassiveHealthCheck struct { // 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 metav1.Duration `json:"baseEjectionTime,omitempty"` + BaseEjectionTime *metav1.Duration `json:"baseEjectionTime,omitempty"` } type ServiceDefaultsDestination struct { diff --git a/control-plane/api/v1alpha1/servicedefaults_types_test.go b/control-plane/api/v1alpha1/servicedefaults_types_test.go index 8404d94934..201b0e138a 100644 --- a/control-plane/api/v1alpha1/servicedefaults_types_test.go +++ b/control-plane/api/v1alpha1/servicedefaults_types_test.go @@ -86,7 +86,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", @@ -113,7 +115,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", @@ -139,7 +143,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", @@ -361,7 +367,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", @@ -387,7 +395,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", @@ -412,7 +422,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", diff --git a/control-plane/api/v1alpha1/zz_generated.deepcopy.go b/control-plane/api/v1alpha1/zz_generated.deepcopy.go index d5230ffbef..0e06d55cd3 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" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -853,7 +854,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. From d643ca1094f8b1992d78158e4f04a032aa47383b Mon Sep 17 00:00:00 2001 From: Maliz Date: Thu, 25 May 2023 10:23:18 -0700 Subject: [PATCH 3/3] update consul image --- charts/consul/values.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/consul/values.yaml b/charts/consul/values.yaml index 8c3f6b6bff..b98892809d 100644 --- a/charts/consul/values.yaml +++ b/charts/consul/values.yaml @@ -63,7 +63,7 @@ global: # image: "hashicorp/consul-enterprise:1.10.0-ent" # ``` # @default: hashicorp/consul: - image: "hashicorp/consul:1.14.7" + image: "docker.mirror.hashicorp.services/hashicorppreview/consul-enterprise:1.14-dev" # Array of objects containing image pull secret names that will be applied to each service account. # This can be used to reference image pull secrets if using a custom consul or consul-k8s-control-plane Docker image.