From c57e760933fec52690e38cc018fa38f94862a2c4 Mon Sep 17 00:00:00 2001 From: Drew Bailey <2614075+drewbailey@users.noreply.github.com> Date: Thu, 15 Oct 2020 16:44:36 -0400 Subject: [PATCH] remove special node drain event type rely on standardized events instead of special node drain event --- nomad/state/events.go | 9 +------ nomad/state/node_events.go | 48 --------------------------------- nomad/state/node_events_test.go | 2 +- nomad/state/state_changes.go | 2 -- 4 files changed, 2 insertions(+), 59 deletions(-) diff --git a/nomad/state/events.go b/nomad/state/events.go index a5a65a02b..b9884a085 100644 --- a/nomad/state/events.go +++ b/nomad/state/events.go @@ -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, diff --git a/nomad/state/node_events.go b/nomad/state/node_events.go index 178262fb9..2bfc439e7 100644 --- a/nomad/state/node_events.go +++ b/nomad/state/node_events.go @@ -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 -} diff --git a/nomad/state/node_events_test.go b/nomad/state/node_events_test.go index 2789ae80f..597f66626 100644 --- a/nomad/state/node_events_test.go +++ b/nomad/state/node_events_test.go @@ -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) diff --git a/nomad/state/state_changes.go b/nomad/state/state_changes.go index c7a2d9634..fa4c27a7b 100644 --- a/nomad/state/state_changes.go +++ b/nomad/state/state_changes.go @@ -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) }