in pkg/monitor/rebalancerecommendation/rebalance-recommendation-monitor.go [63:94]
func (m RebalanceRecommendationMonitor) checkForRebalanceRecommendation() (*monitor.InterruptionEvent, error) {
rebalanceRecommendation, err := m.IMDS.GetRebalanceRecommendationEvent()
if err != nil {
return nil, fmt.Errorf("There was a problem checking for rebalance recommendations: %w", err)
}
if rebalanceRecommendation == nil {
// if there are no rebalance recommendations and no errors
return nil, nil
}
nodeName := m.NodeName
noticeTime, err := time.Parse(time.RFC3339, rebalanceRecommendation.NoticeTime)
if err != nil {
return nil, fmt.Errorf("Could not parse time from rebalance recommendation 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", rebalanceRecommendation)))
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("rebalance-recommendation-%x", hash.Sum(nil)),
Kind: monitor.RebalanceRecommendationKind,
Monitor: RebalanceRecommendationMonitorKind,
StartTime: noticeTime,
NodeName: nodeName,
Description: fmt.Sprintf("Rebalance recommendation received. Instance will be cordoned at %s \n", rebalanceRecommendation.NoticeTime),
PreDrainTask: setInterruptionTaint,
}, nil
}