daemon: Inline bootstrapNode() into sync
Rename `checkStateOnBoot` to `checkStateOnFirstRun` since it
always runs on the MCD startup, not on the node boot.
`bootstrapNode()` was a very short function, let's inline it into
`checkStateOnFirstRun` so that function is the clear focus of logic.
@@ -313,24 +313,6 @@ func (dn *Daemon) processNextWorkItem() bool {
return true
}
-// bootstrapNode takes care of the very first sync of the MCD on a node.
-// It loads the node annotation from the bootstrap (if we're really bootstrapping)
-// and then proceed to checking the state of the node, which includes
-// finalizing an update and/or reconciling the current and desired machine configs.
-func (dn *Daemon) bootstrapNode() error {
- node, err := dn.loadNodeAnnotations(dn.node)
- if err != nil {
- return err
- }
- dn.node = node
- if err := dn.CheckStateOnBoot(); err != nil {
- return err
- }
- // finished syncing node for the first time
- dn.booting = false
- return nil
-}
-
func (dn *Daemon) handleErr(err error, key interface{}) {
if err == nil {
dn.queue.Forget(key)
@@ -388,11 +370,18 @@ func (dn *Daemon) syncNode(key string) error {
// Update our cached copy of the node
dn.node = node
- // Handle initial setup
+ // Take care of the very first sync of the MCD on a node.
+ // This loads the node annotation from the bootstrap (if we're really bootstrapping)
+ // and then proceed to checking the state of the node, which includes
+ // finalizing an update and/or reconciling the current and desired machine configs.
if dn.booting {
- if err := dn.bootstrapNode(); err != nil {
- return errors.Wrapf(err, "during bootstrap")
+ if err := dn.checkStateOnFirstRun(); err != nil {
+ return err
}
+ // finished syncing node for the first time;
+ // currently we return immediately here, although
+ // I think we should change this to continue.
+ dn.booting = false
return nil
}
@@ -805,14 +794,20 @@ func (dn *Daemon) storeCurrentConfigOnDisk(current *mcfgv1.MachineConfig) error
return writeFileAtomicallyWithDefaults(dn.currentConfigPath, mcJSON)
}
-// CheckStateOnBoot is a core entrypoint for our state machine.
+// checkStateOnFirstRun is a core entrypoint for our state machine.
// It determines whether we're in our desired state, or if we're
// transitioning between states, and whether or not we need to update
// to a new state. It also checks if someone jumped on a node before
// the daemon took over.
//
// Some more background in this PR: https://github.com/openshift/machine-config-operator/pull/245
-func (dn *Daemon) CheckStateOnBoot() error {
+func (dn *Daemon) checkStateOnFirstRun() error {
+ node, err := dn.loadNodeAnnotations(dn.node)
+ if err != nil {
+ return err
+ }
+ // Update our cached copy
+ dn.node = node
pendingConfigName, err := dn.getPendingState()
if err != nil {
return err
