Skip to content

Commit 32c9ad3

Browse files
authored
Add SQS InterruptionEvent.InstanceType (#1104)
* Add SQS InterruptionEvent.InstanceType * Fix indentation * Merge InstanceType fields in webhook.combinedDrainData * Fix formatting
1 parent 90f6262 commit 32c9ad3

File tree

10 files changed

+30
-14
lines changed

10 files changed

+30
-14
lines changed

pkg/monitor/sqsevent/asg-lifecycle-event.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func (m SQSMonitor) asgTerminationToInterruptionEvent(event *EventBridgeEvent, m
9191
IsManaged: nodeInfo.IsManaged,
9292
InstanceID: lifecycleDetail.EC2InstanceID,
9393
ProviderID: nodeInfo.ProviderID,
94+
InstanceType: nodeInfo.InstanceType,
9495
Description: fmt.Sprintf("ASG Lifecycle Termination event received. Instance will be interrupted at %s \n", event.getTime()),
9596
}
9697

pkg/monitor/sqsevent/ec2-state-change-event.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ func (m SQSMonitor) ec2StateChangeToInterruptionEvent(event *EventBridgeEvent, m
7575
AutoScalingGroupName: nodeInfo.AsgName,
7676
InstanceID: ec2StateChangeDetail.InstanceID,
7777
ProviderID: nodeInfo.ProviderID,
78+
InstanceType: nodeInfo.InstanceType,
7879
Description: fmt.Sprintf("EC2 State Change event received. Instance %s went into %s at %s \n", ec2StateChangeDetail.InstanceID, ec2StateChangeDetail.State, event.getTime()),
7980
}
8081

pkg/monitor/sqsevent/rebalance-recommendation-event.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func (m SQSMonitor) rebalanceRecommendationToInterruptionEvent(event *EventBridg
6767
IsManaged: nodeInfo.IsManaged,
6868
InstanceID: nodeInfo.InstanceID,
6969
ProviderID: nodeInfo.ProviderID,
70+
InstanceType: nodeInfo.InstanceType,
7071
Description: fmt.Sprintf("Rebalance recommendation event received. Instance %s will be cordoned at %s \n", rebalanceRecDetail.InstanceID, event.getTime()),
7172
}
7273
interruptionEvent.PostDrainTask = func(interruptionEvent monitor.InterruptionEvent, n node.Node) error {

pkg/monitor/sqsevent/scheduled-change-event.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ func (m SQSMonitor) scheduledEventToInterruptionEvents(event *EventBridgeEvent,
102102
NodeName: nodeInfo.Name,
103103
InstanceID: nodeInfo.InstanceID,
104104
ProviderID: nodeInfo.ProviderID,
105+
InstanceType: nodeInfo.InstanceType,
105106
IsManaged: nodeInfo.IsManaged,
106107
Description: fmt.Sprintf("AWS Health scheduled change event received. Instance %s will be interrupted at %s \n", nodeInfo.InstanceID, event.getTime()),
107108
}

pkg/monitor/sqsevent/spot-itn-event.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func (m SQSMonitor) spotITNTerminationToInterruptionEvent(event *EventBridgeEven
6969
IsManaged: nodeInfo.IsManaged,
7070
InstanceID: spotInterruptionDetail.InstanceID,
7171
ProviderID: nodeInfo.ProviderID,
72+
InstanceType: nodeInfo.InstanceType,
7273
Description: fmt.Sprintf("Spot Interruption notice for instance %s was sent at %s \n", spotInterruptionDetail.InstanceID, event.getTime()),
7374
}
7475
interruptionEvent.PostDrainTask = func(interruptionEvent monitor.InterruptionEvent, n node.Node) error {

pkg/monitor/sqsevent/sqs-monitor.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -340,12 +340,13 @@ func (m SQSMonitor) completeLifecycleAction(input *autoscaling.CompleteLifecycle
340340

341341
// NodeInfo is relevant information about a single node
342342
type NodeInfo struct {
343-
AsgName string
344-
InstanceID string
345-
ProviderID string
346-
IsManaged bool
347-
Name string
348-
Tags map[string]string
343+
AsgName string
344+
InstanceID string
345+
ProviderID string
346+
InstanceType string
347+
IsManaged bool
348+
Name string
349+
Tags map[string]string
349350
}
350351

351352
// getNodeInfo returns the NodeInfo record for the given instanceID.
@@ -411,11 +412,12 @@ func (m SQSMonitor) getNodeInfo(instanceID string) (*NodeInfo, error) {
411412
}
412413

413414
nodeInfo := &NodeInfo{
414-
Name: *instance.PrivateDnsName,
415-
InstanceID: instanceID,
416-
ProviderID: providerID,
417-
Tags: make(map[string]string),
418-
IsManaged: true,
415+
Name: *instance.PrivateDnsName,
416+
InstanceID: instanceID,
417+
ProviderID: providerID,
418+
InstanceType: *instance.InstanceType,
419+
Tags: make(map[string]string),
420+
IsManaged: true,
419421
}
420422
for _, t := range (*instance).Tags {
421423
nodeInfo.Tags[*t.Key] = *t.Value

pkg/monitor/sqsevent/sqs-monitor_internal_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ func getDescribeInstancesResp(instanceID string, privateDNSName string, tags map
199199
GroupName: aws.String(""),
200200
Tenancy: aws.String("default"),
201201
},
202+
InstanceType: aws.String("t3.medium"),
202203
PrivateDnsName: aws.String(privateDNSName),
203204
Tags: awsTags,
204205
},

pkg/monitor/sqsevent/sqs-monitor_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,7 @@ func getDescribeInstancesResp(privateDNSName string, withASGTag bool, withManage
929929
GroupName: aws.String(""),
930930
Tenancy: aws.String("default"),
931931
},
932+
InstanceType: aws.String("t3.medium"),
932933
PrivateDnsName: &privateDNSName,
933934
Tags: tags,
934935
},

pkg/monitor/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type InterruptionEvent struct {
5353
Pods []string
5454
InstanceID string
5555
ProviderID string
56+
InstanceType string
5657
IsManaged bool
5758
StartTime time.Time
5859
EndTime time.Time

pkg/webhook/webhook.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ import (
3333
type combinedDrainData struct {
3434
ec2metadata.NodeMetadata
3535
monitor.InterruptionEvent
36-
InstanceID string
36+
InstanceID string
37+
InstanceType string
3738
}
3839

3940
// Post makes a http post to send drain event data to webhook url
@@ -60,12 +61,17 @@ func Post(additionalInfo ec2metadata.NodeMetadata, event *monitor.InterruptionEv
6061
return
6162
}
6263

63-
// Need to merge the two data sources manually since both have an InstanceID field
64+
// Need to merge the two data sources manually since both have
65+
// InstanceID and InstanceType fields
6466
instanceID := additionalInfo.InstanceID
6567
if event.InstanceID != "" {
6668
instanceID = event.InstanceID
6769
}
68-
var combined = combinedDrainData{NodeMetadata: additionalInfo, InterruptionEvent: *event, InstanceID: instanceID}
70+
instanceType := additionalInfo.InstanceType
71+
if event.InstanceType != "" {
72+
instanceType = event.InstanceType
73+
}
74+
var combined = combinedDrainData{NodeMetadata: additionalInfo, InterruptionEvent: *event, InstanceID: instanceID, InstanceType: instanceType}
6975

7076
var byteBuffer bytes.Buffer
7177
err = webhookTemplate.Execute(&byteBuffer, combined)

0 commit comments

Comments
 (0)