From 2f700a9ad5aa3b613763c0f5dfe4837ab8b43c99 Mon Sep 17 00:00:00 2001 From: Anish Ramasekar Date: Tue, 30 Jan 2018 07:24:44 -0600 Subject: [PATCH] Add limit-request-status-code option (#2001) * Add support for limit_req_status * Add documentation * Fix comment --- docs/user-guide/configmap.md | 7 ++++++- internal/ingress/controller/config/config.go | 6 ++++++ rootfs/etc/nginx/template/nginx.tmpl | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/user-guide/configmap.md b/docs/user-guide/configmap.md index 3ac1caeada..d4d03acb3b 100644 --- a/docs/user-guide/configmap.md +++ b/docs/user-guide/configmap.md @@ -127,6 +127,7 @@ The following table shows a configuration option's name, type, and the default v |[limit‑rate‑after](#limit-rate-after)|int|0| |[http‑redirect‑code](#http-redirect-code)|int|308| |[proxy‑buffering](#proxy-buffering)|string|"off"| +|[limit‑request‑status‑code](#limit-request-status-code)|int|503| ## add-headers @@ -702,4 +703,8 @@ Why the default code is 308? ## proxy-buffering -Enables or disables [buffering of responses from the proxied server](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffering). \ No newline at end of file +Enables or disables [buffering of responses from the proxied server](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffering). + +## limit-request-status-code + +Sets the [status code to return in response to rejected requests](http://nginx.org/en/docs/http/ngx_http_limit_req_module.html#limit_req_status).Default: 503 \ No newline at end of file diff --git a/internal/ingress/controller/config/config.go b/internal/ingress/controller/config/config.go index a82a3b3d85..e45e8d2ce8 100644 --- a/internal/ingress/controller/config/config.go +++ b/internal/ingress/controller/config/config.go @@ -467,6 +467,11 @@ type Configuration struct { // server to the client response // Default: empty HideHeaders []string `json:"hide-headers"` + + // LimitReqStatusCode Sets the status code to return in response to rejected requests. + // http://nginx.org/en/docs/http/ngx_http_limit_req_module.html#limit_req_status + // Default: 503 + LimitReqStatusCode int `json:"limit-req-status-code"` } // NewDefault returns the default nginx configuration @@ -560,6 +565,7 @@ func NewDefault() Configuration { JaegerServiceName: "nginx", JaegerSamplerType: "const", JaegerSamplerParam: "1", + LimitReqStatusCode: 503, } if glog.V(5) { diff --git a/rootfs/etc/nginx/template/nginx.tmpl b/rootfs/etc/nginx/template/nginx.tmpl index 15ec3e6274..e4c9e6c574 100644 --- a/rootfs/etc/nginx/template/nginx.tmpl +++ b/rootfs/etc/nginx/template/nginx.tmpl @@ -102,6 +102,8 @@ http { underscores_in_headers {{ if $cfg.EnableUnderscoresInHeaders }}on{{ else }}off{{ end }}; ignore_invalid_headers {{ if $cfg.IgnoreInvalidHeaders }}on{{ else }}off{{ end }}; + limit_req_status {{ $cfg.LimitReqStatusCode }}; + {{ if $cfg.EnableOpentracing }} opentracing on; {{ end }}