Skip to content

Commit 260d716

Browse files
authored
Add client-body-buffer-size directive to VirtualServer (#8557)
1 parent 9ea74f1 commit 260d716

File tree

13 files changed

+127
-0
lines changed

13 files changed

+127
-0
lines changed

config/crd/bases/k8s.nginx.org_virtualserverroutes.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,13 @@ spec:
878878
is enabled. The default is set in the proxy-busy-buffers-size
879879
ConfigMap key.'
880880
type: string
881+
client-body-buffer-size:
882+
description: |-
883+
ClientBodyBufferSize sets the size of the buffer used for reading the client request body. Must be specified as a number followed by:
884+
'k' for kilobytes or 'm' for megabytes.
885+
Examples: "10m" or "512k".
886+
pattern: ^\d+[kKmM]?$
887+
type: string
881888
client-max-body-size:
882889
description: Sets the maximum allowed size of the client request
883890
body. The default is set in the client-max-body-size ConfigMap

config/crd/bases/k8s.nginx.org_virtualservers.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,13 @@ spec:
10671067
is enabled. The default is set in the proxy-busy-buffers-size
10681068
ConfigMap key.'
10691069
type: string
1070+
client-body-buffer-size:
1071+
description: |-
1072+
ClientBodyBufferSize sets the size of the buffer used for reading the client request body. Must be specified as a number followed by:
1073+
'k' for kilobytes or 'm' for megabytes.
1074+
Examples: "10m" or "512k".
1075+
pattern: ^\d+[kKmM]?$
1076+
type: string
10701077
client-max-body-size:
10711078
description: Sets the maximum allowed size of the client request
10721079
body. The default is set in the client-max-body-size ConfigMap

deploy/crds.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,6 +1916,13 @@ spec:
19161916
is enabled. The default is set in the proxy-busy-buffers-size
19171917
ConfigMap key.'
19181918
type: string
1919+
client-body-buffer-size:
1920+
description: |-
1921+
ClientBodyBufferSize sets the size of the buffer used for reading the client request body. Must be specified as a number followed by:
1922+
'k' for kilobytes or 'm' for megabytes.
1923+
Examples: "10m" or "512k".
1924+
pattern: ^\d+[kKmM]?$
1925+
type: string
19191926
client-max-body-size:
19201927
description: Sets the maximum allowed size of the client request
19211928
body. The default is set in the client-max-body-size ConfigMap
@@ -3335,6 +3342,13 @@ spec:
33353342
is enabled. The default is set in the proxy-busy-buffers-size
33363343
ConfigMap key.'
33373344
type: string
3345+
client-body-buffer-size:
3346+
description: |-
3347+
ClientBodyBufferSize sets the size of the buffer used for reading the client request body. Must be specified as a number followed by:
3348+
'k' for kilobytes or 'm' for megabytes.
3349+
Examples: "10m" or "512k".
3350+
pattern: ^\d+[kKmM]?$
3351+
type: string
33383352
client-max-body-size:
33393353
description: Sets the maximum allowed size of the client request
33403354
body. The default is set in the client-max-body-size ConfigMap

docs/crd/k8s.nginx.org_virtualserverroutes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ The `.spec` object supports the following fields:
169169
| `upstreams[].buffers.number` | `integer` | Configures the number of buffers. The default is set in the proxy-buffers ConfigMap key. |
170170
| `upstreams[].buffers.size` | `string` | Configures the size of a buffer. The default is set in the proxy-buffers ConfigMap key. |
171171
| `upstreams[].busy-buffers-size` | `string` | Sets the size of the buffers used for reading a response from the upstream server when the proxy_buffering is enabled. The default is set in the proxy-busy-buffers-size ConfigMap key.' |
172+
| `upstreams[].client-body-buffer-size` | `string` | ClientBodyBufferSize sets the size of the buffer used for reading the client request body. Must be specified as a number followed by: 'k' for kilobytes or 'm' for megabytes. Examples: "10m" or "512k". |
172173
| `upstreams[].client-max-body-size` | `string` | Sets the maximum allowed size of the client request body. The default is set in the client-max-body-size ConfigMap key. |
173174
| `upstreams[].connect-timeout` | `string` | The timeout for establishing a connection with an upstream server. The default is specified in the proxy-connect-timeout ConfigMap key. |
174175
| `upstreams[].fail-timeout` | `string` | The time during which the specified number of unsuccessful attempts to communicate with an upstream server should happen to consider the server unavailable. The default is set in the fail-timeout ConfigMap key. |

docs/crd/k8s.nginx.org_virtualservers.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ The `.spec` object supports the following fields:
204204
| `upstreams[].buffers.number` | `integer` | Configures the number of buffers. The default is set in the proxy-buffers ConfigMap key. |
205205
| `upstreams[].buffers.size` | `string` | Configures the size of a buffer. The default is set in the proxy-buffers ConfigMap key. |
206206
| `upstreams[].busy-buffers-size` | `string` | Sets the size of the buffers used for reading a response from the upstream server when the proxy_buffering is enabled. The default is set in the proxy-busy-buffers-size ConfigMap key.' |
207+
| `upstreams[].client-body-buffer-size` | `string` | ClientBodyBufferSize sets the size of the buffer used for reading the client request body. Must be specified as a number followed by: 'k' for kilobytes or 'm' for megabytes. Examples: "10m" or "512k". |
207208
| `upstreams[].client-max-body-size` | `string` | Sets the maximum allowed size of the client request body. The default is set in the client-max-body-size ConfigMap key. |
208209
| `upstreams[].connect-timeout` | `string` | The timeout for establishing a connection with an upstream server. The default is specified in the proxy-connect-timeout ConfigMap key. |
209210
| `upstreams[].fail-timeout` | `string` | The time during which the specified number of unsuccessful attempts to communicate with an upstream server should happen to consider the server unavailable. The default is set in the fail-timeout ConfigMap key. |

internal/configs/version2/__snapshots__/templates_test.snap

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,6 +1876,56 @@ server {
18761876

18771877
---
18781878

1879+
[TestExecuteVirtualServerTemplate_RendersTemplateWithClientBodyBufferSize - 1]
1880+
1881+
1882+
server {
1883+
listen 80;
1884+
listen [::]:80;
1885+
1886+
1887+
server_name example.com;
1888+
status_zone example.com;
1889+
set $resource_type "virtualserver";
1890+
set $resource_name "";
1891+
set $resource_namespace "";
1892+
1893+
server_tokens "";
1894+
1895+
1896+
1897+
1898+
location / {
1899+
set $service "";
1900+
status_zone "";
1901+
1902+
1903+
set $default_connection_header close;
1904+
proxy_connect_timeout ;
1905+
proxy_read_timeout ;
1906+
proxy_send_timeout ;
1907+
client_max_body_size ;
1908+
client_body_buffer_size 16k;
1909+
1910+
proxy_buffering off;
1911+
proxy_http_version 1.1;
1912+
proxy_set_header Upgrade $http_upgrade;
1913+
proxy_set_header Connection $vs_connection_header;
1914+
proxy_pass_request_headers off;
1915+
proxy_set_header X-Real-IP $remote_addr;
1916+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
1917+
proxy_set_header X-Forwarded-Host $host;
1918+
proxy_set_header X-Forwarded-Port $server_port;
1919+
proxy_set_header X-Forwarded-Proto $scheme;
1920+
proxy_pass http://test-upstream;
1921+
proxy_next_upstream ;
1922+
proxy_next_upstream_timeout ;
1923+
proxy_next_upstream_tries 0;
1924+
}
1925+
}
1926+
1927+
---
1928+
18791929
[TestExecuteVirtualServerTemplate_RendersTemplateWithCustomListener - 1]
18801930

18811931

internal/configs/version2/http.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ type Location struct {
198198
ProxyReadTimeout string
199199
ProxySendTimeout string
200200
ClientMaxBodySize string
201+
ClientBodyBufferSize string
201202
ProxyMaxTempFileSize string
202203
ProxyBuffering bool
203204
ProxyBuffers string

internal/configs/version2/nginx-plus.virtualserver.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,9 @@ server {
674674
{{ $proxyOrGRPC }}_read_timeout {{ $l.ProxyReadTimeout }};
675675
{{ $proxyOrGRPC }}_send_timeout {{ $l.ProxySendTimeout }};
676676
client_max_body_size {{ $l.ClientMaxBodySize }};
677+
{{- if $l.ClientBodyBufferSize }}
678+
client_body_buffer_size {{ $l.ClientBodyBufferSize }};
679+
{{- end }}
677680

678681
{{- if $l.ProxyMaxTempFileSize }}
679682
proxy_max_temp_file_size {{ $l.ProxyMaxTempFileSize }};

internal/configs/version2/nginx.virtualserver.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,9 @@ server {
368368
{{ $proxyOrGRPC }}_read_timeout {{ $l.ProxyReadTimeout }};
369369
{{ $proxyOrGRPC }}_send_timeout {{ $l.ProxySendTimeout }};
370370
client_max_body_size {{ $l.ClientMaxBodySize }};
371+
{{- if $l.ClientBodyBufferSize }}
372+
client_body_buffer_size {{ $l.ClientBodyBufferSize }};
373+
{{- end }}
371374

372375
{{- if $l.ProxyMaxTempFileSize }}
373376
proxy_max_temp_file_size {{ $l.ProxyMaxTempFileSize }};

internal/configs/version2/templates_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,21 @@ func TestExecuteVirtualServerTemplate_RendersPlusTemplateWithHTTP2Off(t *testing
440440
t.Log(string(got))
441441
}
442442

443+
func TestExecuteVirtualServerTemplate_RendersTemplateWithClientBodyBufferSize(t *testing.T) {
444+
t.Parallel()
445+
executor := newTmplExecutorNGINXPlus(t)
446+
447+
got, err := executor.ExecuteVirtualServerTemplate(&virtualServerCfgWithClientBodyBufferSize)
448+
if err != nil {
449+
t.Error(err)
450+
}
451+
if !bytes.Contains(got, []byte("client_body_buffer_size 16k;")) {
452+
t.Error("want `client_body_buffer_size 16k;` directive in generated template")
453+
}
454+
snaps.MatchSnapshot(t, string(got))
455+
t.Log(string(got))
456+
}
457+
443458
func TestExecuteVirtualServerTemplate_RendersOSSTemplateWithHTTP2On(t *testing.T) {
444459
t.Parallel()
445460
executor := newTmplExecutorNGINX(t)
@@ -2171,6 +2186,20 @@ var (
21712186
},
21722187
}
21732188

2189+
virtualServerCfgWithClientBodyBufferSize = VirtualServerConfig{
2190+
Server: Server{
2191+
ServerName: "example.com",
2192+
StatusZone: "example.com",
2193+
Locations: []Location{
2194+
{
2195+
Path: "/",
2196+
ProxyPass: "http://test-upstream",
2197+
ClientBodyBufferSize: "16k",
2198+
},
2199+
},
2200+
},
2201+
}
2202+
21742203
virtualServerCfgWithRateLimitJWTClaim = VirtualServerConfig{
21752204
LimitReqZones: []LimitReqZone{
21762205
{

0 commit comments

Comments
 (0)