github.com/juju/juju@v0.0.0-20240327075706-a90865de2538/worker/uniter/resolver/interface.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package resolver
     5  
     6  import (
     7  	"github.com/juju/errors"
     8  
     9  	"github.com/juju/juju/core/model"
    10  	"github.com/juju/juju/worker/uniter/operation"
    11  	"github.com/juju/juju/worker/uniter/remotestate"
    12  )
    13  
    14  const (
    15  	// ErrNoOperation is used to indicate that there are no
    16  	// currently pending operations to run.
    17  	ErrNoOperation = errors.ConstError("no operations")
    18  
    19  	// ErrRestart indicates that the resolver loop should
    20  	// be restarted with a new remote state watcher.
    21  	ErrRestart = errors.ConstError("restarting resolver")
    22  
    23  	// ErrUnitDead indicates that the unit has been marked as dead and there
    24  	// will be no more units to run after that.
    25  	ErrUnitDead = errors.ConstError("unit dead")
    26  
    27  	// ErrWaiting indicates that the resolver loop should
    28  	// not execute any more operations until a remote state
    29  	// event has occurred.
    30  	ErrWaiting = errors.ConstError("waiting for remote state change")
    31  )
    32  
    33  // Resolver instances use local (as is) and remote (to be) state
    34  // to provide operations to run in order to progress towards
    35  // the desired state.
    36  type Resolver interface {
    37  	// NextOp returns the next operation to run to reconcile
    38  	// the local state with the remote, desired state. The
    39  	// operations returned must be created using the given
    40  	// operation.Factory.
    41  	//
    42  	// This method must return ErrNoOperation if there are no
    43  	// operations to perform.
    44  	//
    45  	// By returning ErrTerminate, the resolver indicates that
    46  	// it will never have any more operations to perform,
    47  	// and the caller can cease calling.
    48  	NextOp(
    49  		LocalState,
    50  		remotestate.Snapshot,
    51  		operation.Factory,
    52  	) (operation.Operation, error)
    53  }
    54  
    55  // LocalState is a cache of the state of the local unit, as needed by the
    56  // Uniter. It is generally compared to the remote state of the expected state of
    57  // the unit as stored in the controller.
    58  type LocalState struct {
    59  	operation.State
    60  
    61  	// CharmModifiedVersion increases any time the charm,
    62  	// or any part of it, is changed in some way.
    63  	CharmModifiedVersion int
    64  
    65  	// CharmURL reports the currently installed charm URL as a string.
    66  	// This is set by the committing of deploy (install/upgrade) ops.
    67  	CharmURL string
    68  
    69  	// Conflicted indicates that the uniter is in a conflicted state,
    70  	// and needs either resolution or a forced upgrade to continue.
    71  	Conflicted bool
    72  
    73  	// Restart indicates that the resolver should exit with ErrRestart
    74  	// at the earliest opportunity.
    75  	Restart bool
    76  
    77  	// UpdateStatusVersion is the version of update status from remotestate.Snapshot
    78  	// for which an update-status hook has been committed.
    79  	UpdateStatusVersion int
    80  
    81  	// RetryHookVersion is the version of hook-retries from
    82  	// remotestate.Snapshot for which a hook has been retried.
    83  	RetryHookVersion int
    84  
    85  	// LeaderSettingsVersion is the version of leader settings from
    86  	// remotestate.Snapshot for which a leader-settings-changed hook has
    87  	// been committed.
    88  	LeaderSettingsVersion int
    89  
    90  	// CompletedActions is the set of actions that have been completed.
    91  	// This is used to prevent us re running actions requested by the
    92  	// controller.
    93  	CompletedActions map[string]struct{}
    94  
    95  	// UpgradeMachineStatus is the current state of any currently running
    96  	// upgrade series.
    97  	UpgradeMachineStatus model.UpgradeSeriesStatus
    98  
    99  	// ContainerRunningStatus is the current state of remote containers for CAAS.
   100  	ContainerRunningStatus *remotestate.ContainerRunningStatus
   101  
   102  	// OutdatedRemoteCharm is true when an upgrade has happened but the remotestate
   103  	// needs an update.
   104  	OutdatedRemoteCharm bool
   105  
   106  	// HookWasShutdown is true if the hook exited due to a SIGTERM.
   107  	HookWasShutdown bool
   108  }