caasoperator

package
v0.0.0-...-a753888 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: AGPL-3.0 Imports: 63 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoStateFile = errors.New("operator state file does not exist")

ErrNoStateFile is used to indicate an operator state file does not exist.

Functions

func LoadOperatorInfo

func LoadOperatorInfo(paths Paths) (*caas.OperatorInfo, error)

LoadOperatorInfo loads the operator info file from the state dir.

func Manifold

func Manifold(config ManifoldConfig) dependency.Manifold

Manifold returns a dependency manifold that runs a caasoperator worker, using the resource names defined in the supplied config.

func NewWorker

func NewWorker(config Config) (worker.Worker, error)

NewWorker creates a new worker which will install and operate a CaaS-based application, by executing hooks and operations in response to application state changes.

Types

type ApplicationWatcher

type ApplicationWatcher interface {
	Watch(string) (watcher.NotifyWatcher, error)
}

ApplicationWatcher provides an interface watching for application changes.

type CharmConfigGetter

type CharmConfigGetter interface {
	CharmConfig(string) (charm.Settings, error)
	WatchCharmConfig(string) (watcher.NotifyWatcher, error)
}

CharmConfigGetter provides an interface for watching and getting the application's charm config settings.

type CharmGetter

type CharmGetter interface {
	Charm(application string) (*caasoperatorapi.CharmInfo, error)
}

CharmGetter provides an interface for getting the URL and SHA256 hash of the charm currently assigned to the application.

type Client

Client provides an interface for interacting with the CAASOperator API. Subsets of this should be passed to the CAASOperator worker.

type Config

type Config struct {
	Logger Logger

	// ModelUUID is the UUID of the model.
	ModelUUID string

	// ModelName is the name of the model.
	ModelName string

	// Application holds the name of the application that
	// this CAAS operator manages.
	Application string

	// CharmGetter is an interface used for getting the
	// application's charm URL and SHA256 hash.
	CharmGetter CharmGetter

	// Clock holds the clock to be used by the CAAS operator
	// for time-related operations.
	Clock clock.Clock

	// DataDir holds the path to the Juju "data directory",
	// i.e. "/var/lib/juju" (by default). The CAAS operator
	// expects to find the jujud binary at <data-dir>/tools/jujud.
	DataDir string

	// ProfileDir is where the introspection scripts are written.
	ProfileDir string

	// Downloader is an interface used for downloading the
	// application charm.
	Downloader Downloader

	// StatusSetter is an interface used for setting the
	// application status.
	StatusSetter StatusSetter

	// UnitGetter is an interface for getting a unit.
	UnitGetter UnitGetter

	// UnitRemover is an interface for removing a unit.
	UnitRemover UnitRemover

	// ApplicationWatcher is an interface for getting info about an application's charm.
	ApplicationWatcher ApplicationWatcher

	// ContainerStartWatcher provides an interface for watching
	// for unit container starts.
	ContainerStartWatcher ContainerStartWatcher

	// VersionSetter is an interface for setting the operator agent version.
	VersionSetter VersionSetter

	// LeadershipTrackerFunc is a function for getting a leadership tracker worker.
	LeadershipTrackerFunc func(unitTag names.UnitTag) leadership.TrackerWorker

	// UniterFacadeFunc is a function for making a uniter facade.
	UniterFacadeFunc func(unitTag names.UnitTag) *apiuniter.State

	// ResourcesFacadeFunc is a function for making a unit resources facade.
	ResourcesFacadeFunc func(unitTag names.UnitTag) (*apiuniter.ResourcesFacadeClient, error)

	// PayloadFacadeFunc is a function for making a unit payload facade.
	PayloadFacadeFunc func() *apiuniter.PayloadFacadeClient

	// UniterParams are parameters used to construct a uniter worker.
	UniterParams *uniter.UniterParams

	// StartUniterFunc starts a uniter worker using the given runner.
	StartUniterFunc func(runner *worker.Runner, params *uniter.UniterParams) error

	// RunListenerSocketFunc returns a socket used for the juju run listener.
	RunListenerSocketFunc func(*uniter.SocketConfig) (*sockets.Socket, error)

	// OperatorInfo contains serving information such as Certs and PrivateKeys.
	OperatorInfo caas.OperatorInfo

	// ExecClientGetter returns an exec client for initializing caas units.
	ExecClientGetter func() (exec.Executor, error)
}

Config hold the configuration for a caasoperator worker.

func (Config) Validate

func (config Config) Validate() error

type ContainerStartWatcher

type ContainerStartWatcher interface {
	WatchContainerStart(string, string) (watcher.StringsWatcher, error)
}

ContainerStartWatcher provides an interface for watching for unit starts.

type Downloader

type Downloader interface {
	// Download downloads a file to a local directory, and
	// returns the local path to the file.
	Download(downloader.Request) (string, error)
}

Downloader provides an interface for downloading files to disk.

type LocalState

type LocalState struct {
	// 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. This is set
	// by the committing of deploy (install/upgrade) ops.
	CharmURL *charm.URL
}

