Skip to content

add pods to webhook event and log pods on node #447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions cmd/node-termination-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,21 @@ func drainOrCordonIfNecessary(interruptionEventStore *interruptioneventstore.Sto
}

if nthConfig.CordonOnly || (drainEvent.IsRebalanceRecommendation() && !nthConfig.EnableRebalanceDraining) {
cordonNode(node, nodeName, drainEvent, metrics, recorder)
err = cordonNode(node, nodeName, drainEvent, metrics, recorder)
} else {
cordonAndDrainNode(node, nodeName, metrics, recorder, nthConfig.EnableSQSTerminationDraining)
err = cordonAndDrainNode(node, nodeName, metrics, recorder, nthConfig.EnableSQSTerminationDraining)
}

if err != nil {
podNameList, err := node.FetchPodNameList(nodeName)
drainEvent.Pods = podNameList
if err != nil {
log.Err(err).Msgf("Unable to fetch running pods for node '%s' ", nodeName)
}
err = node.LogPods(podNameList, nodeName)
if err != nil {
log.Err(err).Msg("There was a problem while trying to log all pod names on the node")
}
}

interruptionEventStore.MarkAllAsProcessed(nodeName)
Expand All @@ -336,7 +348,7 @@ func runPreDrainTask(node node.Node, nodeName string, drainEvent *monitor.Interr
metrics.NodeActionsInc("pre-drain", nodeName, err)
}

func cordonNode(node node.Node, nodeName string, drainEvent *monitor.InterruptionEvent, metrics observability.Metrics, recorder observability.K8sEventRecorder) {
func cordonNode(node node.Node, nodeName string, drainEvent *monitor.InterruptionEvent, metrics observability.Metrics, recorder observability.K8sEventRecorder) error {
err := node.Cordon(nodeName)
if err != nil {
if errors.IsNotFound(err) {
Expand All @@ -346,23 +358,16 @@ func cordonNode(node node.Node, nodeName string, drainEvent *monitor.Interruptio
recorder.Emit(nodeName, observability.Warning, observability.CordonErrReason, observability.CordonErrMsgFmt, err.Error())
os.Exit(1)
}
return err
} else {
log.Info().Str("node_name", nodeName).Msg("Node successfully cordoned")
podNameList, err := node.FetchPodNameList(nodeName)
drainEvent.Pods = podNameList
if err != nil {
log.Err(err).Msgf("Unable to fetch running pods for node '%s' ", nodeName)
}
err = node.LogPods(podNameList, nodeName)
if err != nil {
log.Err(err).Msg("There was a problem while trying to log all pod names on the node")
}
metrics.NodeActionsInc("cordon", nodeName, err)
recorder.Emit(nodeName, observability.Normal, observability.CordonReason, observability.CordonMsg)
}
return nil
}

func cordonAndDrainNode(node node.Node, nodeName string, metrics observability.Metrics, recorder observability.K8sEventRecorder, sqsTerminationDraining bool) {
func cordonAndDrainNode(node node.Node, nodeName string, metrics observability.Metrics, recorder observability.K8sEventRecorder, sqsTerminationDraining bool) error {
err := node.CordonAndDrain(nodeName)
if err != nil {
if errors.IsNotFound(err) {
Expand All @@ -375,11 +380,13 @@ func cordonAndDrainNode(node node.Node, nodeName string, metrics observability.M
os.Exit(1)
}
}
return err
} else {
log.Info().Str("node_name", nodeName).Msg("Node successfully cordoned and drained")
metrics.NodeActionsInc("cordon-and-drain", nodeName, err)
recorder.Emit(nodeName, observability.Normal, observability.CordonAndDrainReason, observability.CordonAndDrainMsg)
}
return nil
}

func runPostDrainTask(node node.Node, nodeName string, drainEvent *monitor.InterruptionEvent, metrics observability.Metrics, recorder observability.K8sEventRecorder) {
Expand Down