Merge pull request #148 from aledbf/body-size
Add annotation to allow custom body sizes
This commit is contained in:
commit
b896215613
6 changed files with 22 additions and 13 deletions
|
@ -179,7 +179,7 @@ Please check the [whitelist](examples/whitelist/README.md) example.
|
||||||
|
|
||||||
### **Allowed parameters in configuration ConfigMap**
|
### **Allowed parameters in configuration ConfigMap**
|
||||||
|
|
||||||
**body-size:** Sets the maximum allowed size of the client request body. See NGINX [client_max_body_size](http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size).
|
**proxy-body-size:** Sets the maximum allowed size of the client request body. See NGINX [client_max_body_size](http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size).
|
||||||
|
|
||||||
|
|
||||||
**custom-http-errors:** Enables which HTTP codes should be passed for processing with the [error_page directive](http://nginx.org/en/docs/http/ngx_http_core_module.html#error_page).
|
**custom-http-errors:** Enables which HTTP codes should be passed for processing with the [error_page directive](http://nginx.org/en/docs/http/ngx_http_core_module.html#error_page).
|
||||||
|
|
|
@ -78,10 +78,6 @@ var (
|
||||||
type Configuration struct {
|
type Configuration struct {
|
||||||
defaults.Backend `json:",squash"`
|
defaults.Backend `json:",squash"`
|
||||||
|
|
||||||
// http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size
|
|
||||||
// Sets the maximum allowed size of the client request body
|
|
||||||
BodySize string `json:"body-size,omitempty"`
|
|
||||||
|
|
||||||
// EnableDynamicTLSRecords enables dynamic TLS record sizes
|
// EnableDynamicTLSRecords enables dynamic TLS record sizes
|
||||||
// https://blog.cloudflare.com/optimizing-tls-over-tcp-to-reduce-latency
|
// https://blog.cloudflare.com/optimizing-tls-over-tcp-to-reduce-latency
|
||||||
// By default this is enabled
|
// By default this is enabled
|
||||||
|
@ -225,7 +221,6 @@ type Configuration struct {
|
||||||
// NewDefault returns the default nginx configuration
|
// NewDefault returns the default nginx configuration
|
||||||
func NewDefault() Configuration {
|
func NewDefault() Configuration {
|
||||||
cfg := Configuration{
|
cfg := Configuration{
|
||||||
BodySize: bodySize,
|
|
||||||
EnableDynamicTLSRecords: true,
|
EnableDynamicTLSRecords: true,
|
||||||
EnableSPDY: false,
|
EnableSPDY: false,
|
||||||
ErrorLogLevel: errorLevel,
|
ErrorLogLevel: errorLevel,
|
||||||
|
@ -253,6 +248,7 @@ func NewDefault() Configuration {
|
||||||
VtsStatusZoneSize: "10m",
|
VtsStatusZoneSize: "10m",
|
||||||
UseHTTP2: true,
|
UseHTTP2: true,
|
||||||
Backend: defaults.Backend{
|
Backend: defaults.Backend{
|
||||||
|
ProxyBodySize: bodySize,
|
||||||
ProxyConnectTimeout: 5,
|
ProxyConnectTimeout: 5,
|
||||||
ProxyReadTimeout: 60,
|
ProxyReadTimeout: 60,
|
||||||
ProxySendTimeout: 60,
|
ProxySendTimeout: 60,
|
||||||
|
|
|
@ -70,9 +70,7 @@ http {
|
||||||
gzip_proxied any;
|
gzip_proxied any;
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
server_tokens {{ if $cfg.ShowServerTokens }}on{{ else }}off{{ end }};
|
server_tokens {{ if $cfg.ShowServerTokens }}on{{ else }}off{{ end }};
|
||||||
|
|
||||||
client_max_body_size "{{ $cfg.BodySize }}";
|
|
||||||
|
|
||||||
log_format upstreaminfo '{{ if $cfg.UseProxyProtocol }}$proxy_protocol_addr{{ else }}$remote_addr{{ end }} - '
|
log_format upstreaminfo '{{ if $cfg.UseProxyProtocol }}$proxy_protocol_addr{{ else }}$remote_addr{{ end }} - '
|
||||||
'[$proxy_add_x_forwarded_for] - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" '
|
'[$proxy_add_x_forwarded_for] - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" '
|
||||||
|
@ -281,6 +279,8 @@ http {
|
||||||
{{ template "CORS" }}
|
{{ template "CORS" }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
client_max_body_size "{{ $location.Proxy.BodySize }}";
|
||||||
|
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
|
|
||||||
# Pass Real IP
|
# Pass Real IP
|
||||||
|
|
|
@ -24,6 +24,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
bodySize = "ingress.kubernetes.io/proxy-body-size"
|
||||||
connect = "ingress.kubernetes.io/proxy-connect-timeout"
|
connect = "ingress.kubernetes.io/proxy-connect-timeout"
|
||||||
send = "ingress.kubernetes.io/proxy-send-timeout"
|
send = "ingress.kubernetes.io/proxy-send-timeout"
|
||||||
read = "ingress.kubernetes.io/proxy-read-timeout"
|
read = "ingress.kubernetes.io/proxy-read-timeout"
|
||||||
|
@ -32,6 +33,7 @@ const (
|
||||||
|
|
||||||
// Configuration returns the proxy timeout to use in the upstream server/s
|
// Configuration returns the proxy timeout to use in the upstream server/s
|
||||||
type Configuration struct {
|
type Configuration struct {
|
||||||
|
BodySize string `json:"bodySize"`
|
||||||
ConnectTimeout int `json:"conectTimeout"`
|
ConnectTimeout int `json:"conectTimeout"`
|
||||||
SendTimeout int `json:"sendTimeout"`
|
SendTimeout int `json:"sendTimeout"`
|
||||||
ReadTimeout int `json:"readTimeout"`
|
ReadTimeout int `json:"readTimeout"`
|
||||||
|
@ -66,10 +68,15 @@ func (a proxy) Parse(ing *extensions.Ingress) (interface{}, error) {
|
||||||
rt = defBackend.ProxyReadTimeout
|
rt = defBackend.ProxyReadTimeout
|
||||||
}
|
}
|
||||||
|
|
||||||
bs, err := parser.GetStringAnnotation(bufferSize, ing)
|
bufs, err := parser.GetStringAnnotation(bufferSize, ing)
|
||||||
if err != nil || bs == "" {
|
if err != nil || bufs == "" {
|
||||||
bs = defBackend.ProxyBufferSize
|
bufs = defBackend.ProxyBufferSize
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Configuration{ct, st, rt, bs}, nil
|
bs, err := parser.GetStringAnnotation(bodySize, ing)
|
||||||
|
if err != nil || bs == "" {
|
||||||
|
bs = defBackend.ProxyBodySize
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Configuration{bs, ct, st, rt, bufs}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -788,6 +788,7 @@ func (ic *GenericController) createServers(data []interface{}, upstreams map[str
|
||||||
|
|
||||||
bdef := ic.GetDefaultBackend()
|
bdef := ic.GetDefaultBackend()
|
||||||
ngxProxy := proxy.Configuration{
|
ngxProxy := proxy.Configuration{
|
||||||
|
BodySize: bdef.ProxyBodySize,
|
||||||
ConnectTimeout: bdef.ProxyConnectTimeout,
|
ConnectTimeout: bdef.ProxyConnectTimeout,
|
||||||
SendTimeout: bdef.ProxySendTimeout,
|
SendTimeout: bdef.ProxySendTimeout,
|
||||||
ReadTimeout: bdef.ProxyReadTimeout,
|
ReadTimeout: bdef.ProxyReadTimeout,
|
||||||
|
|
|
@ -6,12 +6,17 @@ import "net"
|
||||||
// The reason of this requirements is the annotations are generic. If some implementation do not supports
|
// The reason of this requirements is the annotations are generic. If some implementation do not supports
|
||||||
// one or more annotations it just can provides defaults
|
// one or more annotations it just can provides defaults
|
||||||
type Backend struct {
|
type Backend struct {
|
||||||
|
|
||||||
// enables which HTTP codes should be passed for processing with the error_page directive
|
// enables which HTTP codes should be passed for processing with the error_page directive
|
||||||
// http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_intercept_errors
|
// http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_intercept_errors
|
||||||
// http://nginx.org/en/docs/http/ngx_http_core_module.html#error_page
|
// http://nginx.org/en/docs/http/ngx_http_core_module.html#error_page
|
||||||
// By default this is disabled
|
// By default this is disabled
|
||||||
CustomHTTPErrors []int `json:"custom-http-errors,-"`
|
CustomHTTPErrors []int `json:"custom-http-errors,-"`
|
||||||
|
|
||||||
|
// http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size
|
||||||
|
// Sets the maximum allowed size of the client request body
|
||||||
|
ProxyBodySize string `json:"proxy-body-size"`
|
||||||
|
|
||||||
// Defines a timeout for establishing a connection with a proxied server.
|
// Defines a timeout for establishing a connection with a proxied server.
|
||||||
// It should be noted that this timeout cannot usually exceed 75 seconds.
|
// It should be noted that this timeout cannot usually exceed 75 seconds.
|
||||||
// http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_connect_timeout
|
// http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_connect_timeout
|
||||||
|
|
Loading…
Reference in a new issue