Skip to content

Commit

Permalink
api: add the buffer limit knob to the cluster (#3390)
Browse files Browse the repository at this point in the history
* api: add the buffer limit knob to the cluster

Signed-off-by: ShyunnY <1147212064@qq.com>

* fix: use simple fieldName

Signed-off-by: ShyunnY <1147212064@qq.com>

* fix: fix field

Signed-off-by: ShyunnY <1147212064@qq.com>

* fix

Signed-off-by: ShyunnY <1147212064@qq.com>

* fix: override a single field with a connection structured definition

Signed-off-by: ShyunnY <1147212064@qq.com>

* fix: fix gen-check

Signed-off-by: ShyunnY <1147212064@qq.com>

---------

Signed-off-by: ShyunnY <1147212064@qq.com>
  • Loading branch information
ShyunnY authored May 21, 2024
1 parent 566861c commit db90b07
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 0 deletions.
18 changes: 18 additions & 0 deletions api/v1alpha1/backendtrafficpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package v1alpha1

import (
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
)
Expand Down Expand Up @@ -103,6 +104,11 @@ type BackendTrafficPolicySpec struct {
// +optional
// +notImplementedHide
Compression []*Compression `json:"compression,omitempty"`

// Connection includes backend connection settings.
//
// +optional
Connection *BackendTrafficPolicyConnection `json:"connection,omitempty"`
}

// +kubebuilder:object:root=true
Expand All @@ -114,6 +120,18 @@ type BackendTrafficPolicyList struct {
Items []BackendTrafficPolicy `json:"items"`
}

// BackendTrafficPolicyConnection allows users to configure connection-level settings of backend
type BackendTrafficPolicyConnection struct {
// BufferLimit Soft limit on size of the cluster’s connections read and write buffers.
// If unspecified, an implementation defined default is applied (32768 bytes).
// For example, 20Mi, 1Gi, 256Ki etc.
// Note: that when the suffix is not provided, the value is interpreted as bytes.
//
// +kubebuilder:validation:XValidation:rule="type(self) == string ? self.matches(r\"^[1-9]+[0-9]*([EPTGMK]i|[EPTGMk])?$\") : type(self) == int",message="BufferLimit must be of the format \"^[1-9]+[0-9]*([EPTGMK]i|[EPTGMk])?$\""
// +optional
BufferLimit *resource.Quantity `json:"bufferLimit,omitempty"`
}

func init() {
SchemeBuilder.Register(&BackendTrafficPolicy{}, &BackendTrafficPolicyList{})
}
25 changes: 25 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,25 @@ spec:
- type
type: object
type: array
connection:
description: Connection includes backend connection settings.
properties:
bufferLimit:
anyOf:
- type: integer
- type: string
description: |-
BufferLimit Soft limit on size of the cluster’s connections read and write buffers.
If unspecified, an implementation defined default is applied (32768 bytes).
For example, 20Mi, 1Gi, 256Ki etc.
Note: that when the suffix is not provided, the value is interpreted as bytes.
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
x-kubernetes-validations:
- message: BufferLimit must be of the format "^[1-9]+[0-9]*([EPTGMK]i|[EPTGMk])?$"
rule: 'type(self) == string ? self.matches(r"^[1-9]+[0-9]*([EPTGMK]i|[EPTGMk])?$")
: type(self) == int'
type: object
faultInjection:
description: |-
FaultInjection defines the fault injection policy to be applied. This configuration can be used to
Expand Down
15 changes: 15 additions & 0 deletions site/content/en/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,20 @@ _Appears in:_
| `spec` | _[BackendTrafficPolicySpec](#backendtrafficpolicyspec)_ | true | spec defines the desired state of BackendTrafficPolicy. |


#### BackendTrafficPolicyConnection



BackendTrafficPolicyConnection allows users to configure connection-level settings of backend

_Appears in:_
- [BackendTrafficPolicySpec](#backendtrafficpolicyspec)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `bufferLimit` | _[Quantity](#quantity)_ | false | BufferLimit Soft limit on size of the cluster’s connections read and write buffers.<br />If unspecified, an implementation defined default is applied (32768 bytes).<br />For example, 20Mi, 1Gi, 256Ki etc.<br />Note: that when the suffix is not provided, the value is interpreted as bytes. |


#### BackendTrafficPolicyList


Expand Down Expand Up @@ -389,6 +403,7 @@ _Appears in:_
| `retry` | _[Retry](#retry)_ | false | Retry provides more advanced usage, allowing users to customize the number of retries, retry fallback strategy, and retry triggering conditions.<br />If not set, retry will be disabled. |
| `useClientProtocol` | _boolean_ | false | UseClientProtocol configures Envoy to prefer sending requests to backends using<br />the same HTTP protocol that the incoming request used. Defaults to false, which means<br />that Envoy will use the protocol indicated by the attached BackendRef. |
| `timeout` | _[Timeout](#timeout)_ | false | Timeout settings for the backend connections. |
| `connection` | _[BackendTrafficPolicyConnection](#backendtrafficpolicyconnection)_ | false | Connection includes backend connection settings. |


#### BasicAuth
Expand Down
38 changes: 38 additions & 0 deletions test/cel-validation/backendtrafficpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"testing"
"time"

"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
Expand Down Expand Up @@ -920,6 +921,43 @@ func TestBackendTrafficPolicyTarget(t *testing.T) {
`[spec.rateLimit.global.rules: Too many: 65: must have at most 64 items, <nil>: Invalid value: "null": some validation rules were not checked because the object was invalid; correct the existing errors to complete validation]`,
},
},
{
desc: "valid connectionBufferLimitBytes format",
mutate: func(btp *egv1a1.BackendTrafficPolicy) {
btp.Spec = egv1a1.BackendTrafficPolicySpec{
TargetRef: gwapiv1a2.LocalPolicyTargetReferenceWithSectionName{
LocalPolicyTargetReference: gwapiv1a2.LocalPolicyTargetReference{
Group: gwapiv1a2.Group("gateway.networking.k8s.io"),
Kind: gwapiv1a2.Kind("Gateway"),
Name: gwapiv1a2.ObjectName("eg"),
},
},
Connection: &egv1a1.BackendTrafficPolicyConnection{
BufferLimit: ptr.To(resource.MustParse("1Mi")),
},
}
},
},
{
desc: "invalid connectionBufferLimitBytes format",
mutate: func(btp *egv1a1.BackendTrafficPolicy) {
btp.Spec = egv1a1.BackendTrafficPolicySpec{
TargetRef: gwapiv1a2.LocalPolicyTargetReferenceWithSectionName{
LocalPolicyTargetReference: gwapiv1a2.LocalPolicyTargetReference{
Group: gwapiv1a2.Group("gateway.networking.k8s.io"),
Kind: gwapiv1a2.Kind("Gateway"),
Name: gwapiv1a2.ObjectName("eg"),
},
},
Connection: &egv1a1.BackendTrafficPolicyConnection{
BufferLimit: ptr.To(resource.MustParse("1m")),
},
}
},
wantErrors: []string{
"spec.connection.bufferLimit: Invalid value: \"\": BufferLimit must be of the format \"^[1-9]+[0-9]*([EPTGMK]i|[EPTGMk])?$\"",
},
},
}

for _, tc := range cases {
Expand Down

0 comments on commit db90b07

Please sign in to comment.