Skip to content

Commit

Permalink
Merge pull request #1777 from aledbf/stream_responses
Browse files Browse the repository at this point in the history
Add setting to configure proxy responses in the stream section
  • Loading branch information
aledbf authored Nov 30, 2017
2 parents b39e59e + 3058e77 commit 738d839
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
8 changes: 8 additions & 0 deletions docs/user-guide/configmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"|
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions internal/ingress/controller/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down Expand Up @@ -473,6 +479,7 @@ func NewDefault() Configuration {
ServerNameHashMaxSize: 1024,
ProxyHeadersHashMaxSize: 512,
ProxyHeadersHashBucketSize: 64,
ProxyStreamResponses: 1,
ShowServerTokens: true,
SSLBufferSize: sslBufferSize,
SSLCiphers: sslCiphers,
Expand Down
13 changes: 13 additions & 0 deletions internal/ingress/controller/template/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (
proxyRealIPCIDR = "proxy-real-ip-cidr"
bindAddress = "bind-address"
httpRedirectCode = "http-redirect-code"
proxyStreamResponses = "proxy-stream-responses"
)

var (
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion rootfs/etc/nginx/template/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }};
}
Expand Down

0 comments on commit 738d839

Please sign in to comment.