From 5b7b9fdafb7d6026584505606fae8d9969543183 Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Thu, 24 Feb 2022 08:53:15 -0500 Subject: [PATCH] csi: tolerate missing plugins on job delete (#12114) If a plugin job fails before successfully fingerprinting the plugins, the plugin will not exist when we try to delete the job. Tolerate missing plugins. --- .changelog/12114.txt | 3 +++ nomad/state/state_store.go | 10 +++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 .changelog/12114.txt diff --git a/.changelog/12114.txt b/.changelog/12114.txt new file mode 100644 index 000000000..477122945 --- /dev/null +++ b/.changelog/12114.txt @@ -0,0 +1,3 @@ +```release-note:bug +csi: Fixed a bug where purging a job with a missing plugin would fail +``` diff --git a/nomad/state/state_store.go b/nomad/state/state_store.go index 7e9edeeeb..b8215b4ba 100644 --- a/nomad/state/state_store.go +++ b/nomad/state/state_store.go @@ -1460,7 +1460,9 @@ func (s *StateStore) deleteJobFromPlugins(index uint64, txn Txn, job *structs.Jo return fmt.Errorf("error getting plugin: %s, %v", x.pluginID, err) } if plug == nil { - return fmt.Errorf("plugin missing: %s %v", x.pluginID, err) + // plugin was never successfully registered or has been + // GC'd out from under us + continue } // only copy once, so we update the same plugin on each alloc plugins[x.pluginID] = plug.Copy() @@ -1484,8 +1486,10 @@ func (s *StateStore) deleteJobFromPlugins(index uint64, txn Txn, job *structs.Jo } } - if err = txn.Insert("index", &IndexEntry{"csi_plugins", index}); err != nil { - return fmt.Errorf("index update failed: %v", err) + if len(plugins) > 0 { + if err = txn.Insert("index", &IndexEntry{"csi_plugins", index}); err != nil { + return fmt.Errorf("index update failed: %v", err) + } } return nil