8000 Add ClientBodyMaxSize support in vs/vsr · nginx/kubernetes-ingress@ddd8023 · GitHub
[go: up one dir, main page]

Skip to content

Commit ddd8023

Browse files
committed
Add ClientBodyMaxSize support in vs/vsr
1 parent 08c4533 commit ddd8023

File tree

5 files changed

+61
-4
lines changed

5 files changed

+61
-4
lines changed

docs/virtualserver-and-virtualserverroute.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ send-timeout: 30s
191191
next-upstream: "error timeout non_idempotent"
192192
next-upstream-timeout: 5s
193193
next-upstream-tries: 10
194+
client-max-body-size: 2m
194195
tls:
195196
enable: True
196197
```
@@ -210,9 +211,10 @@ tls:
210211
| `connect-timeout` | The timeout for establishing a connection with an upstream server. See the [proxy_connect_timeout](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_connect_timeout) directive. The default is specified in the `proxy-connect-timeout` ConfigMap key. | `string` | No |
211212
| `read-timeout` | The timeout for reading a response from an upstream server. See the [proxy_read_timeout](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_read_timeout) directive. The default is specified in the `proxy-read-timeout` ConfigMap key. | `string` | No |
212213
| `send-timeout` | The timeout for transmitting a request to an upstream server. See the [proxy_send_timeout](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_send_timeout) directive. The default is specified in the `proxy-send-timeout` ConfigMap key. | `string` | No |
213-
| `next-upstream` | Specifies in which cases a request should be passed to the next upstream server. See the [proxy_next_upstream](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream) directive. The default is `error timeout`. | `string` | No |
214-
| `next-upstream-timeout` | The time during which a request can be passed to the next upstream server. See the [proxy_next_upstream_timeout](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream_timeout) directive. The `0` value turns off the time limit. The default is `0`. | `string` | No |
215-
| `next-upstream-tries` | The number of possible tries for passing a request to the next upstream server. See the [proxy_next_upstream_tries](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream_tries) directive. The `0` value turns off this limit. The default is `0`. | `int` | No |
214+
| `next-upstream` | Specifies in which cases a request should be passed to the next upstream server. See the [proxy_next_upstream](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream) directive. The default is `error timeout`. | `string` | No |
215+
| `next-upstream-timeout` | The time during which a request can be passed to the next upstream server. See the [proxy_next_upstream_timeout](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream_timeout) directive. The `0` value turns off the time limit. The default is `0`. | `string` | No |
216+
| `next-upstream-tries` | The number of possible tries for passing a request to the next upstream server. See the [proxy_next_upstream_tries](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream_tries) directive. The `0` value turns off this limit. The default is `0`. | `int` | No |
217+
| `client-max-body-size` | Sets the maximum allowed size of the client request body. See the [client_max_body_size](https://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size) directive. The default is set in the `client-max-body-size` ConfigMap key. | `string` | No |
216218
| `tls` | The TLS configuration for the Upstream. | [`tls`](#UpstreamTLS) | No |
217219
| `healthCheck` | The health check configuration for the Upstream. See the [health_check](http://nginx.org/en/docs/http/ngx_http_upstream_hc_module.html#health_check) directive. Note: this feature is supported only in NGINX Plus. | [`healthcheck`](#UpstreamHealthcheck) | No |
218220

internal/configs/virtualserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ func generateLocation(path string, upstreamName string, upstream conf_v1alpha1.U
398398
ProxyConnectTimeout: generateString(upstream.ProxyConnectTimeout, cfgParams.ProxyConnectTimeout),
399399
ProxyReadTimeout: generateString(upstream.ProxyReadTimeout, cfgParams.ProxyReadTimeout),
400400
ProxySendTimeout: generateString(upstream.ProxySendTimeout, cfgParams.ProxySendTimeout),
401-
ClientMaxBodySize: cfgParams.ClientMaxBodySize,
401+
ClientMaxBodySize: generateString(upstream.ClientMaxBodySize, cfgParams.ClientMaxBodySize),
402402
ProxyMaxTempFileSize: cfgParams.ProxyMaxTempFileSize,
403403
ProxyBuffering: cfgParams.ProxyBuffering,
404404
ProxyBuffers: cfgParams.ProxyBuffers,

pkg/apis/configuration/v1alpha1/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type Upstream struct {
3939
ProxyNextUpstream string `json:"next-upstream"`
4040
ProxyNextUpstreamTimeout string `json:"next-upstream-timeout"`
4141
ProxyNextUpstreamTries int `json:"next-upstream-tries"`
42+
ClientMaxBodySize string `json:"client-max-body-size"`
4243
TLS UpstreamTLS `json:"tls"`
4344
HealthCheck *HealthCheck `json:"healthCheck"`
4445
}

pkg/apis/configuration/validation/validation.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,27 @@ func validateTime(time string, fieldPath *field.Path) field.ErrorList {
9595
return allErrs
9696
}
9797

98+
// http://nginx.org/en/docs/syntax.html
99+
const sizeFmt = `\d+[kKmMgG]?`
100+
const sizeErrMsg = "must consist of numeric characters followed by a valid size suffix. 'k|K|m|M|g|G"
101+
102+
var sizeRegexp = regexp.MustCompile("^" + sizeFmt + "$")
103+
104+
func validateSize(size string, fieldPath *field.Path) field.ErrorList {
105+
allErrs := field.ErrorList{}
106+
107+
if size == "" {
108+
return allErrs
109+
}
110+
111+
if !sizeRegexp.MatchString(size) {
112+
msg := validation.RegexError(sizeErrMsg, sizeFmt, "16", "32k", "64M")
113+
return append(allErrs, field.Invalid(fieldPath, size, msg))
114+
}
115+
116+
return allErrs
117+
}
118+
98119
func validateUpstreamLBMethod(lBMethod string, fieldPath *field.Path, isPlus bool) field.ErrorList {
99120
allErrs := field.ErrorList{}
100121
if lBMethod == "" {
@@ -308,6 +329,7 @@ func validateUpstreams(upstreams []v1alpha1.Upstream, fieldPath *field.Path, isP
308329
allErrs = append(allErrs, validatePositiveIntOrZeroFromPointer(u.MaxFails, idxPath.Child("max-fails"))...)
309330
allErrs = append(allErrs, validatePositiveIntOrZeroFromPointer(u.Keepalive, idxPath.Child("keepalive"))...)
310331
allErrs = append(allErrs, validatePositiveIntOrZeroFromPointer(u.MaxConns, idxPath.Child("max-conns"))...)
332+
allErrs = append(allErrs, validateSize(u.ClientMaxBodySize, idxPath.Child("client-max-body-size"))...)
311333
allErrs = append(allErrs, validateUpstreamHealthCheck(u.HealthCheck, idxPath.Child("healthCheck"))...)
312334

313335
for _, msg := range validation.IsValidPortNum(int(u.Port)) {

pkg/apis/configuration/validation/validation_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,20 @@ func TestValidateUpstreamsFails(t *testing.T) {
308308
},
309309
msg: "negative value for MaxConns",
310310
},
311+
{
312+
upstreams: []v1alpha1.Upstream{
313+
{
314+
Name: "upstream1",
315+
Service: "test-1",
316+
Port: 80,
317+
ClientMaxBodySize: "7mins",
318+
},
319+
},
320+
expectedUpstreamNames: map[string]sets.Empty{
321+
"upstream1": {},
322+
},
323+
msg: "invalid value for ClientMaxBodySize",
324+
},
311325
}
312326

313327
isPlus := false
@@ -1644,6 +1658,24 @@ func TestValidateTime(t *testing.T) {
16441658
}
16451659
}
16461660

1661+
func TestValidateSize(t *testing.T) {
1662+
var validInput = []string{"", "1", "10k", "11m", "1K", "100M"}
1663+
for _, test := range validInput {
1664+
allErrs := validateSize(test, field.NewPath("size-field"))
1665+
if len(allErrs) != 0 {
1666+
t.Errorf("validateSize(%q) returned an error for valid input", test)
1667+
}
1668+
}
1669+
1670+
var invalidInput = []string{"55mm", "2mG", "6kb", "-5k", "1L"}
1671+
for _, test := range invalidInput {
1672+
allErrs := validateSize(test, field.NewPath("size-field"))
1673+
if len(allErrs) == 0 {
1674+
t.Errorf("validateSize(%q) didn't return error for invalid input.", test)
1675+
}
1676+
}
1677+
}
1678+
16471679
func TestValidateTimeFails(t *testing.T) {
16481680
time := "invalid"
16491681
allErrs := validateTime(time, field.NewPath("time-field"))

0 commit comments

Comments
 (0)
0