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 health check location #100

Merged
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
6 changes: 5 additions & 1 deletion nginx-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ var (
// Set during build
version string

healthStatus = flag.Bool("health-status", false,
`If present, the default server listening on port 80 with the health check
location "/nginx-health" gets added to the main nginx configuration.`)

proxyURL = flag.String("proxy", "",
`If specified, the controller assumes a kubctl proxy server is running on the
given url and creates a proxy client. Regenerated NGINX configuration files
Expand Down Expand Up @@ -52,7 +56,7 @@ func main() {
}
}

ngxc, _ := nginx.NewNginxController("/etc/nginx/", local)
ngxc, _ := nginx.NewNginxController("/etc/nginx/", local, *healthStatus)
ngxc.Start()
config := nginx.NewDefaultConfig()
cnf := nginx.NewConfigurator(ngxc, config)
Expand Down
13 changes: 13 additions & 0 deletions nginx-controller/nginx/nginx.conf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,18 @@ http {
{{if .SSLPreferServerCiphers}}ssl_prefer_server_ciphers on;{{end}}
{{if .SSLDHParam}}ssl_dhparam {{.SSLDHParam}};{{end}}

{{if .HealthStatus}}
server {
listen 80 default_server;
server_name _;

location /nginx-health {
access_log off;
default_type text/plain;
return 200 "healthy\n";
}
}
{{end}}

include /etc/nginx/conf.d/*.conf;
}
5 changes: 3 additions & 2 deletions nginx-controller/nginx/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ type NginxMainConfig struct {
ServerNamesHashBucketSize string
ServerNamesHashMaxSize string
LogFormat string
HealthStatus bool
// http://nginx.org/en/docs/http/ngx_http_ssl_module.html
SSLProtocols string
SSLPreferServerCiphers bool
Expand All @@ -98,7 +99,7 @@ func NewUpstreamWithDefaultServer(name string) Upstream {
}

// NewNginxController creates a NGINX controller
func NewNginxController(nginxConfPath string, local bool) (*NginxController, error) {
func NewNginxController(nginxConfPath string, local bool, healthStatus bool) (*NginxController, error) {
ngxc := NginxController{
nginxConfdPath: path.Join(nginxConfPath, "conf.d"),
nginxCertsPath: path.Join(nginxConfPath, "ssl"),
Expand All @@ -109,7 +110,7 @@ func NewNginxController(nginxConfPath string, local bool) (*NginxController, err
createDir(ngxc.nginxCertsPath)
}

cfg := &NginxMainConfig{ServerNamesHashMaxSize: NewDefaultConfig().MainServerNamesHashMaxSize}
cfg := &NginxMainConfig{ServerNamesHashMaxSize: NewDefaultConfig().MainServerNamesHashMaxSize, HealthStatus: healthStatus}
ngxc.UpdateMainConfigFile(cfg)

return &ngxc, nil
Expand Down
6 changes: 5 additions & 1 deletion nginx-plus-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ var (
// Set during build
version string

healthStatus = flag.Bool("health-status", false,
`If present, the default server listening on port 80 with the health check
location "/nginx-health" gets added to the main nginx configuration.`)

proxyURL = flag.String("proxy", "",
`If specified, the controller assumes a kubctl proxy server is running on the
given url and creates a proxy client. Regenerated NGINX configuration files
Expand Down Expand Up @@ -52,7 +56,7 @@ func main() {
}
}

ngxc, _ := nginx.NewNginxController("/etc/nginx/", local)
ngxc, _ := nginx.NewNginxController("/etc/nginx/", local, *healthStatus)
ngxc.Start()
config := nginx.NewDefaultConfig()
nginxAPI, err := nginx.NewNginxAPIController("http://127.0.0.1:8080/upstream_conf", "http://127.0.0.1:8080/status", local)
Expand Down
13 changes: 13 additions & 0 deletions nginx-plus-controller/nginx/nginx.conf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,18 @@ http {
'' close;
}

{{if .HealthStatus}}
server {
listen 80 default_server;
server_name _;

location /nginx-health {
access_log off;
default_type text/plain;
return 200 "healthy\n";
}
}
{{end}}

include /etc/nginx/conf.d/*.conf;
}
5 changes: 3 additions & 2 deletions nginx-plus-controller/nginx/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ type NginxMainConfig struct {
ServerNamesHashBucketSize string
ServerNamesHashMaxSize string
LogFormat string
HealthStatus bool
}

// NewNginxController creates a NGINX controller
func NewNginxController(nginxConfPath string, local bool) (*NginxController, error) {
func NewNginxController(nginxConfPath string, local bool, healthStatus bool) (*NginxController, error) {
ngxc := NginxController{
nginxConfdPath: path.Join(nginxConfPath, "conf.d"),
nginxCertsPath: path.Join(nginxConfPath, "ssl"),
Expand All @@ -108,7 +109,7 @@ func NewNginxController(nginxConfPath string, local bool) (*NginxController, err
ngxc.writeStatusAndUpstreamConfAPIsConf()
}

cfg := &NginxMainConfig{ServerNamesHashMaxSize: NewDefaultConfig().MainServerNamesHashMaxSize}
cfg := &NginxMainConfig{ServerNamesHashMaxSize: NewDefaultConfig().MainServerNamesHashMaxSize, HealthStatus: healthStatus}
ngxc.UpdateMainConfigFile(cfg)

return &ngxc, nil
Expand Down