diff --git a/internal/ingress/annotations/proxy/main.go b/internal/ingress/annotations/proxy/main.go index aaa093eafd..45df90a5c0 100644 --- a/internal/ingress/annotations/proxy/main.go +++ b/internal/ingress/annotations/proxy/main.go @@ -301,9 +301,11 @@ func (a proxy) Parse(ing *networking.Ingress) (interface{}, error) { config.BufferSize = defBackend.ProxyBufferSize } + // Only set BusyBuffersSize if annotation is present, blank is NGINX default + // https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_busy_buffers_size config.BusyBuffersSize, err = parser.GetStringAnnotation(proxyBusyBuffersSizeAnnotation, ing, a.annotationConfig.Annotations) if err != nil { - config.BusyBuffersSize = defBackend.ProxyBusyBuffersSize + config.BusyBuffersSize = "" } config.CookiePath, err = parser.GetStringAnnotation(proxyCookiePathAnnotation, ing, a.annotationConfig.Annotations) diff --git a/internal/ingress/annotations/proxy/main_test.go b/internal/ingress/annotations/proxy/main_test.go index b6ce07fb25..4728af770a 100644 --- a/internal/ingress/annotations/proxy/main_test.go +++ b/internal/ingress/annotations/proxy/main_test.go @@ -258,6 +258,9 @@ func TestProxyWithNoAnnotation(t *testing.T) { if !ok { t.Fatalf("expected a Config type") } + if p.BusyBuffersSize != "" { + t.Errorf("expected empty BusyBuffersSize but returned %v", p.BusyBuffersSize) + } if p.ConnectTimeout != 10 { t.Errorf("expected 10 as connect-timeout but returned %v", p.ConnectTimeout) } @@ -273,9 +276,6 @@ func TestProxyWithNoAnnotation(t *testing.T) { if p.BufferSize != "10k" { t.Errorf("expected 10k as buffer-size but returned %v", p.BufferSize) } - if p.BusyBuffersSize != "15k" { - t.Errorf("expected 15k as buffer-size but returned %v", p.BusyBuffersSize) - } if p.BodySize != "3k" { t.Errorf("expected 3k as body-size but returned %v", p.BodySize) } @@ -298,3 +298,22 @@ func TestProxyWithNoAnnotation(t *testing.T) { t.Errorf("expected 1024m as proxy-max-temp-file-size but returned %v", p.ProxyMaxTempFileSize) } } + +// Add a test for when annotation is set +func TestProxyWithBusyBuffersSizeAnnotation(t *testing.T) { + ing := buildIngress() + data := map[string]string{} + data[parser.GetAnnotationWithPrefix("proxy-busy-buffers-size")] = "4k" + ing.SetAnnotations(data) + i, err := NewParser(mockBackend{}).Parse(ing) + if err != nil { + t.Fatalf("unexpected error parsing a valid") + } + p, ok := i.(*Config) + if !ok { + t.Fatalf("expected a Config type") + } + if p.BusyBuffersSize != "4k" { + t.Errorf("expected 4k as BusyBuffersSize but returned %v", p.BusyBuffersSize) + } +} diff --git a/rootfs/etc/nginx/template/nginx.tmpl b/rootfs/etc/nginx/template/nginx.tmpl index e51eca0e92..965804a718 100644 --- a/rootfs/etc/nginx/template/nginx.tmpl +++ b/rootfs/etc/nginx/template/nginx.tmpl @@ -1076,7 +1076,9 @@ stream { {{ end }} proxy_buffer_size {{ $location.Proxy.BufferSize }}; proxy_buffers {{ $location.Proxy.BuffersNumber }} {{ $location.Proxy.BufferSize }}; + {{ if $location.Proxy.BusyBuffersSize }} proxy_busy_buffers_size {{ $location.Proxy.BusyBuffersSize }}; + {{ end }} proxy_request_buffering {{ $location.Proxy.RequestBuffering }}; proxy_ssl_server_name on; @@ -1334,7 +1336,9 @@ stream { proxy_buffering {{ $location.Proxy.ProxyBuffering }}; proxy_buffer_size {{ $location.Proxy.BufferSize }}; proxy_buffers {{ $location.Proxy.BuffersNumber }} {{ $location.Proxy.BufferSize }}; + {{ if $location.Proxy.BusyBuffersSize }} proxy_busy_buffers_size {{ $location.Proxy.BusyBuffersSize }}; + {{ end }} {{ if isValidByteSize $location.Proxy.ProxyMaxTempFileSize true }} proxy_max_temp_file_size {{ $location.Proxy.ProxyMaxTempFileSize }}; {{ end }}