func()

in pkg/monitor/asglifecycle/asg-lifecycle-monitor.go [65:94]


func (m ASGLifecycleMonitor) checkForASGTargetLifecycleStateNotice() (*monitor.InterruptionEvent, error) {
	state, err := m.IMDS.GetASGTargetLifecycleState()
	if err != nil {
		return nil, fmt.Errorf("There was a problem checking for ASG target lifecycle state: %w", err)
	}
	if state != "Terminated" {
		// if the state is not "Terminated", we can skip. State can also be empty (no hook configured).
		return nil, nil
	}

	nodeName := m.NodeName
	// there is no time in the response, we just set time to the latest check
	interruptionTime := time.Now()

	// There's no EventID returned, so we'll create it using a hash to prevent duplicates.
	hash := sha256.New()
	if _, err = hash.Write([]byte(fmt.Sprintf("%s:%s", state, interruptionTime))); 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("target-lifecycle-state-terminated-%x", hash.Sum(nil)),
		Kind:         monitor.ASGLifecycleKind,
		Monitor:      ASGLifecycleMonitorKind,
		StartTime:    interruptionTime,
		NodeName:     nodeName,
		Description:  "AST target lifecycle state received. Instance will be terminated\n",
		PreDrainTask: setInterruptionTaint,
	}, nil
}