From 703e5b33df2f136104da228091fb6de3c82ebf03 Mon Sep 17 00:00:00 2001 From: Dan Stough Date: Thu, 7 Dec 2023 15:23:00 -0500 Subject: [PATCH] Port: "retryOn" configuration on ServiceRouter CRD (#3308) * feat(crds): add support for retryOn in service router Co-authored-by: ilpianista --------- Co-authored-by: ilpianista --- .changelog/3308.txt | 3 +++ charts/consul/templates/crd-servicerouters.yaml | 7 +++++++ control-plane/api/v1alpha1/servicerouter_types.go | 4 ++++ control-plane/api/v1alpha1/servicerouter_types_test.go | 4 ++++ control-plane/api/v1alpha1/zz_generated.deepcopy.go | 5 +++++ .../crd/bases/consul.hashicorp.com_servicerouters.yaml | 7 +++++++ 6 files changed, 30 insertions(+) create mode 100644 .changelog/3308.txt diff --git a/.changelog/3308.txt b/.changelog/3308.txt new file mode 100644 index 0000000000..a7fde80332 --- /dev/null +++ b/.changelog/3308.txt @@ -0,0 +1,3 @@ +```release-note:feature +crd: adds the [`retryOn`](https://developer.hashicorp.com/consul/docs/connect/config-entries/service-router#routes-destination-retryon) field to the ServiceRouter CRD. +``` diff --git a/charts/consul/templates/crd-servicerouters.yaml b/charts/consul/templates/crd-servicerouters.yaml index f28da9e7c1..4df097a70a 100644 --- a/charts/consul/templates/crd-servicerouters.yaml +++ b/charts/consul/templates/crd-servicerouters.yaml @@ -150,6 +150,13 @@ spec: any existing header values of the same name. type: object type: object + retryOn: + description: RetryOn is a flat list of conditions for Consul + to retry requests based on the response from an upstream + service. + items: + type: string + type: array retryOnConnectFailure: description: RetryOnConnectFailure allows for connection failure errors to trigger a retry. diff --git a/control-plane/api/v1alpha1/servicerouter_types.go b/control-plane/api/v1alpha1/servicerouter_types.go index ffc5dea03b..7ab1e13693 100644 --- a/control-plane/api/v1alpha1/servicerouter_types.go +++ b/control-plane/api/v1alpha1/servicerouter_types.go @@ -148,6 +148,9 @@ type ServiceRouteDestination struct { NumRetries uint32 `json:"numRetries,omitempty"` // RetryOnConnectFailure allows for connection failure errors to trigger a retry. RetryOnConnectFailure bool `json:"retryOnConnectFailure,omitempty"` + // RetryOn is a flat list of conditions for Consul to retry requests based on the response from an upstream service. + // Refer to the valid conditions here: https://developer.hashicorp.com/consul/docs/connect/config-entries/service-router#routes-destination-retryon + RetryOn []string `json:"retryOn,omitempty"` // RetryOnStatusCodes is a flat list of http response status codes that are eligible for retry. RetryOnStatusCodes []uint32 `json:"retryOnStatusCodes,omitempty"` // Allow HTTP header manipulation to be configured. @@ -352,6 +355,7 @@ func (in *ServiceRouteDestination) toConsul() *capi.ServiceRouteDestination { RequestTimeout: in.RequestTimeout.Duration, NumRetries: in.NumRetries, RetryOnConnectFailure: in.RetryOnConnectFailure, + RetryOn: in.RetryOn, RetryOnStatusCodes: in.RetryOnStatusCodes, RequestHeaders: in.RequestHeaders.toConsul(), ResponseHeaders: in.ResponseHeaders.toConsul(), diff --git a/control-plane/api/v1alpha1/servicerouter_types_test.go b/control-plane/api/v1alpha1/servicerouter_types_test.go index e6ffe20aca..134dcd6601 100644 --- a/control-plane/api/v1alpha1/servicerouter_types_test.go +++ b/control-plane/api/v1alpha1/servicerouter_types_test.go @@ -84,6 +84,7 @@ func TestServiceRouter_MatchesConsul(t *testing.T) { RequestTimeout: metav1.Duration{Duration: 1 * time.Second}, NumRetries: 1, RetryOnConnectFailure: true, + RetryOn: []string{"gateway-error"}, RetryOnStatusCodes: []uint32{500, 400}, RequestHeaders: &HTTPHeaderModifiers{ Add: map[string]string{ @@ -162,6 +163,7 @@ func TestServiceRouter_MatchesConsul(t *testing.T) { RequestTimeout: 1 * time.Second, NumRetries: 1, RetryOnConnectFailure: true, + RetryOn: []string{"gateway-error"}, RetryOnStatusCodes: []uint32{500, 400}, RequestHeaders: &capi.HTTPHeaderModifiers{ Add: map[string]string{ @@ -288,6 +290,7 @@ func TestServiceRouter_ToConsul(t *testing.T) { RequestTimeout: metav1.Duration{Duration: 1 * time.Second}, NumRetries: 1, RetryOnConnectFailure: true, + RetryOn: []string{"gateway-error"}, RetryOnStatusCodes: []uint32{500, 400}, RequestHeaders: &HTTPHeaderModifiers{ Add: map[string]string{ @@ -365,6 +368,7 @@ func TestServiceRouter_ToConsul(t *testing.T) { RequestTimeout: 1 * time.Second, NumRetries: 1, RetryOnConnectFailure: true, + RetryOn: []string{"gateway-error"}, RetryOnStatusCodes: []uint32{500, 400}, RequestHeaders: &capi.HTTPHeaderModifiers{ Add: map[string]string{ diff --git a/control-plane/api/v1alpha1/zz_generated.deepcopy.go b/control-plane/api/v1alpha1/zz_generated.deepcopy.go index 6436936b27..74b4297037 100644 --- a/control-plane/api/v1alpha1/zz_generated.deepcopy.go +++ b/control-plane/api/v1alpha1/zz_generated.deepcopy.go @@ -1807,6 +1807,11 @@ func (in *ServiceRouteDestination) DeepCopyInto(out *ServiceRouteDestination) { *out = *in out.IdleTimeout = in.IdleTimeout out.RequestTimeout = in.RequestTimeout + if in.RetryOn != nil { + in, out := &in.RetryOn, &out.RetryOn + *out = make([]string, len(*in)) + copy(*out, *in) + } if in.RetryOnStatusCodes != nil { in, out := &in.RetryOnStatusCodes, &out.RetryOnStatusCodes *out = make([]uint32, len(*in)) diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_servicerouters.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_servicerouters.yaml index 8b55692bd2..049f202488 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_servicerouters.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_servicerouters.yaml @@ -143,6 +143,13 @@ spec: any existing header values of the same name. type: object type: object + retryOn: + description: RetryOn is a flat list of conditions for Consul + to retry requests based on the response from an upstream + service. + items: + type: string + type: array retryOnConnectFailure: description: RetryOnConnectFailure allows for connection failure errors to trigger a retry.