in pkg/monitor/spotitn/spot-itn-monitor.go [65:96]
func (m SpotInterruptionMonitor) checkForSpotInterruptionNotice() (*monitor.InterruptionEvent, error) {
instanceAction, err := m.IMDS.GetSpotITNEvent()
if instanceAction == nil && err == nil {
// if there are no spot itns and no errors
return nil, nil
}
if err != nil {
return nil, fmt.Errorf("There was a problem checking for spot ITNs: %w", err)
}
nodeName := m.NodeName
interruptionTime, err := time.Parse(time.RFC3339, instanceAction.Time)
if err != nil {
return nil, fmt.Errorf("Could not parse time from spot interruption notice metadata json: %w", err)
}
// There's no EventID returned so we'll create it using a hash to prevent duplicates.
hash := sha256.New()
_, err = hash.Write([]byte(fmt.Sprintf("%v", instanceAction)))
if err != nil {
return nil, fmt.Errorf("There was a problem creating an event ID from the event: %w", err)
}
return &monitor.InterruptionEvent{
EventID: fmt.Sprintf("spot-itn-%x", hash.Sum(nil)),
Kind: monitor.SpotITNKind,
Monitor: SpotITNMonitorKind,
StartTime: interruptionTime,
NodeName: nodeName,
Description: fmt.Sprintf("Spot ITN received. Instance will be interrupted at %s \n", instanceAction.Time),
PreDrainTask: setInterruptionTaint,
}, nil
}