From 3058e7758da18a7779cca20e337d0e7981d3e6c8 Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Thu, 30 Nov 2017 17:53:23 -0300 Subject: [PATCH] Add setting to configure proxy responses in the stream section --- docs/user-guide/configmap.md | 8 ++++++++ internal/ingress/controller/config/config.go | 7 +++++++ internal/ingress/controller/template/configmap.go | 13 +++++++++++++ rootfs/etc/nginx/template/nginx.tmpl | 2 +- 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/docs/user-guide/configmap.md b/docs/user-guide/configmap.md index a62df674c..019bfe12f 100644 --- a/docs/user-guide/configmap.md +++ b/docs/user-guide/configmap.md @@ -85,6 +85,7 @@ The following table shows a configuration option's name, type, and the default v |[upstream-keepalive-connections](#upstream-keepalive-connections)|int|32| |[limit-conn-zone-variable](#limit-conn-zone-variable)|string|"$binary_remote_addr"| |[proxy-stream-timeout](#proxy-stream-timeout)|string|"600s"| +|[proxy-stream-responses](#proxy-stream-responses)|int|1| |[bind-address-ipv4](#bind-address-ipv4)|[]string|""| |[bind-address-ipv6](#bind-address-ipv6)|[]string|""| |[forwarded-for-header](#forwarded-for-header)|string|"X-Forwarded-For"| @@ -507,6 +508,13 @@ Sets the timeout between two successive read or write operations on client or pr _References:_ - http://nginx.org/en/docs/stream/ngx_stream_proxy_module.html#proxy_timeout +## proxy-stream-responses + +Sets the number of datagrams expected from the proxied server in response to the client request if the UDP protocol is used. + +_References:_ +- http://nginx.org/en/docs/stream/ngx_stream_proxy_module.html#proxy_responses + ## bind-address-ipv4 Sets the addresses on which the server will accept requests instead of *. It should be noted that these addresses must exist in the runtime environment or the controller will crash loop. diff --git a/internal/ingress/controller/config/config.go b/internal/ingress/controller/config/config.go index 6d3b52758..05ff73bec 100644 --- a/internal/ingress/controller/config/config.go +++ b/internal/ingress/controller/config/config.go @@ -388,6 +388,12 @@ type Configuration struct { // http://nginx.org/en/docs/stream/ngx_stream_proxy_module.html#proxy_timeout ProxyStreamTimeout string `json:"proxy-stream-timeout,omitempty"` + // Sets the number of datagrams expected from the proxied server in response + // to the client request if the UDP protocol is used. + // http://nginx.org/en/docs/stream/ngx_stream_proxy_module.html#proxy_responses + // Default: 1 + ProxyStreamResponses int `json:"proxy-stream-responses,omitempty"` + // Sets the ipv4 addresses on which the server will accept requests. BindAddressIpv4 []string `json:"bind-address-ipv4,omitempty"` @@ -473,6 +479,7 @@ func NewDefault() Configuration { ServerNameHashMaxSize: 1024, ProxyHeadersHashMaxSize: 512, ProxyHeadersHashBucketSize: 64, + ProxyStreamResponses: 1, ShowServerTokens: true, SSLBufferSize: sslBufferSize, SSLCiphers: sslCiphers, diff --git a/internal/ingress/controller/template/configmap.go b/internal/ingress/controller/template/configmap.go index f6db21203..5a65364e1 100644 --- a/internal/ingress/controller/template/configmap.go +++ b/internal/ingress/controller/template/configmap.go @@ -37,6 +37,7 @@ const ( proxyRealIPCIDR = "proxy-real-ip-cidr" bindAddress = "bind-address" httpRedirectCode = "http-redirect-code" + proxyStreamResponses = "proxy-stream-responses" ) var ( @@ -114,6 +115,17 @@ func ReadConfig(src map[string]string) config.Configuration { } } + streamResponses := 1 + if val, ok := conf[proxyStreamResponses]; ok { + delete(conf, proxyStreamResponses) + j, err := strconv.Atoi(val) + if err != nil { + glog.Warningf("%v is not a valid number: %v", val, err) + } else { + streamResponses = j + } + } + to := config.NewDefault() to.CustomHTTPErrors = filterErrors(errors) to.SkipAccessLogURLs = skipUrls @@ -122,6 +134,7 @@ func ReadConfig(src map[string]string) config.Configuration { to.BindAddressIpv4 = bindAddressIpv4List to.BindAddressIpv6 = bindAddressIpv6List to.HTTPRedirectCode = redirectCode + to.ProxyStreamResponses = streamResponses config := &mapstructure.DecoderConfig{ Metadata: nil, diff --git a/rootfs/etc/nginx/template/nginx.tmpl b/rootfs/etc/nginx/template/nginx.tmpl index b3d8bc51b..22cb69969 100644 --- a/rootfs/etc/nginx/template/nginx.tmpl +++ b/rootfs/etc/nginx/template/nginx.tmpl @@ -514,7 +514,7 @@ stream { listen [::]:{{ $udpServer.Port }} udp; {{ end }} {{ end }} - proxy_responses 1; + proxy_responses {{ $cfg.ProxyStreamResponses }}; proxy_timeout {{ $cfg.ProxyStreamTimeout }}; proxy_pass udp-{{ $udpServer.Port }}-{{ $udpServer.Backend.Namespace }}-{{ $udpServer.Backend.Name }}-{{ $udpServer.Backend.Port }}; }