Skip to content

Commit

Permalink
clarified some code around node drain in the state store
Browse files Browse the repository at this point in the history
  • Loading branch information
cgbaker committed Mar 30, 2021
1 parent e13ee79 commit 234c08b
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions nomad/state/state_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -1016,23 +1016,23 @@ func (s *StateStore) updateNodeDrainImpl(txn *txn, index uint64, nodeID string,
// Update LastDrain
updateTime := time.Unix(updatedAt, 0)

// if drain strategy isn't before or after, this wasn't a drain operation
// if drain strategy isn't set before or after, this wasn't a drain operation
// in that case, we don't care about .LastDrain
drainNoop := existingNode.DrainStrategy == nil && updatedNode.DrainStrategy == nil
// when done with this method, updatedNode.LastDrain should be set
// otherwise, when done with this method, updatedNode.LastDrain should be set
// if starting a new drain operation, create a new LastDrain. otherwise, update the existing one.
startedDraining := existingNode.DrainStrategy == nil && updatedNode.DrainStrategy != nil
// if already draining and LastDrain doesn't exist, we need to create a new one.
missingLastDrain := updatedNode.LastDrain == nil
if !drainNoop {
if startedDraining {
updatedNode.LastDrain = &structs.DrainMetadata{
StartedAt: updateTime,
Meta: drainMeta,
}
} else if missingLastDrain {
} else if updatedNode.LastDrain == nil {
// if already draining and LastDrain doesn't exist, we need to create a new one
// this could happen if we upgraded to 1.1.x during a drain
updatedNode.LastDrain = &structs.DrainMetadata{
// we don't have sub-second accuracy, so truncate this
// we don't have sub-second accuracy on these fields, so truncate this
StartedAt: time.Unix(existingNode.DrainStrategy.StartedAt.Unix(), 0),
Status: structs.DrainStatusDraining,
Meta: drainMeta,
Expand All @@ -1043,11 +1043,11 @@ func (s *StateStore) updateNodeDrainImpl(txn *txn, index uint64, nodeID string,

// won't have new metadata on drain complete; keep the existing operator-provided metadata
// also, keep existing if they didn't provide it
if drainMeta != nil {
if len(drainMeta) != 0 {
updatedNode.LastDrain.Meta = drainMeta
}

// we won't have an accessor ID for drain complete; don't overwrite the existing one
// we won't have an accessor ID on drain complete, so don't overwrite the existing one
if accessorId != "" {
updatedNode.LastDrain.AccessorID = accessorId
}
Expand Down

0 comments on commit 234c08b

Please sign in to comment.