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

Allow custom global configuration at multiple levels #1454

Merged
merged 1 commit into from
Oct 1, 2017
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
10 changes: 10 additions & 0 deletions controllers/nginx/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,16 @@ Default: 9411
**zipkin-service-name:** specifies the service name to use for any traces created
Default: nginx

**http-snippet:** adds custom configuration to the http section of the nginx configuration
Default: ""

**server-snippet:** adds custom configuration to all the servers in the nginx configuration
Default: ""

**location-snippet:** adds custom configuration to all the locations in the nginx configuration
Default: ""


### Default configuration options

The following table shows the options, the default value and a description.
Expand Down
9 changes: 9 additions & 0 deletions controllers/nginx/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,15 @@ type Configuration struct {
// ZipkinServiceName specifies the service name to use for any traces created
// Default: nginx
ZipkinServiceName string `json:"zipkin-service-name"`

// HTTPSnippet adds custom configuration to the http section of the nginx configuration
HTTPSnippet string `json:"http-snippet"`

// ServerSnippet adds custom configuration to all the servers in the nginx configuration
ServerSnippet string `json:"server-snippet"`

// LocationSnippet adds custom configuration to all the locations in the nginx configuration
LocationSnippet string `json:"location-snippet"`
}

// NewDefault returns the default nginx configuration
Expand Down
14 changes: 14 additions & 0 deletions controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ http {
proxy_pass_header Server;
{{ end }}

{{ if not (empty $cfg.HTTPSnippet) }}
# Custom code snippet configured in the configuration configmap
{{ $cfg.HTTPSnippet }};
{{ end }}

{{ range $name, $upstream := $backends }}
{{ if eq $upstream.SessionAffinity.AffinityType "cookie" }}
upstream sticky-{{ $upstream.Name }} {
Expand Down Expand Up @@ -394,6 +399,10 @@ http {
server_name {{ $server.Alias }};
{{ template "SERVER" serverConfig $all $server }}

{{ if not (empty $cfg.ServerSnippet) }}
# Custom code snippet configured in the configuration configmap
{{ $cfg.ServerSnippet }};
{{ end }}

{{ template "CUSTOM_ERRORS" $all }}
}
Expand Down Expand Up @@ -808,6 +817,11 @@ stream {
{{/* Add any additional configuration defined */}}
{{ $location.ConfigurationSnippet }}

{{ if not (empty $all.Cfg.LocationSnippet) }}
# Custom code snippet configured in the configuration configmap
{{ $all.Cfg.LocationSnippet }};
{{ end }}

{{/* if we are sending the request to a custom default backend, we add the required headers */}}
{{ if (hasPrefix $location.Backend "custom-default-backend-") }}
proxy_set_header X-Code 503;
Expand Down