Add annotation for setting proxy_redirect

This commit is contained in:
Manuel de Brito Fontes 2017-11-13 19:57:41 -03:00
parent b2a4f5dccd
commit c5b0c8ab0d
6 changed files with 64 additions and 22 deletions

View file

@ -34,6 +34,8 @@ The following annotations are supported:
|[ingress.kubernetes.io/proxy-read-timeout](#custom-timeouts)|number|
|[ingress.kubernetes.io/proxy-next-upstream](#custom-timeouts)|string|
|[ingress.kubernetes.io/proxy-request-buffering](#custom-timeouts)|string|
|[ingress.kubernetes.io/proxy-redirect-from](#proxy-redirect)|string|
|[ingress.kubernetes.io/proxy-redirect-to](#proxy-redirect)|string|
|[ingress.kubernetes.io/rewrite-target](#rewrite)|URI|
|[ingress.kubernetes.io/secure-backends](#secure-backends)|true or false|
|[ingress.kubernetes.io/server-alias](#server-alias)|string|
@ -352,6 +354,13 @@ In some scenarios is required to have different values. To allow this we provide
- `ingress.kubernetes.io/proxy-next-upstream`
- `ingress.kubernetes.io/proxy-request-buffering`
### Proxy redirect
With the annotations `ingress.kubernetes.io/proxy-redirect-from` and `ingress.kubernetes.io/proxy-redirect-to` it is possible to set the text that should be changed in the `Location` and `Refresh` header fields of a proxied server response (http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_redirect)
Setting "off" or "default" in the annotation `ingress.kubernetes.io/proxy-redirect-to` disables `ingress.kubernetes.io/proxy-redirect-to`
Both annotations will be used in any other case
By default the value is "off".
### Custom max body size
For NGINX, 413 error will be returned to the client when the size in a request exceeds the maximum allowed size of the client request body. This size can be configured by the parameter [`client_max_body_size`](http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size).

View file

@ -34,6 +34,8 @@ type Config struct {
CookiePath string `json:"cookiePath"`
NextUpstream string `json:"nextUpstream"`
PassParams string `json:"passParams"`
ProxyRedirectFrom string `json:"proxyRedirectFrom"`
ProxyRedirectTo string `json:"proxyRedirectTo"`
RequestBuffering string `json:"requestBuffering"`
}
@ -72,10 +74,15 @@ func (l1 *Config) Equal(l2 *Config) bool {
if l1.PassParams != l2.PassParams {
return false
}
if l1.RequestBuffering != l2.RequestBuffering {
return false
}
if l1.ProxyRedirectFrom != l2.ProxyRedirectFrom {
return false
}
if l1.ProxyRedirectTo != l2.ProxyRedirectTo {
return false
}
return true
}
@ -143,5 +150,15 @@ func (a proxy) Parse(ing *extensions.Ingress) (interface{}, error) {
rb = defBackend.ProxyRequestBuffering
}
return &Config{bs, ct, st, rt, bufs, cd, cp, nu, pp, rb}, nil
prf, err := parser.GetStringAnnotation("proxy-redirect-from", ing, a.r)
if err != nil || rb == "" {
prf = defBackend.ProxyRedirectFrom
}
prt, err := parser.GetStringAnnotation("proxy-redirect-to", ing, a.r)
if err != nil || rb == "" {
prt = defBackend.ProxyRedirectTo
}
return &Config{bs, ct, st, rt, bufs, cd, cp, nu, pp, prf, prt, rb}, nil
}

View file

@ -497,6 +497,7 @@ func NewDefault() Configuration {
ProxyCookiePath: "off",
ProxyNextUpstream: "error timeout invalid_header http_502 http_503 http_504",
ProxyRequestBuffering: "on",
ProxyRedirectFrom: "off",
SSLRedirect: true,
CustomHTTPErrors: []int{},
WhitelistSourceRange: []string{},

View file

@ -883,6 +883,7 @@ func (n *NGINXController) createServers(data []*extensions.Ingress,
CookiePath: bdef.ProxyCookiePath,
NextUpstream: bdef.ProxyNextUpstream,
RequestBuffering: bdef.ProxyRequestBuffering,
ProxyRedirectFrom: bdef.ProxyRedirectFrom,
}
// generated on Start() with createDefaultSSLCertificate()

View file

@ -72,6 +72,16 @@ type Backend struct {
// Parameters for proxy-pass directive (eg. Apache web server).
ProxyPassParams string `json:"proxy-pass-params"`
// Sets the original text that should be changed in the "Location" and "Refresh" header fields of a proxied server response.
// http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_redirect
// Default: off
ProxyRedirectFrom string `json:"proxy-redirect-from"`
// Sets the replacement text that should be changed in the "Location" and "Refresh" header fields of a proxied server response.
// http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_redirect
// Default: ""
ProxyRedirectTo string `json:"proxy-redirect-to"`
// Enables or disables buffering of a client request body.
// http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_request_buffering
ProxyRequestBuffering string `json:"proxy-request-buffering"`

View file

@ -797,7 +797,11 @@ stream {
proxy_send_timeout {{ $location.Proxy.SendTimeout }}s;
proxy_read_timeout {{ $location.Proxy.ReadTimeout }}s;
proxy_redirect off;
{{ if (or (eq $location.Proxy.ProxyRedirectFrom "default") (eq $location.Proxy.ProxyRedirectFrom "off")) }}
proxy_redirect {{ $location.Proxy.ProxyRedirectFrom }};
{{ else }}
proxy_redirect {{ $location.Proxy.ProxyRedirectFrom }} {{ $location.Proxy.ProxyRedirectTo }};
{{ end }}
proxy_buffering off;
proxy_buffer_size "{{ $location.Proxy.BufferSize }}";
proxy_buffers 4 "{{ $location.Proxy.BufferSize }}";