Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configmap keys #511

Merged
merged 1 commit into from
Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/configmap-and-annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,17 @@ spec:
| N/A | `resolver-ipv6` | Enables IPv6 resolution in the resolver. Supported in NGINX Plus only. | `True` | [Support for Type ExternalName Services](../examples/externalname-services). |
| N/A | `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](../examples/externalname-services). |
| N/A | `resolver-timeout` | Sets the [resolver_timeout](http://nginx.org/en/docs/http/ngx_http_core_module.html#resolver_timeout) for name resolution. Supported in NGINX Plus only. | `30s` | [Support for Type ExternalName Services](../examples/externalname-services). |
| N/A | `keepalive-timeout` | Sets the value of the [keepalive_timeout](http://nginx.org/en/docs/http/ngx_http_core_module.html#keepalive_timeout) directive. | `65s` | |
| N/A | `keepalive-requests` | Sets the value of the [keepalive_requests](http://nginx.org/en/docs/http/ngx_http_core_module.html#keepalive_requests) directive. | `100` | |


### Logging

| Annotation | ConfigMap Key | Description | Default | Example |
| ---------- | -------------- | ----------- | ------- | ------- |
| N/A | `error-log-level` | Sets the global [error log level](http://nginx.org/en/docs/ngx_core_module.html#error_log) for NGINX. | `notice` | |
| N/A | `log-format` | Sets the custom [log format](http://nginx.org/en/docs/http/ngx_http_log_module.html#log_format). | See the [template file](../internal/configs/templates/nginx.tmpl). | |
| N/A | `access-log-off` | Disables the [access log](http://nginx.org/en/docs/http/ngx_http_log_module.html#access_log). | `False` | |
| N/A | `log-format` | Sets the custom [log format](http://nginx.org/en/docs/http/ngx_http_log_module.html#log_format). | See the [template file](../internal/configs/templates/nginx.tmpl) for the access log. | |
| N/A | `stream-log-format` | Sets the custom [log format](http://nginx.org/en/docs/stream/ngx_stream_log_module.html#log_format) for TCP/UDP load balancing. | See the [template file](../internal/configs/templates/nginx.tmpl). | |

### Request URI/Header Manipulation
Expand Down
23 changes: 23 additions & 0 deletions internal/configs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Config struct {
MainStreamSnippets []string
MainServerNamesHashBucketSize string
MainServerNamesHashMaxSize string
MainAccessLogOff bool
MainLogFormat string
MainErrorLogLevel string
MainStreamLogFormat string
Expand Down Expand Up @@ -54,6 +55,8 @@ type Config struct {
ResolverIPV6 bool
ResolverValid string
ResolverTimeout string
MainKeepaliveTimeout string
MainKeepaliveRequests int64

// http://nginx.org/en/docs/http/ngx_http_realip_module.html
RealIPHeader string
Expand Down Expand Up @@ -99,6 +102,8 @@ func NewDefaultConfig() *Config {
LBMethod: "random two least_conn",
MainErrorLogLevel: "notice",
ResolverIPV6: true,
MainKeepaliveTimeout: "65s",
MainKeepaliveRequests: 100,
}
}

Expand Down Expand Up @@ -275,6 +280,13 @@ func ParseConfigMap(cfgm *api_v1.ConfigMap, nginxPlus bool) *Config {
if errorLogLevel, exists := cfgm.Data["error-log-level"]; exists {
cfg.MainErrorLogLevel = errorLogLevel
}
if accessLogOff, exists, err := GetMapKeyAsBool(cfgm.Data, "access-log-off", cfgm); exists {
if err != nil {
glog.Error(err)
} else {
cfg.MainAccessLogOff = accessLogOff
}
}
if logFormat, exists := cfgm.Data["log-format"]; exists {
cfg.MainLogFormat = logFormat
}
Expand Down Expand Up @@ -416,5 +428,16 @@ func ParseConfigMap(cfgm *api_v1.ConfigMap, nginxPlus bool) *Config {
}
}

if keepaliveTimeout, exists := cfgm.Data["keepalive-timeout"]; exists {
cfg.MainKeepaliveTimeout = keepaliveTimeout
}
if keepaliveRequests, exists, err := GetMapKeyAsInt64(cfgm.Data, "keepalive-requests", cfgm); exists {
if err != nil {
glog.Error(err)
} else {
cfg.MainKeepaliveRequests = keepaliveRequests
}
}

return cfg
}
3 changes: 3 additions & 0 deletions internal/configs/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,7 @@ func GenerateNginxMainConfig(config *Config) *MainConfig {
StreamSnippets: config.MainStreamSnippets,
ServerNamesHashBucketSize: config.MainServerNamesHashBucketSize,
ServerNamesHashMaxSize: config.MainServerNamesHashMaxSize,
AccessLogOff: config.MainAccessLogOff,
LogFormat: config.MainLogFormat,
ErrorLogLevel: config.MainErrorLogLevel,
StreamLogFormat: config.MainStreamLogFormat,
Expand All @@ -1199,6 +1200,8 @@ func GenerateNginxMainConfig(config *Config) *MainConfig {
ResolverIPV6: config.ResolverIPV6,
ResolverValid: config.ResolverValid,
ResolverTimeout: config.ResolverTimeout,
KeepaliveTimeout: config.MainKeepaliveTimeout,
KeepaliveRequests: config.MainKeepaliveRequests,
}
return nginxCfg
}
Expand Down
3 changes: 3 additions & 0 deletions internal/configs/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ type Location struct {
type MainConfig struct {
ServerNamesHashBucketSize string
ServerNamesHashMaxSize string
AccessLogOff bool
LogFormat string
ErrorLogLevel string
StreamLogFormat string
Expand Down Expand Up @@ -152,6 +153,8 @@ type MainConfig struct {
ResolverIPV6 bool
ResolverValid string
ResolverTimeout string
KeepaliveTimeout string
KeepaliveRequests int64
}

// NewUpstreamWithDefaultServer creates an upstream with the default server.
Expand Down
8 changes: 7 additions & 1 deletion internal/configs/templates/nginx-plus.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,18 @@ http {
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
{{- end}}

{{if .AccessLogOff}}
access_log off;
{{else}}
access_log /var/log/nginx/access.log main;
{{end}}

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;
keepalive_timeout {{.KeepaliveTimeout}};
keepalive_requests {{.KeepaliveRequests}};

#gzip on;

Expand Down
8 changes: 7 additions & 1 deletion internal/configs/templates/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,18 @@ http {
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
{{- end}}

{{if .AccessLogOff}}
access_log off;
{{else}}
access_log /var/log/nginx/access.log main;
{{end}}

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;
keepalive_timeout {{.KeepaliveTimeout}};
keepalive_requests {{.KeepaliveRequests}};

#gzip on;

Expand Down
2 changes: 2 additions & 0 deletions internal/configs/templates/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ var mainCfg = configs.MainConfig{
ResolverIPV6: false,
ResolverValid: "10s",
ResolverTimeout: "15s",
KeepaliveTimeout: "65s",
KeepaliveRequests: 100,
}

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