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

Fix: fillout missing health check timeout on health check. #4185

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
8 changes: 6 additions & 2 deletions cmd/nginx/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"flag"
"fmt"
"os"
"time"

"github.com/spf13/pflag"

Expand Down Expand Up @@ -97,7 +98,7 @@ Takes the form "namespace/name".`)
Configured inside the NGINX status server. All requests received on the port
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,
`Update the load-balancer status of Ingress objects this controller satisfies.
Expand Down Expand Up @@ -232,6 +233,10 @@ Takes the form "<host>:port". If not provided, no admission controller is starte

nginx.HealthPath = *defHealthzURL

if *defHealthCheckTimeout > 0 {
nginx.HealthCheckTimeout = time.Duration(*defHealthCheckTimeout) * time.Second
}

config := &controller.Configuration{
APIServerHost: *apiserverHost,
KubeConfigFile: *kubeConfigFile,
Expand All @@ -249,7 +254,6 @@ Takes the form "<host>:port". If not provided, no admission controller is starte
TCPConfigMapName: *tcpConfigMapName,
UDPConfigMapName: *udpConfigMapName,
DefaultSSLCertificate: *defSSLCertificate,
HealthCheckTimeout: *healthCheckTimeout,
PublishService: *publishSvc,
PublishStatusAddress: *publishStatusAddress,
UpdateStatusOnShutdown: *updateStatusOnShutdown,
Expand Down
1 change: 0 additions & 1 deletion internal/ingress/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ type Configuration struct {
// +optional
UDPConfigMapName string

HealthCheckTimeout time.Duration
DefaultSSLCertificate string

// +optional
Expand Down
16 changes: 9 additions & 7 deletions internal/nginx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ var StatusSocket = "/tmp/nginx-status-server.sock"
// HealthPath defines the path used to define the health check location in NGINX
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
// http://nginx.org/en/docs/http/ngx_http_stub_status_module.html
var StatusPath = "/nginx_status"
Expand All @@ -47,12 +50,11 @@ var StreamSocket = "/tmp/ingress-stream.sock"

var statusLocation = "nginx-status"

var socketClient = buildUnixSocketClient()

// NewGetStatusRequest creates a new GET request to the internal NGINX status server
func NewGetStatusRequest(path string) (int, []byte, error) {
url := fmt.Sprintf("http+unix://%v%v", statusLocation, path)
res, err := socketClient.Get(url)

res, err := buildUnixSocketClient(HealthCheckTimeout).Get(url)
if err != nil {
return 0, nil, err
}
Expand All @@ -75,7 +77,7 @@ func NewPostStatusRequest(path, contentType string, data interface{}) (int, []by
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 {
return 0, nil, err
}
Expand Down Expand Up @@ -128,11 +130,11 @@ func ReadFileToString(path string) (string, error) {
return string(contents), nil
}

func buildUnixSocketClient() *http.Client {
func buildUnixSocketClient(timeout time.Duration) *http.Client {
u := &httpunix.Transport{
DialTimeout: 1 * time.Second,
RequestTimeout: 10 * time.Second,
ResponseHeaderTimeout: 10 * time.Second,
RequestTimeout: timeout,
ResponseHeaderTimeout: timeout,
}
u.RegisterLocation(statusLocation, StatusSocket)

Expand Down