MCPcopy Create free account
hub / github.com/aws/aws-node-termination-handler / UncordonIfRebooted

Method UncordonIfRebooted

pkg/node/node.go:598–644  ·  view source on GitHub ↗

UncordonIfRebooted will check for node labels to trigger an uncordon because of a system-reboot scheduled event

(nodeName string)

Source from the content-addressed store, hash-verified

596
597// UncordonIfRebooted will check for node labels to trigger an uncordon because of a system-reboot scheduled event
598func (n Node) UncordonIfRebooted(nodeName string) error {
599 // TODO: this logic needs to be updated to dynamically look up the last reboot
600 // w/ the ec2 api if the nodeName is not local.
601 k8sNode, err := n.fetchKubernetesNode(nodeName)
602 if err != nil {
603 return fmt.Errorf("unable to fetch kubernetes node from API: %w", err)
604 }
605 timeVal, ok := k8sNode.Labels[ActionLabelTimeKey]
606 if !ok {
607 log.Debug().Msgf("There was no %s label found requiring action label handling", ActionLabelTimeKey)
608 return nil
609 }
610 timeValNum, err := strconv.ParseInt(timeVal, 10, 64)
611 if err != nil {
612 return fmt.Errorf("cannot convert unix time: %w", err)
613 }
614 secondsSinceLabel := time.Now().Unix() - timeValNum
615 switch actionVal := k8sNode.Labels[ActionLabelKey]; actionVal {
616 case UncordonAfterRebootLabelVal:
617 uptime, err := n.uptime()
618 if err != nil {
619 return err
620 }
621 if secondsSinceLabel < uptime {
622 log.Debug().Msg("The system has not restarted yet.")
623 return nil
624 }
625 err = n.Uncordon(nodeName)
626 if err != nil {
627 return fmt.Errorf("unable to uncordon node: %w", err)
628 }
629 err = n.RemoveNTHLabels(nodeName)
630 if err != nil {
631 return err
632 }
633
634 err = n.RemoveNTHTaints(nodeName)
635 if err != nil {
636 return err
637 }
638
639 log.Info().Msgf("Successfully completed action %s.", UncordonAfterRebootLabelVal)
640 default:
641 log.Debug().Msg("There are no label actions to handle.")
642 }
643 return nil
644}
645
646// fetchKubernetesNode will send an http request to the k8s api server and return the corev1 model node
647func (n Node) fetchKubernetesNode(nodeName string) (*corev1.Node, error) {

Calls 4

fetchKubernetesNodeMethod · 0.95
UncordonMethod · 0.95
RemoveNTHLabelsMethod · 0.95
RemoveNTHTaintsMethod · 0.95