2016-02-22 00:13:08 +00:00
|
|
|
|
/*
|
|
|
|
|
Copyright 2015 The Kubernetes Authors All rights reserved.
|
|
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package nginx
|
|
|
|
|
|
|
|
|
|
import (
|
2016-03-19 23:29:29 +00:00
|
|
|
|
"fmt"
|
2016-03-16 14:12:45 +00:00
|
|
|
|
"os"
|
2016-02-22 00:13:08 +00:00
|
|
|
|
"runtime"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
"sync"
|
|
|
|
|
"text/template"
|
|
|
|
|
|
2016-03-15 15:31:39 +00:00
|
|
|
|
"github.com/golang/glog"
|
|
|
|
|
|
2016-03-19 23:29:29 +00:00
|
|
|
|
"github.com/fatih/structs"
|
|
|
|
|
"github.com/ghodss/yaml"
|
2016-02-22 00:13:08 +00:00
|
|
|
|
|
2016-03-19 23:29:29 +00:00
|
|
|
|
"k8s.io/kubernetes/pkg/api"
|
2016-02-22 00:13:08 +00:00
|
|
|
|
client "k8s.io/kubernetes/pkg/client/unversioned"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
// http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size
|
|
|
|
|
// Sets the maximum allowed size of the client request body
|
|
|
|
|
bodySize = "1m"
|
|
|
|
|
|
|
|
|
|
// http://nginx.org/en/docs/ngx_core_module.html#error_log
|
|
|
|
|
// Configures logging level [debug | info | notice | warn | error | crit | alert | emerg]
|
|
|
|
|
// Log levels above are listed in the order of increasing severity
|
|
|
|
|
errorLevel = "info"
|
|
|
|
|
|
|
|
|
|
// HTTP Strict Transport Security (often abbreviated as HSTS) is a security feature (HTTP header)
|
|
|
|
|
// that tell browsers that it should only be communicated with using HTTPS, instead of using HTTP.
|
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/Security/HTTP_strict_transport_security
|
|
|
|
|
// max-age is the time, in seconds, that the browser should remember that this site is only to be accessed using HTTPS.
|
|
|
|
|
htsMaxAge = "15724800"
|
|
|
|
|
|
|
|
|
|
// If UseProxyProtocol is enabled defIPCIDR defines the default the IP/network address of your external load balancer
|
|
|
|
|
defIPCIDR = "0.0.0.0/0"
|
|
|
|
|
|
|
|
|
|
gzipTypes = "application/atom+xml application/javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/svg+xml image/x-icon text/css text/plain text/x-component"
|
|
|
|
|
|
|
|
|
|
// http://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_buffer_size
|
|
|
|
|
// Sets the size of the buffer used for sending data.
|
|
|
|
|
// 4k helps NGINX to improve TLS Time To First Byte (TTTFB)
|
|
|
|
|
// https://www.igvita.com/2013/12/16/optimizing-nginx-tls-time-to-first-byte/
|
|
|
|
|
sslBufferSize = "4k"
|
|
|
|
|
|
|
|
|
|
// Enabled ciphers list to enabled. The ciphers are specified in the format understood by the OpenSSL library
|
|
|
|
|
// http://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_ciphers
|
|
|
|
|
sslCiphers = "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA"
|
|
|
|
|
|
|
|
|
|
// SSL enabled protocols to use
|
|
|
|
|
// http://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_protocols
|
|
|
|
|
sslProtocols = "TLSv1 TLSv1.1 TLSv1.2"
|
|
|
|
|
|
|
|
|
|
// Time during which a client may reuse the session parameters stored in a cache.
|
|
|
|
|
// http://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_session_timeout
|
|
|
|
|
sslSessionTimeout = "10m"
|
|
|
|
|
|
|
|
|
|
// Size of the SSL shared cache between all worker processes.
|
|
|
|
|
// http://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_session_cache
|
|
|
|
|
sslSessionCacheSize = "10m"
|
|
|
|
|
|
|
|
|
|
// Base directory that contains the mounted secrets with SSL certificates, keys and
|
|
|
|
|
sslDirectory = "/etc/nginx-ssl"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type nginxConfiguration struct {
|
|
|
|
|
// http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size
|
|
|
|
|
// Sets the maximum allowed size of the client request body
|
2016-03-19 23:29:29 +00:00
|
|
|
|
BodySize string `json:"bodySize,omitempty" structs:"bodySize,omitempty"`
|
2016-02-22 00:13:08 +00:00
|
|
|
|
|
|
|
|
|
// http://nginx.org/en/docs/ngx_core_module.html#error_log
|
|
|
|
|
// Configures logging level [debug | info | notice | warn | error | crit | alert | emerg]
|
|
|
|
|
// Log levels above are listed in the order of increasing severity
|
2016-03-19 23:29:29 +00:00
|
|
|
|
ErrorLogLevel string `json:"errorLogLevel,omitempty" structs:"errorLogLevel,omitempty"`
|
2016-02-22 00:13:08 +00:00
|
|
|
|
|
|
|
|
|
// Enables or disables the header HTS in servers running SSL
|
2016-03-19 23:29:29 +00:00
|
|
|
|
UseHTS bool `json:"useHTS,omitempty" structs:"useHTS,omitempty"`
|
2016-02-22 00:13:08 +00:00
|
|
|
|
|
|
|
|
|
// Enables or disables the use of HTS in all the subdomains of the servername
|
2016-03-19 23:29:29 +00:00
|
|
|
|
HTSIncludeSubdomains bool `json:"htsIncludeSubdomains,omitempty" structs:"htsIncludeSubdomains,omitempty"`
|
2016-02-22 00:13:08 +00:00
|
|
|
|
|
|
|
|
|
// HTTP Strict Transport Security (often abbreviated as HSTS) is a security feature (HTTP header)
|
|
|
|
|
// that tell browsers that it should only be communicated with using HTTPS, instead of using HTTP.
|
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/Security/HTTP_strict_transport_security
|
|
|
|
|
// max-age is the time, in seconds, that the browser should remember that this site is only to be
|
|
|
|
|
// accessed using HTTPS.
|
2016-03-19 23:29:29 +00:00
|
|
|
|
HTSMaxAge string `json:"htsMaxAge,omitempty" structs:"htsMaxAge,omitempty"`
|
2016-02-22 00:13:08 +00:00
|
|
|
|
|
|
|
|
|
// Time during which a keep-alive client connection will stay open on the server side.
|
|
|
|
|
// The zero value disables keep-alive client connections
|
|
|
|
|
// http://nginx.org/en/docs/http/ngx_http_core_module.html#keepalive_timeout
|
2016-03-19 23:29:29 +00:00
|
|
|
|
KeepAlive int `json:"keepAlive,omitempty" structs:"keepAlive,omitempty"`
|
2016-02-22 00:13:08 +00:00
|
|
|
|
|
|
|
|
|
// Maximum number of simultaneous connections that can be opened by each worker process
|
|
|
|
|
// http://nginx.org/en/docs/ngx_core_module.html#worker_connections
|
2016-03-19 23:29:29 +00:00
|
|
|
|
MaxWorkerConnections int `json:"maxWorkerConnections,omitempty" structs:"maxWorkerConnections,omitempty"`
|
2016-02-22 00:13:08 +00:00
|
|
|
|
|
|
|
|
|
// Defines a timeout for establishing a connection with a proxied server.
|
|
|
|
|
// It should be noted that this timeout cannot usually exceed 75 seconds.
|
|
|
|
|
// http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_connect_timeout
|
2016-03-19 23:29:29 +00:00
|
|
|
|
ProxyConnectTimeout int `json:"proxyConnectTimeout,omitempty" structs:"proxyConnectTimeout,omitempty"`
|
2016-02-22 00:13:08 +00:00
|
|
|
|
|
|
|
|
|
// If UseProxyProtocol is enabled ProxyRealIPCIDR defines the default the IP/network address
|
|
|
|
|
// of your external load balancer
|
2016-03-19 23:29:29 +00:00
|
|
|
|
ProxyRealIPCIDR string `json:"proxyRealIPCIDR,omitempty" structs:"proxyRealIPCIDR,omitempty"`
|
2016-02-22 00:13:08 +00:00
|
|
|
|
|
|
|
|
|
// Timeout in seconds for reading a response from the proxied server. The timeout is set only between
|
|
|
|
|
// two successive read operations, not for the transmission of the whole response
|
|
|
|
|
// http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_read_timeout
|
2016-03-19 23:29:29 +00:00
|
|
|
|
ProxyReadTimeout int `json:"proxyReadTimeout,omitempty" structs:"proxyReadTimeout,omitempty"`
|
2016-02-22 00:13:08 +00:00
|
|
|
|
|
|
|
|
|
// Timeout in seconds for transmitting a request to the proxied server. The timeout is set only between
|
|
|
|
|
// two successive write operations, not for the transmission of the whole request.
|
|
|
|
|
// http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_send_timeout
|
2016-03-19 23:29:29 +00:00
|
|
|
|
ProxySendTimeout int `json:"proxySendTimeout,omitempty" structs:"proxySendTimeout,omitempty"`
|
2016-02-22 00:13:08 +00:00
|
|
|
|
|
|
|
|
|
// Configures name servers used to resolve names of upstream servers into addresses
|
|
|
|
|
// http://nginx.org/en/docs/http/ngx_http_core_module.html#resolver
|
2016-03-19 23:29:29 +00:00
|
|
|
|
Resolver string `json:"resolver,omitempty" structs:"resolver,omitempty"`
|
2016-02-22 00:13:08 +00:00
|
|
|
|
|
|
|
|
|
// Maximum size of the server names hash tables used in server names, map directive’s values,
|
|
|
|
|
// MIME types, names of request header strings, etcd.
|
|
|
|
|
// http://nginx.org/en/docs/hash.html
|
|
|
|
|
// http://nginx.org/en/docs/http/ngx_http_core_module.html#server_names_hash_max_size
|
2016-03-19 23:29:29 +00:00
|
|
|
|
ServerNameHashMaxSize int `json:"serverNameHashMaxSize,omitempty" structs:"serverNameHashMaxSize,omitempty"`
|
2016-02-22 00:13:08 +00:00
|
|
|
|
|
|
|
|
|
// Size of the bucker for the server names hash tables
|
|
|
|
|
// http://nginx.org/en/docs/hash.html
|
|
|
|
|
// http://nginx.org/en/docs/http/ngx_http_core_module.html#server_names_hash_bucket_size
|
2016-03-19 23:29:29 +00:00
|
|
|
|
ServerNameHashBucketSize int `json:"serverNameHashBucketSize,omitempty" structs:"serverNameHashBucketSize,omitempty"`
|
2016-02-22 00:13:08 +00:00
|
|
|
|
|
|
|
|
|
// http://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_buffer_size
|
|
|
|
|
// Sets the size of the buffer used for sending data.
|
|
|
|
|
// 4k helps NGINX to improve TLS Time To First Byte (TTTFB)
|
|
|
|
|
// https://www.igvita.com/2013/12/16/optimizing-nginx-tls-time-to-first-byte/
|
2016-03-19 23:29:29 +00:00
|
|
|
|
SSLBufferSize string `json:"sslBufferSize,omitempty" structs:"sslBufferSize,omitempty"`
|
2016-02-22 00:13:08 +00:00
|
|
|
|
|
|
|
|
|
// Enabled ciphers list to enabled. The ciphers are specified in the format understood by
|
|
|
|
|
// the OpenSSL library
|
|
|
|
|
// http://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_ciphers
|
2016-03-19 23:29:29 +00:00
|
|
|
|
SSLCiphers string `json:"sslCiphers,omitempty" structs:"sslCiphers,omitempty"`
|
2016-02-22 00:13:08 +00:00
|
|
|
|
|
|
|
|
|
// Base64 string that contains Diffie-Hellman key to help with "Perfect Forward Secrecy"
|
|
|
|
|
// https://www.openssl.org/docs/manmaster/apps/dhparam.html
|
|
|
|
|
// https://wiki.mozilla.org/Security/Server_Side_TLS#DHE_handshake_and_dhparam
|
|
|
|
|
// http://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_dhparam
|
2016-03-19 23:29:29 +00:00
|
|
|
|
SSLDHParam string `json:"sslDHParam,omitempty" structs:"sslDHParam,omitempty"`
|
2016-02-22 00:13:08 +00:00
|
|
|
|
|
|
|
|
|
// SSL enabled protocols to use
|
|
|
|
|
// http://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_protocols
|
2016-03-19 23:29:29 +00:00
|
|
|
|
SSLProtocols string `json:"sslProtocols,omitempty" structs:"sslProtocols,omitempty"`
|
2016-02-22 00:13:08 +00:00
|
|
|
|
|
|
|
|
|
// Enables or disables the use of shared SSL cache among worker processes.
|
|
|
|
|
// http://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_session_cache
|
2016-03-19 23:29:29 +00:00
|
|
|
|
SSLSessionCache bool `json:"sslSessionCache,omitempty" structs:"sslSessionCache,omitempty"`
|
2016-02-22 00:13:08 +00:00
|
|
|
|
|
|
|
|
|
// Size of the SSL shared cache between all worker processes.
|
|
|
|
|
// http://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_session_cache
|
2016-03-19 23:29:29 +00:00
|
|
|
|
SSLSessionCacheSize string `json:"sslSessionCacheSize,omitempty" structs:"sslSessionCacheSize,omitempty"`
|
2016-02-22 00:13:08 +00:00
|
|
|
|
|
|
|
|
|
// Enables or disables session resumption through TLS session tickets.
|
|
|
|
|
// http://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_session_tickets
|
2016-03-19 23:29:29 +00:00
|
|
|
|
SSLSessionTickets bool `json:"sslSessionTickets,omitempty" structs:"sslSessionTickets,omitempty"`
|
2016-02-22 00:13:08 +00:00
|
|
|
|
|
|
|
|
|
// Time during which a client may reuse the session parameters stored in a cache.
|
|
|
|
|
// http://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_session_timeout
|
2016-03-19 23:29:29 +00:00
|
|
|
|
SSLSessionTimeout string `json:"sslSessionTimeout,omitempty" structs:"sslSessionTimeout,omitempty"`
|
2016-02-22 00:13:08 +00:00
|
|
|
|
|
|
|
|
|
// Enables or disables the use of the PROXY protocol to receive client connection
|
|
|
|
|
// (real IP address) information passed through proxy servers and load balancers
|
|
|
|
|
// such as HAproxy and Amazon Elastic Load Balancer (ELB).
|
|
|
|
|
// https://www.nginx.com/resources/admin-guide/proxy-protocol/
|
2016-03-19 23:29:29 +00:00
|
|
|
|
UseProxyProtocol bool `json:"useProxyProtocol,omitempty" structs:"useProxyProtocol,omitempty"`
|
2016-02-22 00:13:08 +00:00
|
|
|
|
|
|
|
|
|
// Enables or disables the use of the nginx module that compresses responses using the "gzip" method
|
|
|
|
|
// http://nginx.org/en/docs/http/ngx_http_gzip_module.html
|
2016-03-19 23:29:29 +00:00
|
|
|
|
UseGzip bool `json:"useGzip,omitempty" structs:"useGzip,omitempty"`
|
2016-02-22 00:13:08 +00:00
|
|
|
|
|
|
|
|
|
// MIME types in addition to "text/html" to compress. The special value “*” matches any MIME type.
|
|
|
|
|
// Responses with the “text/html” type are always compressed if UseGzip is enabled
|
2016-03-19 23:29:29 +00:00
|
|
|
|
GzipTypes string `json:"gzipTypes,omitempty" structs:"gzipTypes,omitempty"`
|
2016-02-22 00:13:08 +00:00
|
|
|
|
|
|
|
|
|
// Defines the number of worker processes. By default auto means number of available CPU cores
|
|
|
|
|
// http://nginx.org/en/docs/ngx_core_module.html#worker_processes
|
2016-03-19 23:29:29 +00:00
|
|
|
|
WorkerProcesses string `json:"workerProcesses,omitempty" structs:"workerProcesses,omitempty"`
|
2016-02-22 00:13:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-22 16:51:50 +00:00
|
|
|
|
// Manager ...
|
|
|
|
|
type Manager struct {
|
2016-02-22 00:13:08 +00:00
|
|
|
|
ConfigFile string
|
|
|
|
|
|
2016-03-19 23:29:29 +00:00
|
|
|
|
defCfg *nginxConfiguration
|
|
|
|
|
|
|
|
|
|
defResolver string
|
2016-03-16 14:12:45 +00:00
|
|
|
|
|
2016-03-19 23:29:29 +00:00
|
|
|
|
sslDHParam string
|
2016-02-22 00:13:08 +00:00
|
|
|
|
|
|
|
|
|
// template loaded ready to be used to generate the nginx configuration file
|
|
|
|
|
template *template.Template
|
|
|
|
|
|
|
|
|
|
reloadLock *sync.Mutex
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// defaultConfiguration returns the default configuration contained
|
|
|
|
|
// in the file default-conf.json
|
|
|
|
|
func newDefaultNginxCfg() *nginxConfiguration {
|
2016-03-15 15:31:39 +00:00
|
|
|
|
cfg := nginxConfiguration{
|
2016-02-22 00:13:08 +00:00
|
|
|
|
BodySize: bodySize,
|
|
|
|
|
ErrorLogLevel: errorLevel,
|
|
|
|
|
UseHTS: true,
|
|
|
|
|
HTSIncludeSubdomains: true,
|
|
|
|
|
HTSMaxAge: htsMaxAge,
|
|
|
|
|
GzipTypes: gzipTypes,
|
|
|
|
|
KeepAlive: 75,
|
|
|
|
|
MaxWorkerConnections: 16384,
|
|
|
|
|
ProxyConnectTimeout: 30,
|
|
|
|
|
ProxyRealIPCIDR: defIPCIDR,
|
|
|
|
|
ProxyReadTimeout: 30,
|
|
|
|
|
ProxySendTimeout: 30,
|
|
|
|
|
ServerNameHashMaxSize: 512,
|
|
|
|
|
ServerNameHashBucketSize: 64,
|
|
|
|
|
SSLBufferSize: sslBufferSize,
|
|
|
|
|
SSLCiphers: sslCiphers,
|
|
|
|
|
SSLProtocols: sslProtocols,
|
|
|
|
|
SSLSessionCache: true,
|
|
|
|
|
SSLSessionCacheSize: sslSessionCacheSize,
|
|
|
|
|
SSLSessionTickets: true,
|
|
|
|
|
SSLSessionTimeout: sslSessionTimeout,
|
|
|
|
|
UseProxyProtocol: false,
|
|
|
|
|
UseGzip: true,
|
|
|
|
|
WorkerProcesses: strconv.Itoa(runtime.NumCPU()),
|
|
|
|
|
}
|
2016-03-15 15:31:39 +00:00
|
|
|
|
|
|
|
|
|
if glog.V(5) {
|
|
|
|
|
cfg.ErrorLogLevel = "debug"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &cfg
|
2016-02-22 00:13:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewManager ...
|
2016-03-22 16:51:50 +00:00
|
|
|
|
func NewManager(kubeClient *client.Client) *Manager {
|
|
|
|
|
ngx := &Manager{
|
2016-03-16 14:12:45 +00:00
|
|
|
|
ConfigFile: "/etc/nginx/nginx.conf",
|
|
|
|
|
defCfg: newDefaultNginxCfg(),
|
2016-03-22 16:51:50 +00:00
|
|
|
|
defResolver: strings.Join(getDNSServers(), " "),
|
2016-03-16 14:12:45 +00:00
|
|
|
|
reloadLock: &sync.Mutex{},
|
2016-02-22 00:13:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-16 14:12:45 +00:00
|
|
|
|
ngx.createCertsDir(sslDirectory)
|
|
|
|
|
|
2016-03-19 23:29:29 +00:00
|
|
|
|
ngx.sslDHParam = ngx.SearchDHParamFile(sslDirectory)
|
2016-03-16 14:12:45 +00:00
|
|
|
|
|
2016-02-22 00:13:08 +00:00
|
|
|
|
ngx.loadTemplate()
|
|
|
|
|
|
|
|
|
|
return ngx
|
|
|
|
|
}
|
2016-03-16 14:12:45 +00:00
|
|
|
|
|
2016-03-22 16:51:50 +00:00
|
|
|
|
func (nginx *Manager) createCertsDir(base string) {
|
2016-03-16 14:12:45 +00:00
|
|
|
|
if err := os.Mkdir(base, os.ModeDir); err != nil {
|
|
|
|
|
glog.Fatalf("Couldn't create directory %v: %v", base, err)
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-19 23:29:29 +00:00
|
|
|
|
|
|
|
|
|
// ConfigMapAsString returns a ConfigMap with the default NGINX
|
|
|
|
|
// configuration to be used a guide to provide a custom configuration
|
|
|
|
|
func ConfigMapAsString() string {
|
|
|
|
|
cfg := &api.ConfigMap{}
|
|
|
|
|
cfg.Name = "custom-name"
|
|
|
|
|
cfg.Namespace = "a-valid-namespace"
|
|
|
|
|
cfg.Data = make(map[string]string)
|
|
|
|
|
|
|
|
|
|
data := structs.Map(newDefaultNginxCfg())
|
|
|
|
|
for k, v := range data {
|
|
|
|
|
cfg.Data[k] = fmt.Sprintf("%v", v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out, err := yaml.Marshal(cfg)
|
|
|
|
|
if err != nil {
|
|
|
|
|
glog.Warningf("Unexpected error creating default configuration: %v", err)
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return string(out)
|
|
|
|
|
}
|