resolver

package
v0.0.0-...-298751d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2024 License: AGPL-3.0 Imports: 11 Imported by: 31

Documentation

Index

Constants

View Source
const (
	// ErrNoOperation is used to indicate that there are no
	// currently pending operations to run.
	ErrNoOperation = errors.ConstError("no operations")

	// ErrRestart indicates that the resolver loop should
	// be restarted with a new remote state watcher.
	ErrRestart = errors.ConstError("restarting resolver")

	// ErrUnitDead indicates that the unit has been marked as dead and there
	// will be no more units to run after that.
	ErrUnitDead = errors.ConstError("unit dead")

	// ErrWaiting indicates that the resolver loop should
	// not execute any more operations until a remote state
	// event has occurred.
	ErrWaiting = errors.ConstError("waiting for remote state change")
)

Variables

View Source
var ErrDoNotProceed = errors.New("do not proceed")

ErrDoNotProceed is used to distinguish behaviour from resolver.ErrNoOperation. i.e do not run any operations versus this resolver has no operations to run.

View Source
var ErrLoopAborted = errors.New("resolver loop aborted")

ErrLoopAborted is used to signal that the loop is exiting because it received a value on its config's Abort chan.

Functions

func Loop

func Loop(cfg LoopConfig, localState *LocalState) error

Loop repeatedly waits for remote state changes, feeding the local and remote state to the provided Resolver to generate Operations which are then run with the provided Executor.

The provided "onIdle" function will be called when the loop is waiting for remote state changes due to a lack of work to perform. It will not be called when a change is anticipated (i.e. due to ErrWaiting).

The resolver loop can be controlled in the following ways:

  • if the "abort" channel is signalled, then the loop will exit with ErrLoopAborted
  • if the resolver returns ErrWaiting, then no operations will be executed until the remote state has changed again
  • if the resolver returns ErrNoOperation, then "onIdle" will be invoked and the loop will wait until the remote state has changed again
  • if the resolver, onIdle, or executor return some other error, the loop will exit immediately

Types

type LocalState

type LocalState struct {
	operation.State

	// CharmModifiedVersion increases any time the charm,
	// or any part of it, is changed in some way.
	CharmModifiedVersion int

	// CharmURL reports the currently installed charm URL as a string.
	// This is set by the committing of deploy (install/upgrade) ops.
	CharmURL string

	// Conflicted indicates that the uniter is in a conflicted state,
	// and needs either resolution or a forced upgrade to continue.
	Conflicted bool

	// Restart indicates that the resolver should exit with ErrRestart
	// at the earliest opportunity.
	Restart bool

	// UpdateStatusVersion is the version of update status from remotestate.Snapshot
	// for which an update-status hook has been committed.
	UpdateStatusVersion int

	// RetryHookVersion is the version of hook-retries from
	// remotestate.Snapshot for which a hook has been retried.
	RetryHookVersion int

	// LeaderSettingsVersion is the version of leader settings from
	// remotestate.Snapshot for which a leader-settings-changed hook has
	// been committed.
	LeaderSettingsVersion int

	// CompletedActions is the set of actions that have been completed.
	// This is used to prevent us re running actions requested by the
	// controller.
	CompletedActions map[string]struct{}

	// UpgradeMachineStatus is the current state of any currently running
	// upgrade series.
	UpgradeMachineStatus model.UpgradeSeriesStatus

	// ContainerRunningStatus is the current state of remote containers for CAAS.
	ContainerRunningStatus *remotestate.ContainerRunningStatus

	// OutdatedRemoteCharm is true when an upgrade has happened but the remotestate
	// needs an update.
	OutdatedRemoteCharm bool

	// HookWasShutdown is true if the hook exited due to a SIGTERM.
	HookWasShutdown bool
}

LocalState is a cache of the state of the local unit, as needed by the Uniter. It is generally compared to the remote state of the expected state of the unit as stored in the controller.

type Logger

type Logger interface {
	Errorf(string, ...interface{})
	Debugf(string, ...interface{})
	Tracef(string, ...interface{})
	Warningf(string, ...interface{})
}

Logger represents the logging methods used in this package.

type LoopConfig

type LoopConfig struct {
	Resolver      Resolver
	Watcher       remotestate.Watcher
	Executor      operation.Executor
	Factory       operation.Factory
	Abort         <-chan struct{}
	OnIdle        func() error
	CharmDirGuard fortress.Guard
	CharmDir      string
	Logger        Logger
}

LoopConfig contains configuration parameters for the resolver loop.

type Resolver

type Resolver interface {
	// NextOp returns the next operation to run to reconcile
	// the local state with the remote, desired state. The
	// operations returned must be created using the given
	// operation.Factory.
	//
	// This method must return ErrNoOperation if there are no
	// operations to perform.
	//
	// By returning ErrTerminate, the resolver indicates that
	// it will never have any more operations to perform,
	// and the caller can cease calling.
	NextOp(
		LocalState,
		remotestate.Snapshot,
		operation.Factory,
	) (operation.Operation, error)
}

Resolver instances use local (as is) and remote (to be) state to provide operations to run in order to progress towards the desired state.

type ResolverFunc

func (ResolverFunc) NextOp

func (f ResolverFunc) NextOp(
	local LocalState,
	remote remotestate.Snapshot,
	opFactory operation.Factory,
) (operation.Operation, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL