From 2c5819e1b31721c40290eb0816d19227e6d24c08 Mon Sep 17 00:00:00 2001 From: Manuel Alejandro de Brito Fontes Date: Mon, 10 Feb 2020 16:52:50 -0300 Subject: [PATCH] Add flag to allow custom ingress status update intervals (#5050) --- cmd/nginx/flags.go | 10 ++++++++++ docs/user-guide/cli-arguments.md | 1 + internal/ingress/status/status.go | 8 ++++---- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cmd/nginx/flags.go b/cmd/nginx/flags.go index 54a52abe0..933678182 100644 --- a/cmd/nginx/flags.go +++ b/cmd/nginx/flags.go @@ -31,6 +31,7 @@ import ( "k8s.io/ingress-nginx/internal/ingress/annotations/parser" "k8s.io/ingress-nginx/internal/ingress/controller" ngx_config "k8s.io/ingress-nginx/internal/ingress/controller/config" + "k8s.io/ingress-nginx/internal/ingress/status" ing_net "k8s.io/ingress-nginx/internal/net" "k8s.io/ingress-nginx/internal/nginx" ) @@ -175,6 +176,8 @@ Takes the form ":port". If not provided, no admission controller is starte streamPort = flags.Int("stream-port", 10247, "Port to use for the lua TCP/UDP endpoint configuration.") profilerPort = flags.Int("profiler-port", 10245, "Port to use for expose the ingress controller Go profiler when it is enabled.") + + statusUpdateInterval = flags.Int("status-update-interval", status.UpdateInterval, "Time interval in seconds in which the status should check if an update is required. Default is 60 seconds") ) flags.MarkDeprecated("force-namespace-isolation", `This flag doesn't do anything.`) @@ -201,6 +204,13 @@ https://blog.maxmind.com/2019/12/18/significant-changes-to-accessing-and-using-g return true, nil, nil } + if *statusUpdateInterval < 5 { + klog.Warningf("The defined time to update the Ingress status too low (%v seconds). Adjusting to 5 seconds", *statusUpdateInterval) + status.UpdateInterval = 5 + } else { + status.UpdateInterval = *statusUpdateInterval + } + if *ingressClass != "" { klog.Infof("Watching for Ingress class: %s", *ingressClass) diff --git a/docs/user-guide/cli-arguments.md b/docs/user-guide/cli-arguments.md index 7489cd6b2..4dfa612f1 100644 --- a/docs/user-guide/cli-arguments.md +++ b/docs/user-guide/cli-arguments.md @@ -44,6 +44,7 @@ They are set in the container spec of the `nginx-ingress-controller` Deployment | `--udp-services-configmap string` | Name of the ConfigMap containing the definition of the UDP services to expose. The key in the map indicates the external port to be used. The value is a reference to a Service in the form "namespace/name:port", where "port" can either be a port name or number. | | `--update-status` | Update the load-balancer status of Ingress objects this controller satisfies. Requires setting the publish-service parameter to a valid Service reference. (default true) | | `--update-status-on-shutdown` | Update the load-balancer status of Ingress objects when the controller shuts down. Requires the update-status parameter. (default true) | +| `--status-update-interval` | Time interval in seconds in which the status should check if an update is required. (default 60 seconds) | | `-v`, `--v Level` | log level for V logs | | `--version` | Show release information about the NGINX Ingress controller and exit. | | `--vmodule moduleSpec` | comma-separated list of pattern=N settings for file-filtered logging | diff --git a/internal/ingress/status/status.go b/internal/ingress/status/status.go index 2c23c9912..60c5fdaf3 100644 --- a/internal/ingress/status/status.go +++ b/internal/ingress/status/status.go @@ -40,9 +40,9 @@ import ( "k8s.io/ingress-nginx/internal/task" ) -const ( - updateInterval = 60 * time.Second -) +// UpdateInterval defines the time interval, in seconds, in +// which the status should check if an update is required. +var UpdateInterval = 60 // Syncer ... type Syncer interface { @@ -98,7 +98,7 @@ func (s statusSync) Run(stopCh chan struct{}) { // when this instance is the leader we need to enqueue // an item to trigger the update of the Ingress status. - wait.PollUntil(updateInterval, func() (bool, error) { + wait.PollUntil(time.Duration(UpdateInterval)*time.Second, func() (bool, error) { s.syncQueue.EnqueueTask(task.GetDummyObject("sync status")) return false, nil }, stopCh)