diff --git a/apisx/v1alpha1/xbackendtrafficpolicy_types.go b/apisx/v1alpha1/xbackendtrafficpolicy_types.go index 17a9d6e1c6..6d7af56dee 100644 --- a/apisx/v1alpha1/xbackendtrafficpolicy_types.go +++ b/apisx/v1alpha1/xbackendtrafficpolicy_types.go @@ -119,26 +119,11 @@ type BackendTrafficPolicySpec struct { // RetryConstraint defines the configuration for when to retry a request. type RetryConstraint struct { - // BudgetPercent defines the maximum percentage of active requests that may - // be made up of retries. - // - // Support: Extended - // - // +optional - // +kubebuilder:default=20 - // +kubebuilder:validation:Minimum=0 - // +kubebuilder:validation:Maximum=100 - BudgetPercent *int `json:"budgetPercent,omitempty"` - - // BudgetInterval defines the duration in which requests will be considered - // for calculating the budget for retries. - // - // Support: Extended + // Budget holds the details of the retry budget configuration. // // +optional - // +kubebuilder:default="10s" - // +kubebuilder:validation:XValidation:message="budgetInterval can not be greater than one hour or less than one second",rule="!(duration(self) < duration('1s') || duration(self) > duration('1h'))" - BudgetInterval *Duration `json:"budgetInterval,omitempty"` + // +kubebuilder:default={percent: 20, interval: "10s"} + Budget *BudgetDetails `json:"budget,omitempty"` // MinRetryRate defines the minimum rate of retries that will be allowable // over a specified duration of time. @@ -157,3 +142,29 @@ type RetryConstraint struct { // +kubebuilder:default={count: 10, interval: "1s"} MinRetryRate *RequestRate `json:"minRetryRate,omitempty"` } + +// BudgetDetails specifies the details of the budget configuration, like +// the percentage of requests in the budget, and the interval between +// checks. +type BudgetDetails struct { + // BudgetPercent defines the maximum percentage of active requests that may + // be made up of retries. + // + // Support: Extended + // + // +optional + // +kubebuilder:default=20 + // +kubebuilder:validation:Minimum=0 + // +kubebuilder:validation:Maximum=100 + Percent *int `json:"percent,omitempty"` + + // BudgetInterval defines the duration in which requests will be considered + // for calculating the budget for retries. + // + // Support: Extended + // + // +optional + // +kubebuilder:default="10s" + // +kubebuilder:validation:XValidation:message="budgetInterval can not be greater than one hour or less than one second",rule="!(duration(self) < duration('1s') || duration(self) > duration('1h'))" + Interval *Duration `json:"interval,omitempty"` +} diff --git a/apisx/v1alpha1/zz_generated.deepcopy.go b/apisx/v1alpha1/zz_generated.deepcopy.go index 5941c061c5..0f201b5027 100644 --- a/apisx/v1alpha1/zz_generated.deepcopy.go +++ b/apisx/v1alpha1/zz_generated.deepcopy.go @@ -57,6 +57,31 @@ func (in *BackendTrafficPolicySpec) DeepCopy() *BackendTrafficPolicySpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BudgetDetails) DeepCopyInto(out *BudgetDetails) { + *out = *in + if in.Percent != nil { + in, out := &in.Percent, &out.Percent + *out = new(int) + **out = **in + } + if in.Interval != nil { + in, out := &in.Interval, &out.Interval + *out = new(v1.Duration) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BudgetDetails. +func (in *BudgetDetails) DeepCopy() *BudgetDetails { + if in == nil { + return nil + } + out := new(BudgetDetails) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ListenerEntry) DeepCopyInto(out *ListenerEntry) { *out = *in @@ -226,15 +251,10 @@ func (in *RequestRate) DeepCopy() *RequestRate { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *RetryConstraint) DeepCopyInto(out *RetryConstraint) { *out = *in - if in.BudgetPercent != nil { - in, out := &in.BudgetPercent, &out.BudgetPercent - *out = new(int) - **out = **in - } - if in.BudgetInterval != nil { - in, out := &in.BudgetInterval, &out.BudgetInterval - *out = new(v1.Duration) - **out = **in + if in.Budget != nil { + in, out := &in.Budget, &out.Budget + *out = new(BudgetDetails) + (*in).DeepCopyInto(*out) } if in.MinRetryRate != nil { in, out := &in.MinRetryRate, &out.MinRetryRate diff --git a/applyconfiguration/apisx/v1alpha1/budgetdetails.go b/applyconfiguration/apisx/v1alpha1/budgetdetails.go new file mode 100644 index 0000000000..573934c748 --- /dev/null +++ b/applyconfiguration/apisx/v1alpha1/budgetdetails.go @@ -0,0 +1,52 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1 "sigs.k8s.io/gateway-api/apis/v1" +) + +// BudgetDetailsApplyConfiguration represents a declarative configuration of the BudgetDetails type for use +// with apply. +type BudgetDetailsApplyConfiguration struct { + Percent *int `json:"percent,omitempty"` + Interval *v1.Duration `json:"interval,omitempty"` +} + +// BudgetDetailsApplyConfiguration constructs a declarative configuration of the BudgetDetails type for use with +// apply. +func BudgetDetails() *BudgetDetailsApplyConfiguration { + return &BudgetDetailsApplyConfiguration{} +} + +// WithPercent sets the Percent field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Percent field is set to the value of the last call. +func (b *BudgetDetailsApplyConfiguration) WithPercent(value int) *BudgetDetailsApplyConfiguration { + b.Percent = &value + return b +} + +// WithInterval sets the Interval field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Interval field is set to the value of the last call. +func (b *BudgetDetailsApplyConfiguration) WithInterval(value v1.Duration) *BudgetDetailsApplyConfiguration { + b.Interval = &value + return b +} diff --git a/applyconfiguration/apisx/v1alpha1/retryconstraint.go b/applyconfiguration/apisx/v1alpha1/retryconstraint.go index 4248ea83fc..05c7ac5941 100644 --- a/applyconfiguration/apisx/v1alpha1/retryconstraint.go +++ b/applyconfiguration/apisx/v1alpha1/retryconstraint.go @@ -18,16 +18,11 @@ limitations under the License. package v1alpha1 -import ( - v1 "sigs.k8s.io/gateway-api/apis/v1" -) - // RetryConstraintApplyConfiguration represents a declarative configuration of the RetryConstraint type for use // with apply. type RetryConstraintApplyConfiguration struct { - BudgetPercent *int `json:"budgetPercent,omitempty"` - BudgetInterval *v1.Duration `json:"budgetInterval,omitempty"` - MinRetryRate *RequestRateApplyConfiguration `json:"minRetryRate,omitempty"` + Budget *BudgetDetailsApplyConfiguration `json:"budget,omitempty"` + MinRetryRate *RequestRateApplyConfiguration `json:"minRetryRate,omitempty"` } // RetryConstraintApplyConfiguration constructs a declarative configuration of the RetryConstraint type for use with @@ -36,19 +31,11 @@ func RetryConstraint() *RetryConstraintApplyConfiguration { return &RetryConstraintApplyConfiguration{} } -// WithBudgetPercent sets the BudgetPercent field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the BudgetPercent field is set to the value of the last call. -func (b *RetryConstraintApplyConfiguration) WithBudgetPercent(value int) *RetryConstraintApplyConfiguration { - b.BudgetPercent = &value - return b -} - -// WithBudgetInterval sets the BudgetInterval field in the declarative configuration to the given value +// WithBudget sets the Budget field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the BudgetInterval field is set to the value of the last call. -func (b *RetryConstraintApplyConfiguration) WithBudgetInterval(value v1.Duration) *RetryConstraintApplyConfiguration { - b.BudgetInterval = &value +// If called multiple times, the Budget field is set to the value of the last call. +func (b *RetryConstraintApplyConfiguration) WithBudget(value *BudgetDetailsApplyConfiguration) *RetryConstraintApplyConfiguration { + b.Budget = value return b } diff --git a/applyconfiguration/internal/internal.go b/applyconfiguration/internal/internal.go index b42032c934..447d5f90b7 100644 --- a/applyconfiguration/internal/internal.go +++ b/applyconfiguration/internal/internal.go @@ -1765,6 +1765,15 @@ var schemaYAML = typed.YAMLObject(`types: - group - kind - name +- name: io.k8s.sigs.gateway-api.apisx.v1alpha1.BudgetDetails + map: + fields: + - name: interval + type: + scalar: string + - name: percent + type: + scalar: numeric - name: io.k8s.sigs.gateway-api.apisx.v1alpha1.ListenerEntry map: fields: @@ -1879,12 +1888,9 @@ var schemaYAML = typed.YAMLObject(`types: - name: io.k8s.sigs.gateway-api.apisx.v1alpha1.RetryConstraint map: fields: - - name: budgetInterval + - name: budget type: - scalar: string - - name: budgetPercent - type: - scalar: numeric + namedType: io.k8s.sigs.gateway-api.apisx.v1alpha1.BudgetDetails - name: minRetryRate type: namedType: io.k8s.sigs.gateway-api.apisx.v1alpha1.RequestRate diff --git a/applyconfiguration/utils.go b/applyconfiguration/utils.go index d26fd42311..1982019b84 100644 --- a/applyconfiguration/utils.go +++ b/applyconfiguration/utils.go @@ -236,6 +236,8 @@ func ForKind(kind schema.GroupVersionKind) interface{} { // Group=gateway.networking.x-k8s.io, Version=v1alpha1 case v1alpha1.SchemeGroupVersion.WithKind("BackendTrafficPolicySpec"): return &apisxv1alpha1.BackendTrafficPolicySpecApplyConfiguration{} + case v1alpha1.SchemeGroupVersion.WithKind("BudgetDetails"): + return &apisxv1alpha1.BudgetDetailsApplyConfiguration{} case v1alpha1.SchemeGroupVersion.WithKind("ListenerEntry"): return &apisxv1alpha1.ListenerEntryApplyConfiguration{} case v1alpha1.SchemeGroupVersion.WithKind("ListenerEntryStatus"): diff --git a/config/crd/experimental/gateway.networking.x-k8s.io_xbackendtrafficpolicies.yaml b/config/crd/experimental/gateway.networking.x-k8s.io_xbackendtrafficpolicies.yaml index 9ea687fcf1..abbfb33c93 100644 --- a/config/crd/experimental/gateway.networking.x-k8s.io_xbackendtrafficpolicies.yaml +++ b/config/crd/experimental/gateway.networking.x-k8s.io_xbackendtrafficpolicies.yaml @@ -85,30 +85,37 @@ spec: Support: Extended properties: - budgetInterval: - default: 10s - description: |- - BudgetInterval defines the duration in which requests will be considered - for calculating the budget for retries. + budget: + default: + interval: 10s + percent: 20 + description: Budget holds the details of the retry budget configuration. + properties: + interval: + default: 10s + description: |- + BudgetInterval defines the duration in which requests will be considered + for calculating the budget for retries. - Support: Extended - pattern: ^([0-9]{1,5}(h|m|s|ms)){1,4}$ - type: string - x-kubernetes-validations: - - message: budgetInterval can not be greater than one hour or - less than one second - rule: '!(duration(self) < duration(''1s'') || duration(self) - > duration(''1h''))' - budgetPercent: - default: 20 - description: |- - BudgetPercent defines the maximum percentage of active requests that may - be made up of retries. + Support: Extended + pattern: ^([0-9]{1,5}(h|m|s|ms)){1,4}$ + type: string + x-kubernetes-validations: + - message: budgetInterval can not be greater than one hour + or less than one second + rule: '!(duration(self) < duration(''1s'') || duration(self) + > duration(''1h''))' + percent: + default: 20 + description: |- + BudgetPercent defines the maximum percentage of active requests that may + be made up of retries. - Support: Extended - maximum: 100 - minimum: 0 - type: integer + Support: Extended + maximum: 100 + minimum: 0 + type: integer + type: object minRetryRate: default: count: 10 diff --git a/pkg/generated/openapi/zz_generated.openapi.go b/pkg/generated/openapi/zz_generated.openapi.go index 380ebc62a6..e7934cfc66 100644 --- a/pkg/generated/openapi/zz_generated.openapi.go +++ b/pkg/generated/openapi/zz_generated.openapi.go @@ -193,6 +193,7 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "sigs.k8s.io/gateway-api/apis/v1beta1.ReferenceGrantSpec": schema_sigsk8sio_gateway_api_apis_v1beta1_ReferenceGrantSpec(ref), "sigs.k8s.io/gateway-api/apis/v1beta1.ReferenceGrantTo": schema_sigsk8sio_gateway_api_apis_v1beta1_ReferenceGrantTo(ref), "sigs.k8s.io/gateway-api/apisx/v1alpha1.BackendTrafficPolicySpec": schema_sigsk8sio_gateway_api_apisx_v1alpha1_BackendTrafficPolicySpec(ref), + "sigs.k8s.io/gateway-api/apisx/v1alpha1.BudgetDetails": schema_sigsk8sio_gateway_api_apisx_v1alpha1_BudgetDetails(ref), "sigs.k8s.io/gateway-api/apisx/v1alpha1.ListenerEntry": schema_sigsk8sio_gateway_api_apisx_v1alpha1_ListenerEntry(ref), "sigs.k8s.io/gateway-api/apisx/v1alpha1.ListenerEntryStatus": schema_sigsk8sio_gateway_api_apisx_v1alpha1_ListenerEntryStatus(ref), "sigs.k8s.io/gateway-api/apisx/v1alpha1.ListenerSetSpec": schema_sigsk8sio_gateway_api_apisx_v1alpha1_ListenerSetSpec(ref), @@ -7837,6 +7838,33 @@ func schema_sigsk8sio_gateway_api_apisx_v1alpha1_BackendTrafficPolicySpec(ref co } } +func schema_sigsk8sio_gateway_api_apisx_v1alpha1_BudgetDetails(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "BudgetDetails specifies the details of the budget configuration, like the percentage of requests in the budget, and the interval between checks.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "percent": { + SchemaProps: spec.SchemaProps{ + Description: "BudgetPercent defines the maximum percentage of active requests that may be made up of retries.\n\nSupport: Extended", + Type: []string{"integer"}, + Format: "int32", + }, + }, + "interval": { + SchemaProps: spec.SchemaProps{ + Description: "BudgetInterval defines the duration in which requests will be considered for calculating the budget for retries.\n\nSupport: Extended", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + } +} + func schema_sigsk8sio_gateway_api_apisx_v1alpha1_ListenerEntry(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -8150,18 +8178,10 @@ func schema_sigsk8sio_gateway_api_apisx_v1alpha1_RetryConstraint(ref common.Refe Description: "RetryConstraint defines the configuration for when to retry a request.", Type: []string{"object"}, Properties: map[string]spec.Schema{ - "budgetPercent": { + "budget": { SchemaProps: spec.SchemaProps{ - Description: "BudgetPercent defines the maximum percentage of active requests that may be made up of retries.\n\nSupport: Extended", - Type: []string{"integer"}, - Format: "int32", - }, - }, - "budgetInterval": { - SchemaProps: spec.SchemaProps{ - Description: "BudgetInterval defines the duration in which requests will be considered for calculating the budget for retries.\n\nSupport: Extended", - Type: []string{"string"}, - Format: "", + Description: "Budget holds the details of the retry budget configuration.", + Ref: ref("sigs.k8s.io/gateway-api/apisx/v1alpha1.BudgetDetails"), }, }, "minRetryRate": { @@ -8174,7 +8194,7 @@ func schema_sigsk8sio_gateway_api_apisx_v1alpha1_RetryConstraint(ref common.Refe }, }, Dependencies: []string{ - "sigs.k8s.io/gateway-api/apisx/v1alpha1.RequestRate"}, + "sigs.k8s.io/gateway-api/apisx/v1alpha1.BudgetDetails", "sigs.k8s.io/gateway-api/apisx/v1alpha1.RequestRate"}, } } diff --git a/pkg/test/cel/backendtrafficpolicy_test.go b/pkg/test/cel/backendtrafficpolicy_test.go index 0f2c45e9a6..443b82bf26 100644 --- a/pkg/test/cel/backendtrafficpolicy_test.go +++ b/pkg/test/cel/backendtrafficpolicy_test.go @@ -45,7 +45,9 @@ func TestBackendTrafficPolicyConfig(t *testing.T) { Type: ptrTo(gatewayv1.CookieBasedSessionPersistence), }, retryConstraint: xgatewayv1alpha1.RetryConstraint{ - BudgetInterval: toDuration("10s"), + Budget: ptrTo(xgatewayv1alpha1.BudgetDetails{ + Interval: toDuration("10s"), + }), MinRetryRate: ptrTo(xgatewayv1alpha1.RequestRate{ Count: ptrTo(10), Interval: toDuration("1s"), @@ -61,7 +63,9 @@ func TestBackendTrafficPolicyConfig(t *testing.T) { Type: ptrTo(gatewayv1.CookieBasedSessionPersistence), }, retryConstraint: xgatewayv1alpha1.RetryConstraint{ - BudgetPercent: ptrTo(20), + Budget: ptrTo(xgatewayv1alpha1.BudgetDetails{ + Percent: ptrTo(20), + }), MinRetryRate: ptrTo(xgatewayv1alpha1.RequestRate{ Count: ptrTo(10), Interval: toDuration("1s"), @@ -77,8 +81,10 @@ func TestBackendTrafficPolicyConfig(t *testing.T) { Type: ptrTo(gatewayv1.CookieBasedSessionPersistence), }, retryConstraint: xgatewayv1alpha1.RetryConstraint{ - BudgetPercent: ptrTo(20), - BudgetInterval: toDuration("10s"), + Budget: ptrTo(xgatewayv1alpha1.BudgetDetails{ + Percent: ptrTo(20), + Interval: toDuration("10s"), + }), }, wantErrors: []string{}, }, @@ -90,8 +96,10 @@ func TestBackendTrafficPolicyConfig(t *testing.T) { Type: ptrTo(gatewayv1.CookieBasedSessionPersistence), }, retryConstraint: xgatewayv1alpha1.RetryConstraint{ - BudgetPercent: ptrTo(20), - BudgetInterval: toDuration("2h"), + Budget: ptrTo(xgatewayv1alpha1.BudgetDetails{ + Percent: ptrTo(20), + Interval: toDuration("2h"), + }), MinRetryRate: ptrTo(xgatewayv1alpha1.RequestRate{ Count: ptrTo(10), Interval: toDuration("10s"), @@ -107,8 +115,10 @@ func TestBackendTrafficPolicyConfig(t *testing.T) { Type: ptrTo(gatewayv1.CookieBasedSessionPersistence), }, retryConstraint: xgatewayv1alpha1.RetryConstraint{ - BudgetPercent: ptrTo(20), - BudgetInterval: toDuration("1ms"), + Budget: ptrTo(xgatewayv1alpha1.BudgetDetails{ + Percent: ptrTo(20), + Interval: toDuration("1ms"), + }), MinRetryRate: ptrTo(xgatewayv1alpha1.RequestRate{ Count: ptrTo(10), Interval: toDuration("10s"), @@ -124,8 +134,10 @@ func TestBackendTrafficPolicyConfig(t *testing.T) { Type: ptrTo(gatewayv1.CookieBasedSessionPersistence), }, retryConstraint: xgatewayv1alpha1.RetryConstraint{ - BudgetPercent: ptrTo(20), - BudgetInterval: toDuration("10s"), + Budget: ptrTo(xgatewayv1alpha1.BudgetDetails{ + Percent: ptrTo(20), + Interval: toDuration("10s"), + }), MinRetryRate: ptrTo(xgatewayv1alpha1.RequestRate{ Count: ptrTo(10), Interval: toDuration("2h"), @@ -141,8 +153,10 @@ func TestBackendTrafficPolicyConfig(t *testing.T) { Type: ptrTo(gatewayv1.CookieBasedSessionPersistence), }, retryConstraint: xgatewayv1alpha1.RetryConstraint{ - BudgetPercent: ptrTo(20), - BudgetInterval: toDuration("10s"), + Budget: ptrTo(xgatewayv1alpha1.BudgetDetails{ + Percent: ptrTo(20), + Interval: toDuration("10s"), + }), MinRetryRate: ptrTo(xgatewayv1alpha1.RequestRate{ Count: ptrTo(10), Interval: toDuration("1s"), @@ -160,8 +174,10 @@ func TestBackendTrafficPolicyConfig(t *testing.T) { }, }, retryConstraint: xgatewayv1alpha1.RetryConstraint{ - BudgetPercent: ptrTo(20), - BudgetInterval: toDuration("10s"), + Budget: ptrTo(xgatewayv1alpha1.BudgetDetails{ + Percent: ptrTo(20), + Interval: toDuration("10s"), + }), MinRetryRate: ptrTo(xgatewayv1alpha1.RequestRate{ Count: ptrTo(10), Interval: toDuration("1s"), @@ -179,8 +195,10 @@ func TestBackendTrafficPolicyConfig(t *testing.T) { }, }, retryConstraint: xgatewayv1alpha1.RetryConstraint{ - BudgetPercent: ptrTo(20), - BudgetInterval: toDuration("10s"), + Budget: ptrTo(xgatewayv1alpha1.BudgetDetails{ + Percent: ptrTo(20), + Interval: toDuration("10s"), + }), MinRetryRate: ptrTo(xgatewayv1alpha1.RequestRate{ Count: ptrTo(10), Interval: toDuration("1s"), @@ -199,8 +217,10 @@ func TestBackendTrafficPolicyConfig(t *testing.T) { }, }, retryConstraint: xgatewayv1alpha1.RetryConstraint{ - BudgetPercent: ptrTo(20), - BudgetInterval: toDuration("10s"), + Budget: ptrTo(xgatewayv1alpha1.BudgetDetails{ + Percent: ptrTo(20), + Interval: toDuration("10s"), + }), MinRetryRate: ptrTo(xgatewayv1alpha1.RequestRate{ Count: ptrTo(10), Interval: toDuration("1s"), @@ -215,8 +235,10 @@ func TestBackendTrafficPolicyConfig(t *testing.T) { Type: ptrTo(gatewayv1.HeaderBasedSessionPersistence), }, retryConstraint: xgatewayv1alpha1.RetryConstraint{ - BudgetPercent: ptrTo(20), - BudgetInterval: toDuration("10s"), + Budget: ptrTo(xgatewayv1alpha1.BudgetDetails{ + Percent: ptrTo(20), + Interval: toDuration("10s"), + }), MinRetryRate: ptrTo(xgatewayv1alpha1.RequestRate{ Count: ptrTo(10), Interval: toDuration("1s"),