Skip to content

Commit 75a5907

Browse files
authored
Config/Annotations: Fix proxy-busy-buffers-size. (#13610)
1 parent 23a4c20 commit 75a5907

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

internal/ingress/annotations/proxy/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,11 @@ func (a proxy) Parse(ing *networking.Ingress) (interface{}, error) {
301301
config.BufferSize = defBackend.ProxyBufferSize
302302
}
303303

304+
// Only set BusyBuffersSize if annotation is present, blank is NGINX default
305+
// https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_busy_buffers_size
304306
config.BusyBuffersSize, err = parser.GetStringAnnotation(proxyBusyBuffersSizeAnnotation, ing, a.annotationConfig.Annotations)
305307
if err != nil {
306-
config.BusyBuffersSize = defBackend.ProxyBusyBuffersSize
308+
config.BusyBuffersSize = ""
307309
}
308310

309311
config.CookiePath, err = parser.GetStringAnnotation(proxyCookiePathAnnotation, ing, a.annotationConfig.Annotations)

internal/ingress/annotations/proxy/main_test.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ func TestProxyWithNoAnnotation(t *testing.T) {
258258
if !ok {
259259
t.Fatalf("expected a Config type")
260260
}
261+
if p.BusyBuffersSize != "" {
262+
t.Errorf("expected empty BusyBuffersSize but returned %v", p.BusyBuffersSize)
263+
}
261264
if p.ConnectTimeout != 10 {
262265
t.Errorf("expected 10 as connect-timeout but returned %v", p.ConnectTimeout)
263266
}
@@ -273,9 +276,6 @@ func TestProxyWithNoAnnotation(t *testing.T) {
273276
if p.BufferSize != "10k" {
274277
t.Errorf("expected 10k as buffer-size but returned %v", p.BufferSize)
275278
}
276-
if p.BusyBuffersSize != "15k" {
277-
t.Errorf("expected 15k as buffer-size but returned %v", p.BusyBuffersSize)
278-
}
279279
if p.BodySize != "3k" {
280280
t.Errorf("expected 3k as body-size but returned %v", p.BodySize)
281281
}
@@ -298,3 +298,22 @@ func TestProxyWithNoAnnotation(t *testing.T) {
298298
t.Errorf("expected 1024m as proxy-max-temp-file-size but returned %v", p.ProxyMaxTempFileSize)
299299
}
300300
}
301+
302+
// Add a test for when annotation is set
303+
func TestProxyWithBusyBuffersSizeAnnotation(t *testing.T) {
304+
ing := buildIngress()
305+
data := map[string]string{}
306+
data[parser.GetAnnotationWithPrefix("proxy-busy-buffers-size")] = "4k"
307+
ing.SetAnnotations(data)
308+
i, err := NewParser(mockBackend{}).Parse(ing)
309+
if err != nil {
310+
t.Fatalf("unexpected error parsing a valid")
311+
}
312+
p, ok := i.(*Config)
313+
if !ok {
314+
t.Fatalf("expected a Config type")
315+
}
316+
if p.BusyBuffersSize != "4k" {
317+
t.Errorf("expected 4k as BusyBuffersSize but returned %v", p.BusyBuffersSize)
318+
}
319+
}

rootfs/etc/nginx/template/nginx.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,9 @@ stream {
10761076
{{ end }}
10771077
proxy_buffer_size {{ $location.Proxy.BufferSize }};
10781078
proxy_buffers {{ $location.Proxy.BuffersNumber }} {{ $location.Proxy.BufferSize }};
1079+
{{ if $location.Proxy.BusyBuffersSize }}
10791080
proxy_busy_buffers_size {{ $location.Proxy.BusyBuffersSize }};
1081+
{{ end }}
10801082
proxy_request_buffering {{ $location.Proxy.RequestBuffering }};
10811083

10821084
proxy_ssl_server_name on;
@@ -1334,7 +1336,9 @@ stream {
13341336
proxy_buffering {{ $location.Proxy.ProxyBuffering }};
13351337
proxy_buffer_size {{ $location.Proxy.BufferSize }};
13361338
proxy_buffers {{ $location.Proxy.BuffersNumber }} {{ $location.Proxy.BufferSize }};
1339+
{{ if $location.Proxy.BusyBuffersSize }}
13371340
proxy_busy_buffers_size {{ $location.Proxy.BusyBuffersSize }};
1341+
{{ end }}
13381342
{{ if isValidByteSize $location.Proxy.ProxyMaxTempFileSize true }}
13391343
proxy_max_temp_file_size {{ $location.Proxy.ProxyMaxTempFileSize }};
13401344
{{ end }}

0 commit comments

Comments
 (0)