Merge pull request #9108 from hashicorp/rm-special-node-drain-event

remove special node drain event type
This commit is contained in:
Drew Bailey 2020-10-15 17:30:53 -04:00 committed by GitHub
commit 4c04b40c62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 2 additions and 59 deletions

View File

@ -51,14 +51,6 @@ type NodeEvent struct {
Node *structs.Node
}
// NNodeDrainEvent is the Payload for a NodeDrain event. It contains
// information related to the Node being drained as well as high level
// information about the current allocations on the Node
type NodeDrainEvent struct {
Node *structs.Node
JobAllocs map[string]*JobDrainDetails
}
type NodeDrainAllocDetails struct {
ID string
Migrate *structs.MigrateStrategy
@ -81,6 +73,7 @@ var MsgTypeEvents = map[structs.MessageType]string{
structs.JobBatchDeregisterRequestType: TypeJobBatchDeregistered,
structs.AllocUpdateDesiredTransitionRequestType: TypeAllocUpdateDesiredStatus,
structs.NodeUpdateEligibilityRequestType: TypeNodeDrain,
structs.NodeUpdateDrainRequestType: TypeNodeDrain,
structs.BatchNodeUpdateDrainRequestType: TypeNodeDrain,
structs.DeploymentStatusUpdateRequestType: TypeDeploymentUpdate,
structs.DeploymentPromoteRequestType: TypeDeploymentPromotion,

View File

@ -32,51 +32,3 @@ func NodeDeregisterEventFromChanges(tx ReadTxn, changes Changes) (*structs.Event
}
return &structs.Events{Index: changes.Index, Events: events}, nil
}
func NodeDrainEventFromChanges(tx ReadTxn, changes Changes) (*structs.Events, error) {
var events []structs.Event
for _, change := range changes.Changes {
switch change.Table {
case "nodes":
after, ok := change.After.(*structs.Node)
if !ok {
return nil, fmt.Errorf("transaction change was not a Node")
}
// retrieve allocations currently on node
allocs, err := allocsByNodeTxn(tx, nil, after.ID)
if err != nil {
return nil, fmt.Errorf("retrieving allocations for node drain event: %w", err)
}
// build job/alloc details for node drain
jobAllocs := make(map[string]*JobDrainDetails)
for _, a := range allocs {
if _, ok := jobAllocs[a.Job.Name]; !ok {
jobAllocs[a.Job.Name] = &JobDrainDetails{
AllocDetails: make(map[string]NodeDrainAllocDetails),
Type: a.Job.Type,
}
}
jobAllocs[a.Job.Name].AllocDetails[a.ID] = NodeDrainAllocDetails{
Migrate: a.MigrateStrategy(),
ID: a.ID,
}
}
event := structs.Event{
Topic: structs.TopicNode,
Type: TypeNodeDrain,
Index: changes.Index,
Key: after.ID,
Payload: &NodeDrainEvent{
Node: after,
JobAllocs: jobAllocs,
},
}
events = append(events, event)
}
}
return &structs.Events{Index: changes.Index, Events: events}, nil
}

View File

@ -255,7 +255,7 @@ func TestNodeDrainEventFromChanges(t *testing.T) {
require.Equal(t, TypeNodeDrain, got.Events[0].Type)
require.Equal(t, uint64(100), got.Events[0].Index)
nodeEvent, ok := got.Events[0].Payload.(*NodeDrainEvent)
nodeEvent, ok := got.Events[0].Payload.(*NodeEvent)
require.True(t, ok)
require.Equal(t, structs.NodeSchedulingIneligible, nodeEvent.Node.SchedulingEligibility)

View File

@ -188,8 +188,6 @@ func processDBChanges(tx ReadTxn, changes Changes) (*structs.Events, error) {
return nil, nil
case structs.NodeDeregisterRequestType:
return NodeDeregisterEventFromChanges(tx, changes)
case structs.NodeUpdateDrainRequestType:
return NodeDrainEventFromChanges(tx, changes)
default:
return GenericEventsFromChanges(tx, changes)
}