in pkg/node/node.go [598:644]
func (n Node) UncordonIfRebooted(nodeName string) error {
// TODO: this logic needs to be updated to dynamically look up the last reboot
// w/ the ec2 api if the nodeName is not local.
k8sNode, err := n.fetchKubernetesNode(nodeName)
if err != nil {
return fmt.Errorf("Unable to fetch kubernetes node from API: %w", err)
}
timeVal, ok := k8sNode.Labels[ActionLabelTimeKey]
if !ok {
log.Debug().Msgf("There was no %s label found requiring action label handling", ActionLabelTimeKey)
return nil
}
timeValNum, err := strconv.ParseInt(timeVal, 10, 64)
if err != nil {
return fmt.Errorf("Cannot convert unix time: %w", err)
}
secondsSinceLabel := time.Now().Unix() - timeValNum
switch actionVal := k8sNode.Labels[ActionLabelKey]; actionVal {
case UncordonAfterRebootLabelVal:
uptime, err := n.uptime()
if err != nil {
return err
}
if secondsSinceLabel < uptime {
log.Debug().Msg("The system has not restarted yet.")
return nil
}
err = n.Uncordon(nodeName)
if err != nil {
return fmt.Errorf("Unable to uncordon node: %w", err)
}
err = n.RemoveNTHLabels(nodeName)
if err != nil {
return err
}
err = n.RemoveNTHTaints(nodeName)
if err != nil {
return err
}
log.Info().Msgf("Successfully completed action %s.", UncordonAfterRebootLabelVal)
default:
log.Debug().Msg("There are no label actions to handle.")
}
return nil
}