Fix: fillout missing health check timeout on health check.
This commit is contained in:
parent
28793092e7
commit
b28577a4bf
3 changed files with 15 additions and 10 deletions
|
@ -20,6 +20,7 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
|
||||||
|
@ -97,7 +98,7 @@ Takes the form "namespace/name".`)
|
||||||
Configured inside the NGINX status server. All requests received on the port
|
Configured inside the NGINX status server. All requests received on the port
|
||||||
defined by the healthz-port parameter are forwarded internally to this path.`)
|
defined by the healthz-port parameter are forwarded internally to this path.`)
|
||||||
|
|
||||||
healthCheckTimeout = flags.Duration("health-check-timeout", 10, `Time limit, in seconds, for a probe to health-check-path to succeed.`)
|
defHealthCheckTimeout = flags.Int("health-check-timeout", 10, `Time limit, in seconds, for a probe to health-check-path to succeed.`)
|
||||||
|
|
||||||
updateStatus = flags.Bool("update-status", true,
|
updateStatus = flags.Bool("update-status", true,
|
||||||
`Update the load-balancer status of Ingress objects this controller satisfies.
|
`Update the load-balancer status of Ingress objects this controller satisfies.
|
||||||
|
@ -232,6 +233,10 @@ Takes the form "<host>:port". If not provided, no admission controller is starte
|
||||||
|
|
||||||
nginx.HealthPath = *defHealthzURL
|
nginx.HealthPath = *defHealthzURL
|
||||||
|
|
||||||
|
if *defHealthCheckTimeout > 0 {
|
||||||
|
nginx.HealthCheckTimeout = time.Duration(*defHealthCheckTimeout) * time.Second
|
||||||
|
}
|
||||||
|
|
||||||
config := &controller.Configuration{
|
config := &controller.Configuration{
|
||||||
APIServerHost: *apiserverHost,
|
APIServerHost: *apiserverHost,
|
||||||
KubeConfigFile: *kubeConfigFile,
|
KubeConfigFile: *kubeConfigFile,
|
||||||
|
@ -249,7 +254,6 @@ Takes the form "<host>:port". If not provided, no admission controller is starte
|
||||||
TCPConfigMapName: *tcpConfigMapName,
|
TCPConfigMapName: *tcpConfigMapName,
|
||||||
UDPConfigMapName: *udpConfigMapName,
|
UDPConfigMapName: *udpConfigMapName,
|
||||||
DefaultSSLCertificate: *defSSLCertificate,
|
DefaultSSLCertificate: *defSSLCertificate,
|
||||||
HealthCheckTimeout: *healthCheckTimeout,
|
|
||||||
PublishService: *publishSvc,
|
PublishService: *publishSvc,
|
||||||
PublishStatusAddress: *publishStatusAddress,
|
PublishStatusAddress: *publishStatusAddress,
|
||||||
UpdateStatusOnShutdown: *updateStatusOnShutdown,
|
UpdateStatusOnShutdown: *updateStatusOnShutdown,
|
||||||
|
|
|
@ -64,7 +64,6 @@ type Configuration struct {
|
||||||
// +optional
|
// +optional
|
||||||
UDPConfigMapName string
|
UDPConfigMapName string
|
||||||
|
|
||||||
HealthCheckTimeout time.Duration
|
|
||||||
DefaultSSLCertificate string
|
DefaultSSLCertificate string
|
||||||
|
|
||||||
// +optional
|
// +optional
|
||||||
|
|
|
@ -38,6 +38,9 @@ var StatusSocket = "/tmp/nginx-status-server.sock"
|
||||||
// HealthPath defines the path used to define the health check location in NGINX
|
// HealthPath defines the path used to define the health check location in NGINX
|
||||||
var HealthPath = "/healthz"
|
var HealthPath = "/healthz"
|
||||||
|
|
||||||
|
// HealthCheckTimeout defines the time limit in seconds for a probe to health-check-path to succeed
|
||||||
|
var HealthCheckTimeout = 10 * time.Second
|
||||||
|
|
||||||
// StatusPath defines the path used to expose the NGINX status page
|
// StatusPath defines the path used to expose the NGINX status page
|
||||||
// http://nginx.org/en/docs/http/ngx_http_stub_status_module.html
|
// http://nginx.org/en/docs/http/ngx_http_stub_status_module.html
|
||||||
var StatusPath = "/nginx_status"
|
var StatusPath = "/nginx_status"
|
||||||
|
@ -47,12 +50,11 @@ var StreamSocket = "/tmp/ingress-stream.sock"
|
||||||
|
|
||||||
var statusLocation = "nginx-status"
|
var statusLocation = "nginx-status"
|
||||||
|
|
||||||
var socketClient = buildUnixSocketClient()
|
|
||||||
|
|
||||||
// NewGetStatusRequest creates a new GET request to the internal NGINX status server
|
// NewGetStatusRequest creates a new GET request to the internal NGINX status server
|
||||||
func NewGetStatusRequest(path string) (int, []byte, error) {
|
func NewGetStatusRequest(path string) (int, []byte, error) {
|
||||||
url := fmt.Sprintf("http+unix://%v%v", statusLocation, path)
|
url := fmt.Sprintf("http+unix://%v%v", statusLocation, path)
|
||||||
res, err := socketClient.Get(url)
|
|
||||||
|
res, err := buildUnixSocketClient(HealthCheckTimeout).Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, err
|
return 0, nil, err
|
||||||
}
|
}
|
||||||
|
@ -75,7 +77,7 @@ func NewPostStatusRequest(path, contentType string, data interface{}) (int, []by
|
||||||
return 0, nil, err
|
return 0, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := socketClient.Post(url, contentType, bytes.NewReader(buf))
|
res, err := buildUnixSocketClient(HealthCheckTimeout).Post(url, contentType, bytes.NewReader(buf))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, err
|
return 0, nil, err
|
||||||
}
|
}
|
||||||
|
@ -128,11 +130,11 @@ func ReadFileToString(path string) (string, error) {
|
||||||
return string(contents), nil
|
return string(contents), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildUnixSocketClient() *http.Client {
|
func buildUnixSocketClient(timeout time.Duration) *http.Client {
|
||||||
u := &httpunix.Transport{
|
u := &httpunix.Transport{
|
||||||
DialTimeout: 1 * time.Second,
|
DialTimeout: 1 * time.Second,
|
||||||
RequestTimeout: 10 * time.Second,
|
RequestTimeout: timeout,
|
||||||
ResponseHeaderTimeout: 10 * time.Second,
|
ResponseHeaderTimeout: timeout,
|
||||||
}
|
}
|
||||||
u.RegisterLocation(statusLocation, StatusSocket)
|
u.RegisterLocation(statusLocation, StatusSocket)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue