Skip to content

Commit

Permalink
Merge pull request #223 from Sarga/master
Browse files Browse the repository at this point in the history
Add worker-connections configmap key
  • Loading branch information
pleshakov authored Jan 10, 2018
2 parents 9eda836 + a521e6c commit b491961
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/customization/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ The table below summarizes some of the options. More options (extensions) are av
| `nginx.org/listen-ports` | N/A | Configures HTTP ports that NGINX will listen on. | `[80]` |
| `nginx.org/listen-ports-ssl` | N/A | Configures HTTPS ports that NGINX will listen on. | `[443]` |
| N/A | `worker-processes` | Sets the value of the [worker_processes](http://nginx.org/en/docs/ngx_core_module.html#worker_processes) directive. | `auto` |
| N/A | `worker-connections` | Sets the value of the [worker_connections](http://nginx.org/en/docs/ngx_core_module.html#worker_connections) directive. | `1024` |
| N/A | `worker-cpu-affinity` | Sets the value of the [worker_cpu_affinity](http://nginx.org/en/docs/ngx_core_module.html#worker_cpu_affinity) directive. | N/A |
| N/A | `worker-shutdown-timeout` | Sets the value of the [worker_shutdown_timeout](http://nginx.org/en/docs/ngx_core_module.html#worker_shutdown_timeout) directive. | N/A |
| `nginx.org/keepalive` | `keepalive` | Sets the value of the [keepalive](http://nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive) directive. Note that `proxy_set_header Connection "";` is added to the generated configuration when the value > 0. | `0` |
Expand Down
1 change: 1 addition & 0 deletions examples/customization/nginx-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ data:
proxy_temp_path /var/nginx/proxy_temp;
charset koi8-r;
worker-processes: "1" # default is "auto". Sets the value of the worker_processes directive. See http://nginx.org/en/docs/ngx_core_module.html#worker_processes
worker-connections: "10240" # default is "1024". Sets the value of the worker_connections directive. See http://nginx.org/en/docs/ngx_core_module.html#worker_connections
worker-cpu-affinity: "auto" # No default. Sets the value of the worker_cpu_affinity directive. See http://nginx.org/en/docs/ngx_core_module.html#worker_cpu_affinity
worker-shutdown-timeout: "5m" # No default. Sets the value of the worker_shutdown_timeout directive. See http://nginx.org/en/docs/ngx_core_module.html#worker_shutdown_timeout
keepalive: "32" # default is 0. When > 0, sets the value of the keepalive directive and adds 'proxy_set_header Connection "";' to a location block. See http://nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive
3 changes: 3 additions & 0 deletions nginx-controller/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,9 @@ func (lbc *LoadBalancerController) syncCfgm(task Task) {
if workerShutdownTimeout, exists := cfgm.Data["worker-shutdown-timeout"]; exists {
cfg.MainWorkerShutdownTimeout = workerShutdownTimeout
}
if workerConnections, exists := cfgm.Data["worker-connections"]; exists {
cfg.MainWorkerConnections = workerConnections
}
if keepalive, exists, err := nginx.GetMapKeyAsInt(cfgm.Data, "keepalive", cfgm); exists {
if err != nil {
glog.Error(err)
Expand Down
2 changes: 2 additions & 0 deletions nginx-controller/nginx/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Config struct {
MainWorkerProcesses string
MainWorkerCPUAffinity string
MainWorkerShutdownTimeout string
MainWorkerConnections string
Keepalive int64

// http://nginx.org/en/docs/http/ngx_http_realip_module.html
Expand Down Expand Up @@ -63,6 +64,7 @@ func NewDefaultConfig() *Config {
MainServerNamesHashMaxSize: "512",
ProxyBuffering: true,
MainWorkerProcesses: "auto",
MainWorkerConnections: "1024",
HSTSMaxAge: 2592000,
Ports: []int{80},
SSLPorts: []int{443},
Expand Down
1 change: 1 addition & 0 deletions nginx-controller/nginx/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ func (cnf *Configurator) UpdateConfig(config *Config, ingExes []*IngressEx) erro
WorkerProcesses: config.MainWorkerProcesses,
WorkerCPUAffinity: config.MainWorkerCPUAffinity,
WorkerShutdownTimeout: config.MainWorkerShutdownTimeout,
WorkerConnections: config.MainWorkerConnections,
}

cnf.nginx.UpdateMainConfigFile(mainCfg)
Expand Down
2 changes: 2 additions & 0 deletions nginx-controller/nginx/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ type NginxMainConfig struct {
WorkerProcesses string
WorkerCPUAffinity string
WorkerShutdownTimeout string
WorkerConnections string
}

// NewUpstreamWithDefaultServer creates an upstream with the default server.
Expand Down Expand Up @@ -146,6 +147,7 @@ func NewNginxController(nginxConfPath string, local bool, healthStatus bool, ngi
ServerNamesHashMaxSize: NewDefaultConfig().MainServerNamesHashMaxSize,
ServerTokens: NewDefaultConfig().ServerTokens,
WorkerProcesses: NewDefaultConfig().MainWorkerProcesses,
WorkerConnections: NewDefaultConfig().MainWorkerConnections,
}
ngxc.UpdateMainConfigFile(cfg)

Expand Down
2 changes: 1 addition & 1 deletion nginx-controller/nginx/templates/nginx-plus.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pid /var/run/nginx.pid;
{{- end}}

events {
worker_connections 1024;
worker_connections {{.WorkerConnections}};
}


Expand Down
2 changes: 1 addition & 1 deletion nginx-controller/nginx/templates/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pid /var/run/nginx.pid;
{{- end}}

events {
worker_connections 1024;
worker_connections {{.WorkerConnections}};
}


Expand Down
1 change: 1 addition & 0 deletions nginx-controller/nginx/templates/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ var mainCfg = nginx.NginxMainConfig{
WorkerProcesses: "auto",
WorkerCPUAffinity: "auto",
WorkerShutdownTimeout: "1m",
WorkerConnections: "1024",
}

func TestIngressForNGINXPlus(t *testing.T) {
Expand Down

0 comments on commit b491961

Please sign in to comment.