Enable proxy buffering using configmap and annotation
This commit is contained in:
parent
86889532aa
commit
88303c4575
6 changed files with 23 additions and 2 deletions
|
@ -37,6 +37,7 @@ type Config struct {
|
||||||
ProxyRedirectFrom string `json:"proxyRedirectFrom"`
|
ProxyRedirectFrom string `json:"proxyRedirectFrom"`
|
||||||
ProxyRedirectTo string `json:"proxyRedirectTo"`
|
ProxyRedirectTo string `json:"proxyRedirectTo"`
|
||||||
RequestBuffering string `json:"requestBuffering"`
|
RequestBuffering string `json:"requestBuffering"`
|
||||||
|
ProxyBuffering string `json:"proxyBuffering"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Equal tests for equality between two Configuration types
|
// Equal tests for equality between two Configuration types
|
||||||
|
@ -83,6 +84,9 @@ func (l1 *Config) Equal(l2 *Config) bool {
|
||||||
if l1.ProxyRedirectTo != l2.ProxyRedirectTo {
|
if l1.ProxyRedirectTo != l2.ProxyRedirectTo {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if l1.ProxyBuffering != l2.ProxyBuffering {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -99,6 +103,7 @@ func NewParser(r resolver.Resolver) parser.IngressAnnotation {
|
||||||
// ParseAnnotations parses the annotations contained in the ingress
|
// ParseAnnotations parses the annotations contained in the ingress
|
||||||
// rule used to configure upstream check parameters
|
// rule used to configure upstream check parameters
|
||||||
func (a proxy) Parse(ing *extensions.Ingress) (interface{}, error) {
|
func (a proxy) Parse(ing *extensions.Ingress) (interface{}, error) {
|
||||||
|
|
||||||
defBackend := a.r.GetDefaultBackend()
|
defBackend := a.r.GetDefaultBackend()
|
||||||
ct, err := parser.GetIntAnnotation("proxy-connect-timeout", ing)
|
ct, err := parser.GetIntAnnotation("proxy-connect-timeout", ing)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -160,5 +165,10 @@ func (a proxy) Parse(ing *extensions.Ingress) (interface{}, error) {
|
||||||
prt = defBackend.ProxyRedirectTo
|
prt = defBackend.ProxyRedirectTo
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Config{bs, ct, st, rt, bufs, cd, cp, nu, pp, prf, prt, rb}, nil
|
pb, err := parser.GetStringAnnotation("proxy-buffering", ing)
|
||||||
|
if err != nil || pb == "" {
|
||||||
|
pb = defBackend.ProxyBuffering
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Config{bs, ct, st, rt, bufs, cd, cp, nu, pp, prf, prt, rb, pb}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,6 +79,7 @@ func (m mockBackend) GetDefaultBackend() defaults.Backend {
|
||||||
ProxyNextUpstream: "error",
|
ProxyNextUpstream: "error",
|
||||||
ProxyPassParams: "nocanon keepalive=On",
|
ProxyPassParams: "nocanon keepalive=On",
|
||||||
ProxyRequestBuffering: "on",
|
ProxyRequestBuffering: "on",
|
||||||
|
ProxyBuffering: "off",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,6 +95,7 @@ func TestProxy(t *testing.T) {
|
||||||
data[parser.GetAnnotationWithPrefix("proxy-next-upstream")] = "off"
|
data[parser.GetAnnotationWithPrefix("proxy-next-upstream")] = "off"
|
||||||
data[parser.GetAnnotationWithPrefix("proxy-pass-params")] = "smax=5 max=10"
|
data[parser.GetAnnotationWithPrefix("proxy-pass-params")] = "smax=5 max=10"
|
||||||
data[parser.GetAnnotationWithPrefix("proxy-request-buffering")] = "off"
|
data[parser.GetAnnotationWithPrefix("proxy-request-buffering")] = "off"
|
||||||
|
data[parser.GetAnnotationWithPrefix("proxy-buffering")] = "on"
|
||||||
ing.SetAnnotations(data)
|
ing.SetAnnotations(data)
|
||||||
|
|
||||||
i, err := NewParser(mockBackend{}).Parse(ing)
|
i, err := NewParser(mockBackend{}).Parse(ing)
|
||||||
|
@ -128,6 +130,9 @@ func TestProxy(t *testing.T) {
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
if p.ProxyBuffering != "on" {
|
||||||
|
t.Errorf("expected on as proxy-buffering but returned %v", p.ProxyBuffering)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestProxyWithNoAnnotation(t *testing.T) {
|
func TestProxyWithNoAnnotation(t *testing.T) {
|
||||||
|
|
|
@ -548,6 +548,7 @@ func NewDefault() Configuration {
|
||||||
SkipAccessLogURLs: []string{},
|
SkipAccessLogURLs: []string{},
|
||||||
LimitRate: 0,
|
LimitRate: 0,
|
||||||
LimitRateAfter: 0,
|
LimitRateAfter: 0,
|
||||||
|
ProxyBuffering: "off",
|
||||||
},
|
},
|
||||||
UpstreamKeepaliveConnections: 32,
|
UpstreamKeepaliveConnections: 32,
|
||||||
LimitConnZoneVariable: defaultLimitConnZoneVariable,
|
LimitConnZoneVariable: defaultLimitConnZoneVariable,
|
||||||
|
|
|
@ -814,6 +814,7 @@ func (n *NGINXController) createServers(data []*extensions.Ingress,
|
||||||
NextUpstream: bdef.ProxyNextUpstream,
|
NextUpstream: bdef.ProxyNextUpstream,
|
||||||
RequestBuffering: bdef.ProxyRequestBuffering,
|
RequestBuffering: bdef.ProxyRequestBuffering,
|
||||||
ProxyRedirectFrom: bdef.ProxyRedirectFrom,
|
ProxyRedirectFrom: bdef.ProxyRedirectFrom,
|
||||||
|
ProxyBuffering: bdef.ProxyBuffering,
|
||||||
}
|
}
|
||||||
|
|
||||||
// generated on Start() with createDefaultSSLCertificate()
|
// generated on Start() with createDefaultSSLCertificate()
|
||||||
|
|
|
@ -138,4 +138,8 @@ type Backend struct {
|
||||||
// Sets the initial amount after which the further transmission of a response to a client will be rate limited.
|
// Sets the initial amount after which the further transmission of a response to a client will be rate limited.
|
||||||
// http://nginx.org/en/docs/http/ngx_http_core_module.html#limit_rate_after
|
// http://nginx.org/en/docs/http/ngx_http_core_module.html#limit_rate_after
|
||||||
LimitRateAfter int `json:"limit-rate-after"`
|
LimitRateAfter int `json:"limit-rate-after"`
|
||||||
|
|
||||||
|
// Enables or disables buffering of responses from the proxied server.
|
||||||
|
// http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffering
|
||||||
|
ProxyBuffering string `json:"proxy-buffering"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -828,7 +828,7 @@ stream {
|
||||||
proxy_send_timeout {{ $location.Proxy.SendTimeout }}s;
|
proxy_send_timeout {{ $location.Proxy.SendTimeout }}s;
|
||||||
proxy_read_timeout {{ $location.Proxy.ReadTimeout }}s;
|
proxy_read_timeout {{ $location.Proxy.ReadTimeout }}s;
|
||||||
|
|
||||||
proxy_buffering off;
|
proxy_buffering "{{ $location.Proxy.ProxyBuffering }}";
|
||||||
proxy_buffer_size "{{ $location.Proxy.BufferSize }}";
|
proxy_buffer_size "{{ $location.Proxy.BufferSize }}";
|
||||||
proxy_buffers 4 "{{ $location.Proxy.BufferSize }}";
|
proxy_buffers 4 "{{ $location.Proxy.BufferSize }}";
|
||||||
proxy_request_buffering "{{ $location.Proxy.RequestBuffering }}";
|
proxy_request_buffering "{{ $location.Proxy.RequestBuffering }}";
|
||||||
|
|
Loading…
Reference in a new issue