Skip to content

Commit 9d94d45

Browse files
shaun-nx“shaun-nx”
andauthored
Allow configuration of map-hash-bucket-size and map-hash-max-size directives (#3274)
Co-authored-by: “shaun-nx” <“[email protected]”>
1 parent 02b5896 commit 9d94d45

File tree

6 files changed

+24
-0
lines changed

6 files changed

+24
-0
lines changed

docs/content/configuration/global-configuration/configmap-resource.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ See the doc about [VirtualServer and VirtualServerRoute resources](/nginx-ingres
8686
|``worker-shutdown-timeout`` | Sets the value of the [worker_shutdown_timeout](https://nginx.org/en/docs/ngx_core_module.html#worker_shutdown_timeout) directive. | N/A | |
8787
|``server-names-hash-bucket-size`` | Sets the value of the [server_names_hash_bucket_size](https://nginx.org/en/docs/http/ngx_http_core_module.html#server_names_hash_bucket_size) directive. | ``256`` | |
8888
|``server-names-hash-max-size`` | Sets the value of the [server_names_hash_max_size](https://nginx.org/en/docs/http/ngx_http_core_module.html#server_names_hash_max_size) directive. | ``1024`` | |
89+
|``map-hash-bucket-size`` | Sets the value of the [map_hash_bucket_size](http://nginx.org/en/docs/http/ngx_http_map_module.html#map_hash_bucket_size) directive.| ``256`` | |
90+
|``map-hash-max-size`` | Sets the value of the [map_hash_max_size](http://nginx.org/en/docs/http/ngx_http_map_module.html#map_hash_max_size) directive. | ``2048`` | |
8991
|``resolver-addresses`` | Sets the value of the [resolver](https://nginx.org/en/docs/http/ngx_http_core_module.html#resolver) addresses. Note: If you use a DNS name (for example, ``kube-dns.kube-system.svc.cluster.local`` ) as a resolver address, NGINX Plus will resolve it using the system resolver during the start and on every configuration reload. If the name cannot be resolved or the DNS server doesn't respond, NGINX Plus will fail to start or reload. To avoid this, we recommend using IP addresses as resolver addresses instead of DNS names. Supported in NGINX Plus only. | N/A | [Support for Type ExternalName Services](https://github.com/nginxinc/kubernetes-ingress/tree/v2.4.1/examples/ingress-resources/externalname-services). |
9092
|``resolver-ipv6`` | Enables IPv6 resolution in the resolver. Supported in NGINX Plus only. | ``True`` | [Support for Type ExternalName Services](https://github.com/nginxinc/kubernetes-ingress/tree/v2.4.1/examples/ingress-resources/externalname-services). |
9193
|``resolver-valid`` | Sets the time NGINX caches the resolved DNS records. Supported in NGINX Plus only. | TTL value of a DNS record | [Support for Type ExternalName Services](https://github.com/nginxinc/kubernetes-ingress/tree/v2.4.1/examples/ingress-resources/externalname-services). |

internal/configs/config_params.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ type ConfigParams struct {
3737
MainStreamLogFormat []string
3838
MainStreamLogFormatEscaping string
3939
MainStreamSnippets []string
40+
MainMapHashBucketSize string
41+
MainMapHashMaxSize string
4042
MainWorkerConnections string
4143
MainWorkerCPUAffinity string
4244
MainWorkerProcesses string
@@ -160,6 +162,8 @@ func NewDefaultConfigParams(isPlus bool) *ConfigParams {
160162
SSLRedirect: true,
161163
MainServerNamesHashBucketSize: "256",
162164
MainServerNamesHashMaxSize: "1024",
165+
MainMapHashBucketSize: "256",
166+
MainMapHashMaxSize: "2048",
163167
ProxyBuffering: true,
164168
MainWorkerProcesses: "auto",
165169
MainWorkerConnections: "1024",

internal/configs/configmaps.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ func ParseConfigMap(cfgm *v1.ConfigMap, nginxPlus bool, hasAppProtect bool, hasA
7878
cfgParams.MainServerNamesHashMaxSize = serverNamesHashMaxSize
7979
}
8080

81+
if mapHashBucketSize, exists := cfgm.Data["map-hash-bucket-size"]; exists {
82+
cfgParams.MainMapHashBucketSize = mapHashBucketSize
83+
}
84+
85+
if mapHashMaxSize, exists := cfgm.Data["map-hash-max-size"]; exists {
86+
cfgParams.MainMapHashMaxSize = mapHashMaxSize
87+
}
88+
8189
if HTTP2, exists, err := GetMapKeyAsBool(cfgm.Data, "http2", cfgm); exists {
8290
if err != nil {
8391
glog.Error(err)
@@ -533,6 +541,8 @@ func GenerateNginxMainConfig(staticCfgParams *StaticConfigParams, config *Config
533541
SetRealIPFrom: config.SetRealIPFrom,
534542
ServerNamesHashBucketSize: config.MainServerNamesHashBucketSize,
535543
ServerNamesHashMaxSize: config.MainServerNamesHashMaxSize,
544+
MapHashBucketSize: config.MainMapHashBucketSize,
545+
MapHashMaxSize: config.MainMapHashMaxSize,
536546
ServerTokens: config.ServerTokens,
537547
SSLCiphers: config.MainServerSSLCiphers,
538548
SSLDHParam: config.MainServerSSLDHParam,

internal/configs/version1/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ type MainConfig struct {
192192
SetRealIPFrom []string
193193
ServerNamesHashBucketSize string
194194
ServerNamesHashMaxSize string
195+
MapHashBucketSize string
196+
MapHashMaxSize string
195197
ServerTokens string
196198
SSLRejectHandshake bool
197199
SSLCiphers string

internal/configs/version1/nginx-plus.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@ stream {
295295
{{if .ResolverTimeout}}resolver_timeout {{.ResolverTimeout}};{{end}}
296296
{{end}}
297297

298+
map_hash_max_size {{.MapHashMaxSize}};
299+
{{if .MapHashBucketSize}}map_hash_bucket_size {{.MapHashBucketSize}};{{end}}
300+
298301
{{if .TLSPassthrough}}
299302
map $ssl_preread_server_name $dest_internal_passthrough {
300303
default unix:/var/lib/nginx/passthrough-https.sock;

internal/configs/version1/nginx.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ stream {
229229
{{range $value := .StreamSnippets}}
230230
{{$value}}{{end}}
231231

232+
map_hash_max_size {{.MapHashMaxSize}};
233+
{{if .MapHashBucketSize}}map_hash_bucket_size {{.MapHashBucketSize}};{{end}}
234+
232235
{{if .TLSPassthrough}}
233236
map $ssl_preread_server_name $dest_internal_passthrough {
234237
default unix:/var/lib/nginx/passthrough-https.sock;

0 commit comments

Comments
 (0)