From 9f2a0b63631df24ebff2a29c3ef99f8548e61f24 Mon Sep 17 00:00:00 2001 From: Zenara Daley Date: Wed, 24 Oct 2018 16:02:28 -0400 Subject: [PATCH] Add healthcheck timeout as CLA --- cmd/nginx/flags.go | 3 +++ internal/ingress/controller/checker.go | 9 +++++---- internal/ingress/controller/controller.go | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cmd/nginx/flags.go b/cmd/nginx/flags.go index f26947e523..25633ef54b 100644 --- a/cmd/nginx/flags.go +++ b/cmd/nginx/flags.go @@ -84,6 +84,8 @@ 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.`) + updateStatus = flags.Bool("update-status", true, `Update the load-balancer status of Ingress objects this controller satisfies. Requires setting the publish-service parameter to a valid Service reference.`) @@ -217,6 +219,7 @@ Feature backed by OpenResty Lua libraries. Requires that OCSP stapling is not en ConfigMapName: *configMap, DefaultSSLCertificate: *defSSLCertificate, DefaultHealthzURL: *defHealthzURL, + HealthCheckTimeout: *healthCheckTimeout, PublishService: *publishSvc, PublishStatusAddress: *publishStatusAddress, ForceNamespaceIsolation: *forceIsolation, diff --git a/internal/ingress/controller/checker.go b/internal/ingress/controller/checker.go index b595dd5325..6dd6b3be01 100644 --- a/internal/ingress/controller/checker.go +++ b/internal/ingress/controller/checker.go @@ -38,7 +38,8 @@ func (n NGINXController) Name() string { func (n *NGINXController) Check(_ *http.Request) error { url := fmt.Sprintf("http://127.0.0.1:%v%v", n.cfg.ListenPorts.Status, ngxHealthPath) - statusCode, err := simpleGet(url) + timeout := n.cfg.HealthCheckTimeout + statusCode, err := simpleGet(url, timeout) if err != nil { return err } @@ -48,7 +49,7 @@ func (n *NGINXController) Check(_ *http.Request) error { } url = fmt.Sprintf("http://127.0.0.1:%v/is-dynamic-lb-initialized", n.cfg.ListenPorts.Status) - statusCode, err = simpleGet(url) + statusCode, err = simpleGet(url, timeout) if err != nil { return err } @@ -75,9 +76,9 @@ func (n *NGINXController) Check(_ *http.Request) error { return err } -func simpleGet(url string) (int, error) { +func simpleGet(url string, timeout time.Duration) (int, error) { client := &http.Client{ - Timeout: 10 * time.Second, + Timeout: timeout * time.Second, Transport: &http.Transport{DisableKeepAlives: true}, } diff --git a/internal/ingress/controller/controller.go b/internal/ingress/controller/controller.go index d070c5e128..770166dda3 100644 --- a/internal/ingress/controller/controller.go +++ b/internal/ingress/controller/controller.go @@ -61,6 +61,7 @@ type Configuration struct { ForceNamespaceIsolation bool DefaultHealthzURL string + HealthCheckTimeout time.Duration DefaultSSLCertificate string // +optional