Make proxy_next_upstream_tries configurable (#2232)
* Make proxy_next_upstream_tries configurable * Code generation
This commit is contained in:
parent
4f5fa47d27
commit
8575769781
9 changed files with 59 additions and 28 deletions
|
@ -42,6 +42,7 @@ The following annotations are supported:
|
||||||
|[nginx.ingress.kubernetes.io/proxy-send-timeout](#custom-timeouts)|number|
|
|[nginx.ingress.kubernetes.io/proxy-send-timeout](#custom-timeouts)|number|
|
||||||
|[nginx.ingress.kubernetes.io/proxy-read-timeout](#custom-timeouts)|number|
|
|[nginx.ingress.kubernetes.io/proxy-read-timeout](#custom-timeouts)|number|
|
||||||
|[nginx.ingress.kubernetes.io/proxy-next-upstream](#custom-timeouts)|string|
|
|[nginx.ingress.kubernetes.io/proxy-next-upstream](#custom-timeouts)|string|
|
||||||
|
|[nginx.ingress.kubernetes.io/proxy-next-upstream-tries](#custom-timeouts)|number|
|
||||||
|[nginx.ingress.kubernetes.io/proxy-request-buffering](#custom-timeouts)|string|
|
|[nginx.ingress.kubernetes.io/proxy-request-buffering](#custom-timeouts)|string|
|
||||||
|[nginx.ingress.kubernetes.io/proxy-redirect-from](#proxy-redirect)|string|
|
|[nginx.ingress.kubernetes.io/proxy-redirect-from](#proxy-redirect)|string|
|
||||||
|[nginx.ingress.kubernetes.io/proxy-redirect-to](#proxy-redirect)|string|
|
|[nginx.ingress.kubernetes.io/proxy-redirect-to](#proxy-redirect)|string|
|
||||||
|
@ -405,6 +406,7 @@ In some scenarios is required to have different values. To allow this we provide
|
||||||
- `nginx.ingress.kubernetes.io/proxy-send-timeout`
|
- `nginx.ingress.kubernetes.io/proxy-send-timeout`
|
||||||
- `nginx.ingress.kubernetes.io/proxy-read-timeout`
|
- `nginx.ingress.kubernetes.io/proxy-read-timeout`
|
||||||
- `nginx.ingress.kubernetes.io/proxy-next-upstream`
|
- `nginx.ingress.kubernetes.io/proxy-next-upstream`
|
||||||
|
- `nginx.ingress.kubernetes.io/proxy-next-upstream-tries`
|
||||||
- `nginx.ingress.kubernetes.io/proxy-request-buffering`
|
- `nginx.ingress.kubernetes.io/proxy-request-buffering`
|
||||||
|
|
||||||
### Proxy redirect
|
### Proxy redirect
|
||||||
|
|
|
@ -123,6 +123,7 @@ The following table shows a configuration option's name, type, and the default v
|
||||||
|[proxy-cookie-path](#proxy-cookie-path)|string|"off"|
|
|[proxy-cookie-path](#proxy-cookie-path)|string|"off"|
|
||||||
|[proxy-cookie-domain](#proxy-cookie-domain)|string|"off"|
|
|[proxy-cookie-domain](#proxy-cookie-domain)|string|"off"|
|
||||||
|[proxy-next-upstream](#proxy-next-upstream)|string|"error timeout invalid_header http_502 http_503 http_504"|
|
|[proxy-next-upstream](#proxy-next-upstream)|string|"error timeout invalid_header http_502 http_503 http_504"|
|
||||||
|
|[proxy-next-upstream-tries](#proxy-next-upstream-tries)|int|0|
|
||||||
|[proxy-redirect-from](#proxy-redirect-from)|string|"off"|
|
|[proxy-redirect-from](#proxy-redirect-from)|string|"off"|
|
||||||
|[proxy-request-buffering](#proxy-request-buffering)|string|"on"|
|
|[proxy-request-buffering](#proxy-request-buffering)|string|"on"|
|
||||||
|[ssl-redirect](#ssl-redirect)|bool|"true"|
|
|[ssl-redirect](#ssl-redirect)|bool|"true"|
|
||||||
|
@ -676,6 +677,10 @@ Sets a text that [should be changed in the domain attribute](http://nginx.org/en
|
||||||
|
|
||||||
Specifies in [which cases](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream) a request should be passed to the next server.
|
Specifies in [which cases](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream) a request should be passed to the next server.
|
||||||
|
|
||||||
|
## proxy-next-upstream-tries
|
||||||
|
|
||||||
|
Limit the number of [possible tries](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream_tries) a request should be passed to the next server.
|
||||||
|
|
||||||
## proxy-redirect-from
|
## proxy-redirect-from
|
||||||
|
|
||||||
Sets the original text that should be changed in the "Location" and "Refresh" header fields of a proxied server response. Default: off.
|
Sets the original text that should be changed in the "Location" and "Refresh" header fields of a proxied server response. Default: off.
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -33,6 +33,7 @@ type Config struct {
|
||||||
CookieDomain string `json:"cookieDomain"`
|
CookieDomain string `json:"cookieDomain"`
|
||||||
CookiePath string `json:"cookiePath"`
|
CookiePath string `json:"cookiePath"`
|
||||||
NextUpstream string `json:"nextUpstream"`
|
NextUpstream string `json:"nextUpstream"`
|
||||||
|
NextUpstreamTries int `json:"nextUpstreamTries"`
|
||||||
ProxyRedirectFrom string `json:"proxyRedirectFrom"`
|
ProxyRedirectFrom string `json:"proxyRedirectFrom"`
|
||||||
ProxyRedirectTo string `json:"proxyRedirectTo"`
|
ProxyRedirectTo string `json:"proxyRedirectTo"`
|
||||||
RequestBuffering string `json:"requestBuffering"`
|
RequestBuffering string `json:"requestBuffering"`
|
||||||
|
@ -71,6 +72,9 @@ func (l1 *Config) Equal(l2 *Config) bool {
|
||||||
if l1.NextUpstream != l2.NextUpstream {
|
if l1.NextUpstream != l2.NextUpstream {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if l1.NextUpstreamTries != l2.NextUpstreamTries {
|
||||||
|
return false
|
||||||
|
}
|
||||||
if l1.RequestBuffering != l2.RequestBuffering {
|
if l1.RequestBuffering != l2.RequestBuffering {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -141,6 +145,11 @@ func (a proxy) Parse(ing *extensions.Ingress) (interface{}, error) {
|
||||||
nu = defBackend.ProxyNextUpstream
|
nu = defBackend.ProxyNextUpstream
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nut, err := parser.GetIntAnnotation("proxy-next-upstream-tries", ing)
|
||||||
|
if err != nil {
|
||||||
|
nut = defBackend.ProxyNextUpstreamTries
|
||||||
|
}
|
||||||
|
|
||||||
rb, err := parser.GetStringAnnotation("proxy-request-buffering", ing)
|
rb, err := parser.GetStringAnnotation("proxy-request-buffering", ing)
|
||||||
if err != nil || rb == "" {
|
if err != nil || rb == "" {
|
||||||
rb = defBackend.ProxyRequestBuffering
|
rb = defBackend.ProxyRequestBuffering
|
||||||
|
@ -161,5 +170,5 @@ func (a proxy) Parse(ing *extensions.Ingress) (interface{}, error) {
|
||||||
pb = defBackend.ProxyBuffering
|
pb = defBackend.ProxyBuffering
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Config{bs, ct, st, rt, bufs, cd, cp, nu, prf, prt, rb, pb}, nil
|
return &Config{bs, ct, st, rt, bufs, cd, cp, nu, nut, prf, prt, rb, pb}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,15 +70,16 @@ type mockBackend struct {
|
||||||
|
|
||||||
func (m mockBackend) GetDefaultBackend() defaults.Backend {
|
func (m mockBackend) GetDefaultBackend() defaults.Backend {
|
||||||
return defaults.Backend{
|
return defaults.Backend{
|
||||||
UpstreamFailTimeout: 1,
|
UpstreamFailTimeout: 1,
|
||||||
ProxyConnectTimeout: 10,
|
ProxyConnectTimeout: 10,
|
||||||
ProxySendTimeout: 15,
|
ProxySendTimeout: 15,
|
||||||
ProxyReadTimeout: 20,
|
ProxyReadTimeout: 20,
|
||||||
ProxyBufferSize: "10k",
|
ProxyBufferSize: "10k",
|
||||||
ProxyBodySize: "3k",
|
ProxyBodySize: "3k",
|
||||||
ProxyNextUpstream: "error",
|
ProxyNextUpstream: "error",
|
||||||
ProxyRequestBuffering: "on",
|
ProxyNextUpstreamTries: 3,
|
||||||
ProxyBuffering: "off",
|
ProxyRequestBuffering: "on",
|
||||||
|
ProxyBuffering: "off",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,6 +93,7 @@ func TestProxy(t *testing.T) {
|
||||||
data[parser.GetAnnotationWithPrefix("proxy-buffer-size")] = "1k"
|
data[parser.GetAnnotationWithPrefix("proxy-buffer-size")] = "1k"
|
||||||
data[parser.GetAnnotationWithPrefix("proxy-body-size")] = "2k"
|
data[parser.GetAnnotationWithPrefix("proxy-body-size")] = "2k"
|
||||||
data[parser.GetAnnotationWithPrefix("proxy-next-upstream")] = "off"
|
data[parser.GetAnnotationWithPrefix("proxy-next-upstream")] = "off"
|
||||||
|
data[parser.GetAnnotationWithPrefix("proxy-next-upstream-tries")] = "3"
|
||||||
data[parser.GetAnnotationWithPrefix("proxy-request-buffering")] = "off"
|
data[parser.GetAnnotationWithPrefix("proxy-request-buffering")] = "off"
|
||||||
data[parser.GetAnnotationWithPrefix("proxy-buffering")] = "on"
|
data[parser.GetAnnotationWithPrefix("proxy-buffering")] = "on"
|
||||||
ing.SetAnnotations(data)
|
ing.SetAnnotations(data)
|
||||||
|
@ -122,6 +124,9 @@ func TestProxy(t *testing.T) {
|
||||||
if p.NextUpstream != "off" {
|
if p.NextUpstream != "off" {
|
||||||
t.Errorf("expected off as next-upstream but returned %v", p.NextUpstream)
|
t.Errorf("expected off as next-upstream but returned %v", p.NextUpstream)
|
||||||
}
|
}
|
||||||
|
if p.NextUpstreamTries != 3 {
|
||||||
|
t.Errorf("expected 3 as next-upstream-tries but returned %v", p.NextUpstreamTries)
|
||||||
|
}
|
||||||
if p.RequestBuffering != "off" {
|
if p.RequestBuffering != "off" {
|
||||||
t.Errorf("expected off as request-buffering but returned %v", p.RequestBuffering)
|
t.Errorf("expected off as request-buffering but returned %v", p.RequestBuffering)
|
||||||
}
|
}
|
||||||
|
@ -162,6 +167,9 @@ func TestProxyWithNoAnnotation(t *testing.T) {
|
||||||
if p.NextUpstream != "error" {
|
if p.NextUpstream != "error" {
|
||||||
t.Errorf("expected error as next-upstream but returned %v", p.NextUpstream)
|
t.Errorf("expected error as next-upstream but returned %v", p.NextUpstream)
|
||||||
}
|
}
|
||||||
|
if p.NextUpstreamTries != 3 {
|
||||||
|
t.Errorf("expected 3 as next-upstream-tries but returned %v", p.NextUpstreamTries)
|
||||||
|
}
|
||||||
if p.RequestBuffering != "on" {
|
if p.RequestBuffering != "on" {
|
||||||
t.Errorf("expected on as request-buffering but returned %v", p.RequestBuffering)
|
t.Errorf("expected on as request-buffering but returned %v", p.RequestBuffering)
|
||||||
}
|
}
|
||||||
|
|
|
@ -561,23 +561,24 @@ func NewDefault() Configuration {
|
||||||
UseHTTP2: true,
|
UseHTTP2: true,
|
||||||
ProxyStreamTimeout: "600s",
|
ProxyStreamTimeout: "600s",
|
||||||
Backend: defaults.Backend{
|
Backend: defaults.Backend{
|
||||||
ProxyBodySize: bodySize,
|
ProxyBodySize: bodySize,
|
||||||
ProxyConnectTimeout: 5,
|
ProxyConnectTimeout: 5,
|
||||||
ProxyReadTimeout: 60,
|
ProxyReadTimeout: 60,
|
||||||
ProxySendTimeout: 60,
|
ProxySendTimeout: 60,
|
||||||
ProxyBufferSize: "4k",
|
ProxyBufferSize: "4k",
|
||||||
ProxyCookieDomain: "off",
|
ProxyCookieDomain: "off",
|
||||||
ProxyCookiePath: "off",
|
ProxyCookiePath: "off",
|
||||||
ProxyNextUpstream: "error timeout invalid_header http_502 http_503 http_504",
|
ProxyNextUpstream: "error timeout invalid_header http_502 http_503 http_504",
|
||||||
ProxyRequestBuffering: "on",
|
ProxyNextUpstreamTries: 0,
|
||||||
ProxyRedirectFrom: "off",
|
ProxyRequestBuffering: "on",
|
||||||
SSLRedirect: true,
|
ProxyRedirectFrom: "off",
|
||||||
CustomHTTPErrors: []int{},
|
SSLRedirect: true,
|
||||||
WhitelistSourceRange: []string{},
|
CustomHTTPErrors: []int{},
|
||||||
SkipAccessLogURLs: []string{},
|
WhitelistSourceRange: []string{},
|
||||||
LimitRate: 0,
|
SkipAccessLogURLs: []string{},
|
||||||
LimitRateAfter: 0,
|
LimitRate: 0,
|
||||||
ProxyBuffering: "off",
|
LimitRateAfter: 0,
|
||||||
|
ProxyBuffering: "off",
|
||||||
},
|
},
|
||||||
UpstreamKeepaliveConnections: 32,
|
UpstreamKeepaliveConnections: 32,
|
||||||
LimitConnZoneVariable: defaultLimitConnZoneVariable,
|
LimitConnZoneVariable: defaultLimitConnZoneVariable,
|
||||||
|
|
|
@ -852,6 +852,7 @@ func (n *NGINXController) createServers(data []*extensions.Ingress,
|
||||||
CookieDomain: bdef.ProxyCookieDomain,
|
CookieDomain: bdef.ProxyCookieDomain,
|
||||||
CookiePath: bdef.ProxyCookiePath,
|
CookiePath: bdef.ProxyCookiePath,
|
||||||
NextUpstream: bdef.ProxyNextUpstream,
|
NextUpstream: bdef.ProxyNextUpstream,
|
||||||
|
NextUpstreamTries: bdef.ProxyNextUpstreamTries,
|
||||||
RequestBuffering: bdef.ProxyRequestBuffering,
|
RequestBuffering: bdef.ProxyRequestBuffering,
|
||||||
ProxyRedirectFrom: bdef.ProxyRedirectFrom,
|
ProxyRedirectFrom: bdef.ProxyRedirectFrom,
|
||||||
ProxyBuffering: bdef.ProxyBuffering,
|
ProxyBuffering: bdef.ProxyBuffering,
|
||||||
|
|
|
@ -69,6 +69,10 @@ type Backend struct {
|
||||||
// http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream
|
// http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream
|
||||||
ProxyNextUpstream string `json:"proxy-next-upstream"`
|
ProxyNextUpstream string `json:"proxy-next-upstream"`
|
||||||
|
|
||||||
|
// Limits the number of possible tries for passing a request to the next server.
|
||||||
|
// https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream_tries
|
||||||
|
ProxyNextUpstreamTries int `json:"proxy-next-upstream-tries"`
|
||||||
|
|
||||||
// Sets the original text that should be changed in the "Location" and "Refresh" header fields of a proxied server response.
|
// 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
|
// http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_redirect
|
||||||
// Default: off
|
// Default: off
|
||||||
|
|
|
@ -949,6 +949,7 @@ stream {
|
||||||
|
|
||||||
# In case of errors try the next upstream server before returning an error
|
# In case of errors try the next upstream server before returning an error
|
||||||
proxy_next_upstream {{ buildNextUpstream $location.Proxy.NextUpstream $all.Cfg.RetryNonIdempotent }};
|
proxy_next_upstream {{ buildNextUpstream $location.Proxy.NextUpstream $all.Cfg.RetryNonIdempotent }};
|
||||||
|
proxy_next_upstream_tries {{ $location.Proxy.NextUpstreamTries }};
|
||||||
|
|
||||||
{{/* rewrite only works if the content is not compressed */}}
|
{{/* rewrite only works if the content is not compressed */}}
|
||||||
{{ if $location.Rewrite.AddBaseURL }}
|
{{ if $location.Rewrite.AddBaseURL }}
|
||||||
|
|
Loading…
Reference in a new issue