Allow custom health checks

This commit is contained in:
Manuel de Brito Fontes 2016-05-16 17:29:33 -03:00
parent a38fcda255
commit 675ce396ac
14 changed files with 340 additions and 41 deletions

View file

@ -54,7 +54,7 @@ func (ngx *Manager) Start() {
// shut down, stop accepting new connections and continue to service current requests
// until all such requests are serviced. After that, the old worker processes exit.
// http://nginx.org/en/docs/beginners_guide.html#control
func (ngx *Manager) CheckAndReload(cfg nginxConfiguration, ingressCfg IngressConfig) {
func (ngx *Manager) CheckAndReload(cfg NginxConfiguration, ingressCfg IngressConfig) {
ngx.reloadRateLimiter.Accept()
ngx.reloadLock.Lock()

View file

@ -84,7 +84,8 @@ var (
sslDirectory = "/etc/nginx-ssl"
)
type nginxConfiguration struct {
// NginxConfiguration ...
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
BodySize string `structs:"body-size,omitempty"`
@ -210,6 +211,18 @@ type nginxConfiguration struct {
// http://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_session_timeout
SSLSessionTimeout string `structs:"ssl-session-timeout,omitempty"`
// Number of unsuccessful attempts to communicate with the server that should happen in the
// duration set by the fail_timeout parameter to consider the server unavailable
// http://nginx.org/en/docs/http/ngx_http_upstream_module.html#upstream
// Default: 0, ie use platform liveness probe
UpstreamMaxFails int `structs:"upstream-max-fails,omitempty"`
// Time during which the specified number of unsuccessful attempts to communicate with
// the server should happen to consider the server unavailable
// http://nginx.org/en/docs/http/ngx_http_upstream_module.html#upstream
// Default: 0, ie use platform liveness probe
UpstreamFailTimeout int `structs:"upstream-fail-timeout,omitempty"`
// 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).
@ -238,7 +251,7 @@ type nginxConfiguration struct {
type Manager struct {
ConfigFile string
defCfg nginxConfiguration
defCfg NginxConfiguration
defResolver string
@ -254,8 +267,8 @@ type Manager struct {
// defaultConfiguration returns the default configuration contained
// in the file default-conf.json
func newDefaultNginxCfg() nginxConfiguration {
cfg := nginxConfiguration{
func newDefaultNginxCfg() NginxConfiguration {
cfg := NginxConfiguration{
BodySize: bodySize,
ErrorLogLevel: errorLevel,
HSTS: true,

View file

@ -41,8 +41,10 @@ func (c UpstreamByNameServers) Less(i, j int) bool {
// UpstreamServer describes a server in an NGINX upstream
type UpstreamServer struct {
Address string
Port string
Address string
Port string
MaxFails int
FailTimeout int
}
// UpstreamServerByAddrPort sorts upstream servers by address and port

View file

@ -48,7 +48,7 @@ func (ngx *Manager) loadTemplate() {
ngx.template = tmpl
}
func (ngx *Manager) writeCfg(cfg nginxConfiguration, ingressCfg IngressConfig) (bool, error) {
func (ngx *Manager) writeCfg(cfg NginxConfiguration, ingressCfg IngressConfig) (bool, error) {
conf := make(map[string]interface{})
conf["upstreams"] = ingressCfg.Upstreams
conf["servers"] = ingressCfg.Servers

View file

@ -67,7 +67,7 @@ func getDNSServers() []string {
// getConfigKeyToStructKeyMap returns a map with the ConfigMapKey as key and the StructName as value.
func getConfigKeyToStructKeyMap() map[string]string {
keyMap := map[string]string{}
n := &nginxConfiguration{}
n := &NginxConfiguration{}
val := reflect.Indirect(reflect.ValueOf(n))
for i := 0; i < val.Type().NumField(); i++ {
fieldSt := val.Type().Field(i)
@ -79,12 +79,12 @@ func getConfigKeyToStructKeyMap() map[string]string {
}
// ReadConfig obtains the configuration defined by the user merged with the defaults.
func (ngx *Manager) ReadConfig(config *api.ConfigMap) nginxConfiguration {
func (ngx *Manager) ReadConfig(config *api.ConfigMap) NginxConfiguration {
if len(config.Data) == 0 {
return newDefaultNginxCfg()
}
cfgCM := nginxConfiguration{}
cfgCM := NginxConfiguration{}
cfgDefault := newDefaultNginxCfg()
metadata := &mapstructure.Metadata{}

View file

@ -22,7 +22,7 @@ import (
"k8s.io/kubernetes/pkg/api"
)
func getConfigNginxBool(data map[string]string) nginxConfiguration {
func getConfigNginxBool(data map[string]string) NginxConfiguration {
manager := &Manager{}
configMap := &api.ConfigMap{
Data: data,