Skip to content

Commit bc0dc4b

Browse files
authored
Drop sqs messages for absent nodes (#375)
1 parent e8efa78 commit bc0dc4b

File tree

3 files changed

+4
-11
lines changed

3 files changed

+4
-11
lines changed

Diff for: pkg/monitor/sqsevent/asg-lifecycle-event.go

-8
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,5 @@ func (m SQSMonitor) asgTerminationToInterruptionEvent(event EventBridgeEvent, me
109109
return nil
110110
}
111111

112-
if nodeName == "" {
113-
log.Info().Msg("Node name is empty, assuming instance was already terminated, deleting queue message")
114-
errs := m.deleteMessages([]*sqs.Message{message})
115-
if errs != nil {
116-
log.Warn().Errs("errors", errs).Msg("There was an error deleting the messages")
117-
}
118-
}
119-
120112
return interruptionEvent, nil
121113
}

Diff for: pkg/monitor/sqsevent/sqs-monitor.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,15 @@ func (m SQSMonitor) retrieveNodeName(instanceID string) (string, error) {
192192
return "", err
193193
}
194194
if len(result.Reservations) == 0 || len(result.Reservations[0].Instances) == 0 {
195-
return "", fmt.Errorf("No instance found with instance-id %s", instanceID)
195+
log.Info().Msgf("No instance found with instance-id %s", instanceID)
196+
return "", ErrNodeStateNotRunning
196197
}
197198

198199
instance := result.Reservations[0].Instances[0]
199200
nodeName := *instance.PrivateDnsName
200201
log.Debug().Msgf("Got nodename from private ip %s", nodeName)
201202
instanceJSON, _ := json.MarshalIndent(*instance, " ", " ")
202-
log.Debug().Msgf("Got nodename from ec2 describe call: %s", instanceJSON)
203+
log.Debug().Msgf("Got instance data from ec2 describe call: %s", instanceJSON)
203204

204205
if nodeName == "" {
205206
state := "unknown"

Diff for: pkg/monitor/sqsevent/sqs-monitor_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ func TestMonitor_EC2NoInstances(t *testing.T) {
474474
}
475475

476476
err = sqsMonitor.Monitor()
477-
h.Nok(t, err)
477+
h.Ok(t, err)
478478

479479
select {
480480
case <-drainChan:

0 commit comments

Comments
 (0)