Skip to content
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

pkg/daemon: allow reboots from external componenents #576

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
20 changes: 20 additions & 0 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,15 @@ func (dn *Daemon) bootstrapNode() error {
return err
}
dn.node = node
if _, err := os.Stat("/etc/defaults/rhcos/reboot-needed"); err == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, /etc/defaults is a legacy of SySV init; no reason to put anything new there.

The right place for this is more likely /run/machine-config-operator/reboot-needed or so. (We also have /etc/machine-config-daemon used for /etc/machine-config-daemon/state.json but I think /run makes more sense since it goes away automatically if the machine is rebooted)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if err := os.Remove("/etc/defaults/rhcos/reboot-needed"); err != nil {
return err
}
}
if err := dn.CheckStateOnBoot(); err != nil {
return err
}

// finished syncing node for the first time
dn.booting = false
return nil
Expand All @@ -330,6 +336,8 @@ func (dn *Daemon) bootstrapNode() error {
func (dn *Daemon) handleErr(err error, key interface{}) {
if err == nil {
dn.queue.Forget(key)
// This is a workaround to have the controller keep calling the syncHandler for the MCD reboot signaling
dn.queue.AddAfter(key, 5*time.Minute)
return
}

Expand Down Expand Up @@ -400,6 +408,18 @@ func (dn *Daemon) syncNode(key string) error {
return err
}
}
// FIXME: this is a temporary workaround, remove once an MCD signaling system is in place
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

if _, err := os.Stat("/etc/defaults/rhcos/reboot-needed"); err == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

dn.catchIgnoreSIGTERM()
if err := dn.drainNode(); err != nil {
dn.cancelSIGTERM()
return err
}
if err := dn.reboot("rebooting due to another component signaling"); err != nil {
dn.catchIgnoreSIGTERM()
return err
}
}
glog.V(2).Infof("Node %s is already synced", node.Name)
}
return nil
Expand Down
74 changes: 41 additions & 33 deletions pkg/daemon/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,46 +94,54 @@ func getNodeRef(node *corev1.Node) *corev1.ObjectReference {
}
}

func (dn *Daemon) drainNode() error {
// Skip draining of the node when we're not cluster driven
if dn.onceFrom != "" {
return nil
}

glog.Info("Update prepared; draining the node")
dn.recorder.Eventf(getNodeRef(dn.node), corev1.EventTypeNormal, "Drain", "Draining node to update config.")

backoff := wait.Backoff{
Steps: 5,
Duration: 10 * time.Second,
Factor: 2,
}
var lastErr error
if err := wait.ExponentialBackoff(backoff, func() (bool, error) {
err := drain.Drain(dn.kubeClient, []*corev1.Node{dn.node}, &drain.DrainOptions{
DeleteLocalData: true,
Force: true,
GracePeriodSeconds: 600,
IgnoreDaemonsets: true,
})
if err == nil {
return true, nil
}
lastErr = err
glog.Infof("Draining failed with: %v, retrying", err)
return false, nil

}); err != nil {
if err == wait.ErrWaitTimeout {
return errors.Wrapf(lastErr, "failed to drain node (%d tries): %v", backoff.Steps, err)
}
return errors.Wrap(err, "failed to drain node")
}
glog.Info("Node successfully drained")
return nil
}

// updateOSAndReboot is the last step in an update(), and it can also
// be called as a special case for the "bootstrap pivot".
func (dn *Daemon) updateOSAndReboot(newConfig *mcfgv1.MachineConfig) error {
if err := dn.updateOS(newConfig); err != nil {
return err
}

// Skip draining of the node when we're not cluster driven
if dn.onceFrom == "" {
glog.Info("Update prepared; draining the node")

dn.recorder.Eventf(getNodeRef(dn.node), corev1.EventTypeNormal, "Drain", "Draining node to update config.")

backoff := wait.Backoff{
Steps: 5,
Duration: 10 * time.Second,
Factor: 2,
}
var lastErr error
if err := wait.ExponentialBackoff(backoff, func() (bool, error) {
err := drain.Drain(dn.kubeClient, []*corev1.Node{dn.node}, &drain.DrainOptions{
DeleteLocalData: true,
Force: true,
GracePeriodSeconds: 600,
IgnoreDaemonsets: true,
})
if err == nil {
return true, nil
}
lastErr = err
glog.Infof("Draining failed with: %v, retrying", err)
return false, nil

}); err != nil {
if err == wait.ErrWaitTimeout {
return errors.Wrapf(lastErr, "failed to drain node (%d tries): %v", backoff.Steps, err)
}
return errors.Wrap(err, "failed to drain node")
}
glog.Info("Node successfully drained")
if err := dn.drainNode(); err != nil {
return err
}

if err := dn.writePendingState(newConfig); err != nil {
Expand Down