Skip to content

Commit

Permalink
refactor: rename CSI state store functions for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross committed Feb 8, 2022
1 parent 79e8d39 commit 84810dc
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions nomad/state/state_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ func upsertNodeTxn(txn *txn, index uint64, node *structs.Node) error {
if err := txn.Insert("index", &IndexEntry{"nodes", index}); err != nil {
return fmt.Errorf("index update failed: %v", err)
}
if err := upsertNodeCSIPlugins(txn, node, index); err != nil {
if err := upsertCSIPluginsForNode(txn, node, index); err != nil {
return fmt.Errorf("csi plugin update failed: %v", err)
}

Expand Down Expand Up @@ -1178,11 +1178,11 @@ func appendNodeEvents(index uint64, node *structs.Node, events []*structs.NodeEv
}
}

// upsertNodeCSIPlugins indexes csi plugins for volume retrieval, with health. It's called
// upsertCSIPluginsForNode indexes csi plugins for volume retrieval, with health. It's called
// on upsertNodeEvents, so that event driven health changes are updated
func upsertNodeCSIPlugins(txn *txn, node *structs.Node, index uint64) error {
func upsertCSIPluginsForNode(txn *txn, node *structs.Node, index uint64) error {

loop := func(info *structs.CSIInfo) error {
upsertFn := func(info *structs.CSIInfo) error {
raw, err := txn.First("csi_plugins", "id", info.PluginID)
if err != nil {
return fmt.Errorf("csi_plugin lookup error: %s %v", info.PluginID, err)
Expand Down Expand Up @@ -1226,15 +1226,15 @@ func upsertNodeCSIPlugins(txn *txn, node *structs.Node, index uint64) error {
inUseNode := map[string]struct{}{}

for _, info := range node.CSIControllerPlugins {
err := loop(info)
err := upsertFn(info)
if err != nil {
return err
}
inUseController[info.PluginID] = struct{}{}
}

for _, info := range node.CSINodePlugins {
err := loop(info)
err := upsertFn(info)
if err != nil {
return err
}
Expand Down Expand Up @@ -3228,7 +3228,7 @@ func (s *StateStore) nestedUpdateAllocFromClient(txn *txn, index uint64, alloc *
return err
}

if err := s.updatePluginWithAlloc(index, copyAlloc, txn); err != nil {
if err := s.updatePluginForTerminalAlloc(index, copyAlloc, txn); err != nil {
return err
}

Expand Down Expand Up @@ -3337,7 +3337,7 @@ func (s *StateStore) upsertAllocsImpl(index uint64, allocs []*structs.Allocation
return err
}

if err := s.updatePluginWithAlloc(index, alloc, txn); err != nil {
if err := s.updatePluginForTerminalAlloc(index, alloc, txn); err != nil {
return err
}

Expand Down Expand Up @@ -4782,7 +4782,7 @@ func (s *StateStore) updateJobScalingPolicies(index uint64, job *structs.Job, tx
func (s *StateStore) updateJobCSIPlugins(index uint64, job, prev *structs.Job, txn *txn) error {
plugIns := make(map[string]*structs.CSIPlugin)

loop := func(job *structs.Job, delete bool) error {
upsertFn := func(job *structs.Job, delete bool) error {
for _, tg := range job.TaskGroups {
for _, t := range tg.Tasks {
if t.CSIPluginConfig == nil {
Expand Down Expand Up @@ -4816,13 +4816,13 @@ func (s *StateStore) updateJobCSIPlugins(index uint64, job, prev *structs.Job, t
}

if prev != nil {
err := loop(prev, true)
err := upsertFn(prev, true)
if err != nil {
return err
}
}

err := loop(job, false)
err := upsertFn(job, false)
if err != nil {
return err
}
Expand Down Expand Up @@ -5067,10 +5067,11 @@ func (s *StateStore) updateSummaryWithAlloc(index uint64, alloc *structs.Allocat
return nil
}

// updatePluginWithAlloc updates the CSI plugins for an alloc when the
// updatePluginForTerminalAlloc updates the CSI plugins for an alloc when the
// allocation is updated or inserted with a terminal server status.
func (s *StateStore) updatePluginWithAlloc(index uint64, alloc *structs.Allocation,
func (s *StateStore) updatePluginForTerminalAlloc(index uint64, alloc *structs.Allocation,
txn *txn) error {

if !alloc.ServerTerminalStatus() {
return nil
}
Expand Down

0 comments on commit 84810dc

Please sign in to comment.