From 9e23cf94bc05fdcc8e8958bc32971f0270e040fc Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Tue, 22 Feb 2022 11:53:16 -0500 Subject: [PATCH] csi: don't wait to fire initial unmount RPC In PR #11892 we updated the `csi_hook` to unmount the volume locally via the CSI node RPCs before releasing the claim from the server. The timer for this hook was initialized with the retry time, forcing us to wait 1s before making the first unmount RPC calls. Use the new helper for timers to ensure we clean up the timer nicely. --- client/allocrunner/csi_hook.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/client/allocrunner/csi_hook.go b/client/allocrunner/csi_hook.go index 6fb1b2866abb..0594002ec00b 100644 --- a/client/allocrunner/csi_hook.go +++ b/client/allocrunner/csi_hook.go @@ -9,6 +9,7 @@ import ( hclog "github.com/hashicorp/go-hclog" multierror "github.com/hashicorp/go-multierror" "github.com/hashicorp/nomad/client/pluginmanager/csimanager" + "github.com/hashicorp/nomad/helper" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/plugins/drivers" ) @@ -286,13 +287,13 @@ func (c *csiHook) unmountWithRetry(pair *volumeAndRequest) error { defer cancel() var err error backoff := time.Second - ticker := time.NewTicker(backoff) - defer ticker.Stop() + t, stop := helper.NewSafeTimer(0) + defer stop() for { select { case <-ctx.Done(): return err - case <-ticker.C: + case <-t.C: } err = c.unmountImpl(pair) @@ -306,7 +307,7 @@ func (c *csiHook) unmountWithRetry(pair *volumeAndRequest) error { backoff = c.maxBackoffInterval } } - ticker.Reset(backoff) + t.Reset(backoff) } return nil }