From d7175a57e26381ad2fc92541690107331e5ddf05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Nussbaumer?= Date: Thu, 14 Dec 2023 10:17:05 +0100 Subject: [PATCH] fix(shutdown): make shutdown duration configurable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Clément Nussbaumer --- internal/kubenurse/server.go | 16 ++++++++++++++-- internal/servicecheck/types.go | 3 +++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/internal/kubenurse/server.go b/internal/kubenurse/server.go index 91238e85..618c75a8 100644 --- a/internal/kubenurse/server.go +++ b/internal/kubenurse/server.go @@ -46,6 +46,7 @@ type Server struct { // * KUBERNETES_SERVICE_PORT // * KUBENURSE_NAMESPACE // * KUBENURSE_NEIGHBOUR_FILTER +// * KUBENURSE_SHUTDOWN_DURATION // * KUBENURSE_CHECK_API_SERVER_DIRECT // * KUBENURSE_CHECK_API_SERVER_DNS // * KUBENURSE_CHECK_ME_INGRESS @@ -107,12 +108,23 @@ func New(ctx context.Context, k8s kubernetes.Interface) (*Server, error) { return nil, err } + shutdownDuration := 5 * time.Second + if v, ok := os.LookupEnv("KUBENURSE_SHUTDOWN_DURATION"); ok { + var err error + shutdownDuration, err = time.ParseDuration(v) + + if err != nil { + return nil, err + } + } + chk.KubenurseIngressURL = os.Getenv("KUBENURSE_INGRESS_URL") chk.KubenurseServiceURL = os.Getenv("KUBENURSE_SERVICE_URL") chk.KubernetesServiceHost = os.Getenv("KUBERNETES_SERVICE_HOST") chk.KubernetesServicePort = os.Getenv("KUBERNETES_SERVICE_PORT") chk.KubenurseNamespace = os.Getenv("KUBENURSE_NAMESPACE") chk.NeighbourFilter = os.Getenv("KUBENURSE_NEIGHBOUR_FILTER") + chk.ShutdownDuration = shutdownDuration //nolint:goconst // No need to make "false" a constant in my opinion, readability is better like this. chk.SkipCheckAPIServerDirect = os.Getenv("KUBENURSE_CHECK_API_SERVER_DIRECT") == "false" @@ -198,11 +210,11 @@ func (s *Server) Shutdown(ctx context.Context) error { s.ready = false s.mu.Unlock() - // wait 5 second before actually shutting down the http/s server, as the updated + // wait before actually shutting down the http/s server, as the updated // endpoints for the kubenurse service might not have propagated everywhere // (other kubenurse/ingress controller) yet, which will lead to // me_ingress or path errors in other pods - time.Sleep(5 * time.Second) + time.Sleep(s.checker.ShutdownDuration) // stop the scheduled checker s.checker.StopScheduled() diff --git a/internal/servicecheck/types.go b/internal/servicecheck/types.go index 45bfcf24..d08b1e14 100644 --- a/internal/servicecheck/types.go +++ b/internal/servicecheck/types.go @@ -16,6 +16,9 @@ type Checker struct { SkipCheckMeIngress bool SkipCheckMeService bool + // shutdownDuration defines the time during which kubenurse will wait before stopping + ShutdownDuration time.Duration + // Kubernetes API KubernetesServiceHost string KubernetesServicePort string