From 436fd23f641c438eac806f9d5bbb4d1fe4897970 Mon Sep 17 00:00:00 2001 From: Daniel Bennett Date: Mon, 2 Dec 2024 17:09:46 -0500 Subject: [PATCH] extend timeout for restores --- client/client.go | 2 +- client/hostvolumemanager/host_volumes.go | 8 ++++---- client/hostvolumemanager/host_volumes_test.go | 7 ++++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/client/client.go b/client/client.go index 3be764f8342..46fd7b7947d 100644 --- a/client/client.go +++ b/client/client.go @@ -536,7 +536,7 @@ func NewClient(cfg *config.Config, consulCatalog consul.CatalogAPI, consulProxie c.pluginManagers.RegisterAndRun(devManager) c.hostVolumeManager, err = hvm.NewHostVolumeManager(logger, - c.stateDB, + c.stateDB, hostVolumeRequestTimeout, cfg.HostVolumePluginDir, cfg.AllocMountsDir) if err != nil { diff --git a/client/hostvolumemanager/host_volumes.go b/client/hostvolumemanager/host_volumes.go index 5d4f72e718a..adf6580e176 100644 --- a/client/hostvolumemanager/host_volumes.go +++ b/client/hostvolumemanager/host_volumes.go @@ -28,7 +28,7 @@ type HostVolumeManager struct { } func NewHostVolumeManager(logger hclog.Logger, - stateMgr HostVolumeStateManager, + stateMgr HostVolumeStateManager, restoreTimeout time.Duration, pluginDir, sharedMountDir string) (*HostVolumeManager, error) { log := logger.Named("host_volume_mgr") @@ -41,14 +41,14 @@ func NewHostVolumeManager(logger hclog.Logger, log: log, } - if err := hvm.restoreState(stateMgr); err != nil { + if err := hvm.restoreState(stateMgr, restoreTimeout); err != nil { return nil, err } return hvm, nil } -func (hvm *HostVolumeManager) restoreState(state HostVolumeStateManager) error { +func (hvm *HostVolumeManager) restoreState(state HostVolumeStateManager, timeout time.Duration) error { vols, err := state.GetDynamicHostVolumes() if err != nil { return err @@ -64,7 +64,7 @@ func (hvm *HostVolumeManager) restoreState(state HostVolumeStateManager) error { wg.Add(1) func() { defer wg.Done() - ctx, cancel := context.WithTimeout(context.Background(), time.Second) + ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() // note: this will rewrite client state that we just restored if _, err := hvm.Create(ctx, vol.CreateReq); err != nil { diff --git a/client/hostvolumemanager/host_volumes_test.go b/client/hostvolumemanager/host_volumes_test.go index 7ace22f5f5c..4b1123b752c 100644 --- a/client/hostvolumemanager/host_volumes_test.go +++ b/client/hostvolumemanager/host_volumes_test.go @@ -8,6 +8,7 @@ import ( "path/filepath" "sync" "testing" + "time" cstructs "github.com/hashicorp/nomad/client/structs" "github.com/hashicorp/nomad/helper/testlog" @@ -33,7 +34,7 @@ func TestNewHostVolumeManager_restoreState(t *testing.T) { // resulting in a volume directory in this mountDir. mountDir := t.TempDir() - _, err := NewHostVolumeManager(log, state, "/wherever", mountDir) + _, err := NewHostVolumeManager(log, state, time.Second, "/wherever", mountDir) must.NoError(t, err) volPath := filepath.Join(mountDir, vol.ID) @@ -43,7 +44,7 @@ func TestNewHostVolumeManager_restoreState(t *testing.T) { t.Run("get error", func(t *testing.T) { state := newMockState() state.getErr = errors.New("get error") - _, err := NewHostVolumeManager(log, state, "/wherever", "/wherever") + _, err := NewHostVolumeManager(log, state, time.Second, "/wherever", "/wherever") // error loading state should break the world must.ErrorIs(t, err, state.getErr) }) @@ -58,7 +59,7 @@ func TestNewHostVolumeManager_restoreState(t *testing.T) { must.Error(t, state.PutDynamicHostVolume(vol)) // restore process also attempts a state Put during vol Create - _, err := NewHostVolumeManager(log, state, "/wherever", t.TempDir()) + _, err := NewHostVolumeManager(log, state, time.Second, "/wherever", t.TempDir()) // but it should not cause the whole agent to fail to start must.NoError(t, err) })