LocalState is a cache of the state of the operator It is generally compared to the remote state of the the application as stored in the controller.

type Logger

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

	Child(string) loggo.Logger
}

type ManifoldConfig

type ManifoldConfig struct {
	Logger Logger

	AgentName     string
	APICallerName string
	ClockName     string

	MachineLock           machinelock.Lock
	LeadershipGuarantee   time.Duration
	CharmDirName          string
	ProfileDir            string
	HookRetryStrategyName string
	TranslateResolverErr  func(error) error

	NewWorker          func(Config) (worker.Worker, error)
	NewClient          func(base.APICaller) Client
	NewCharmDownloader func(base.APICaller) Downloader

	NewExecClient     func(namespace string) (exec.Executor, error)
	RunListenerSocket func(*uniter.SocketConfig) (*sockets.Socket, error)

	LoadOperatorInfo func(paths Paths) (*caas.OperatorInfo, error)

	NewContainerStartWatcherClient func(Client) ContainerStartWatcher
}

ManifoldConfig defines the names of the manifolds on which a Manifold will depend.

func (ManifoldConfig) Validate

func (config ManifoldConfig) Validate() error

type Paths

type Paths struct {

	// ToolsDir is the directory containing the jujud executable running this
	// process; and also containing hook tool symlinks to that executable. It's
	// the only path in this struct that is not typically pointing inside the
	// directory reserved for the exclusive use of this worker (typically
	// /var/lib/juju/tools )
	ToolsDir string

	// Runtime represents the set of paths that are relevant at runtime.
	Runtime RuntimePaths

	// State represents the set of paths that hold persistent local state for
	// the operator.
	State StatePaths
}

Paths represents the set of filesystem paths a caasoperator worker has reason to care about.

func NewPaths

func NewPaths(dataDir string, applicationTag names.ApplicationTag) Paths

NewPaths returns the set of filesystem paths that the supplied unit should use, given the supplied root juju data directory path.

func (Paths) ComponentDir

func (paths Paths) ComponentDir(name string) string

ComponentDir returns the filesystem path to the directory containing all data files for a component.

func (Paths) GetBaseDir

func (paths Paths) GetBaseDir() string

GetBaseDir exists to satisfy the context.Paths interface.

func (Paths) GetCharmDir

func (paths Paths) GetCharmDir() string

GetCharmDir exists to satisfy the context.Paths interface.

func (Paths) GetMetricsSpoolDir

func (paths Paths) GetMetricsSpoolDir() string

GetMetricsSpoolDir exists to satisfy the runner.Paths interface.

func (Paths) GetToolsDir

func (paths Paths) GetToolsDir() string

GetToolsDir exists to satisfy the context.Paths interface.

type RuntimePaths

type RuntimePaths struct {

	// JujuExecSocket listens for juju-exec invocations, and is always
	// active.
	JujuExecSocket string

	// HookCommandServerSocket listens for hook command invocations, and is only
	// active when supporting a hook execution context.
	HookCommandServerSocket string
}

RuntimePaths represents the set of paths that are relevant at runtime.

type StateFile

type StateFile struct {
	// contains filtered or unexported fields
}

StateFile holds the disk state for an operator.

func NewStateFile

func NewStateFile(path string) *StateFile

NewStateFile returns a new StateFile using path.

func (*StateFile) Read

func (f *StateFile) Read() (*LocalState, error)

Read reads a State from the file. If the file does not exist it returns ErrNoStateFile.

func (*StateFile) Write

func (f *StateFile) Write(st *LocalState) error

Write stores the supplied state to the file.

type StatePaths

type StatePaths struct {

	// BaseDir is the operator's base directory.
	BaseDir string

	// CharmDir is the directory to which the charm the operator runs is deployed.
	CharmDir string

	// OperationsFile holds information about what the operator is doing
	// and/or has done.
	OperationsFile string

	// BundlesDir holds downloaded charms.
	BundlesDir string

	// DeployerDir holds metadata about charms that are installing or have
	// been installed.
	DeployerDir string

	// MetricsSpoolDir acts as temporary storage for metrics being sent from
	// the operator to state.
	MetricsSpoolDir string
}

StatePaths represents the set of paths that hold persistent local state for the operator.

type StatusSetter

type StatusSetter interface {
	// SetStatus sets the status of an application.
	SetStatus(
		application string,
		status status.Status,
		info string,
		data map[string]interface{},
	) error
}

StatusSetter provides an interface for setting the status of a CAAS application.

type UnitGetter

type UnitGetter interface {
	WatchUnits(string) (watcher.StringsWatcher, error)
	Life(string) (life.Value, error)
}

UnitGetter provides an interface for watching for the lifecycle state changes (including addition) of a specified application's units, and fetching their details.

type UnitRemover

type UnitRemover interface {
	RemoveUnit(string) error
}

UnitRemover provides an interface for removing a unit.

type VersionSetter

type VersionSetter interface {
	SetVersion(appName string, v version.Binary) error
}

VersionSetter provides an interface for setting the operator agent version.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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