resource

package
v0.0.0-...-3f873ad Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrActionNotSupported      = errors.New("the resource action is not supported on resource")
	ErrActionPostponedToLinker = errors.New("the resource action is postponed to its linker")
	ErrDisabled                = errors.New("the resource is disabled")
	ErrActionReqNotMet         = errors.New("the resource action requirements are not met")
)

Functions

func Action

func Action(ctx context.Context, r Driver) error

Action calls the resource method set as the RES_ACTION environment variable

func Boot

func Boot(ctx context.Context, r Driver) error

Boot deactivates a resource when the node is rebooted

func EvalStatus

func EvalStatus(ctx context.Context, r Driver) status.T

EvalStatus evaluates the status of a resource interfacer

func Full

func Full(ctx context.Context, r Driver) error

Full execute the resource Update function, if implemented by the driver.

func ImportDevices

func ImportDevices(r Driver) error

ImportDevices execute the Driver ImportDevices() function if defined. Some drivers need to import devices before they can list the reservable devices to register. So use this in the start codepath.

func NewResourceFunc

func NewResourceFunc(drvID driver.ID) func() Driver

func PRStart

func PRStart(ctx context.Context, r Driver) error

PRStart activates a resource interfacer S3GPR

func PRStop

func PRStop(ctx context.Context, r Driver) error

PRStop deactivates a resource interfacer S3GPR

func Provision

func Provision(ctx context.Context, r Driver, leader bool) error

Provision handles triggers around provision() and resource dependencies

func Provisioned

func Provisioned(t Driver) (provisioned.T, error)

func Resync

func Resync(ctx context.Context, r Driver) error

Resync execute the resource Resync function, if implemented by the driver.

func Run

func Run(ctx context.Context, r Driver) error

Run calls Run() if the resource is a Runner

func SCSIPersistentReservationStart

func SCSIPersistentReservationStart(ctx context.Context, r Driver) error

func SCSIPersistentReservationStatus

func SCSIPersistentReservationStatus(r Driver) status.T

func SCSIPersistentReservationStop

func SCSIPersistentReservationStop(ctx context.Context, r Driver) error

func SetProvisioned

func SetProvisioned(ctx context.Context, r Driver) error

SetProvisioned creates a flag file in the resource var dir to remember that the provision is done.

func SetUnprovisioned

func SetUnprovisioned(ctx context.Context, r Driver) error

SetUnprovisioned removes the flag file in the resource var dir to forget that the provision is done.

func Setenv

func Setenv(r Driver)

func Shutdown

func Shutdown(ctx context.Context, r Driver) error

Shutdown deactivates a resource even if standby is true

func Start

func Start(ctx context.Context, r Driver) error

Start activates a resource interfacer

func StartStandby

func StartStandby(ctx context.Context, r Driver) error

StartStandby activates a resource interfacer

func StatusCheckRequires

func StatusCheckRequires(ctx context.Context, r Driver) error

func Stop

func Stop(ctx context.Context, r Driver) error

Stop deactivates a resource

func Unprovision

func Unprovision(ctx context.Context, r Driver, leader bool) error

Unprovision handles triggers around unprovision() and resource dependencies

func Update

func Update(ctx context.Context, r Driver) error

Update execute the resource Update function, if implemented by the driver.

Types

type Aborter

type Aborter interface {
	Abort(ctx context.Context) bool
}

Aborter implements the Abort func, which can return true to block a start action before any resource has entered Start().

type ActionResourceDepser

type ActionResourceDepser interface {
	ActionResourceDeps() []actionresdeps.Dep
}

ActionResourceDepser implements the ActionResourceDeps func, which return a list of {action, rid depending on, rid depended on} tuples.

type Configurer

type Configurer interface {
	Configure() error
}

Configurer is an optional interface resource drivers can implement if they want to configure the resource after the manifest data has been loaded. For example, tuning the logger.

type DisableFlag

type DisableFlag bool

DisableFlag hints the resource ignores all state transition actions

func (DisableFlag) FlagString

func (t DisableFlag) FlagString() string

FlagString returns a one character representation of the type instance.

type Driver

type Driver interface {
	Provisioned() (provisioned.T, error)
	Provision(context.Context) error
	Unprovision(context.Context) error

	// common
	ApplyPGChain(context.Context) error
	GetObject() any
	GetPG() *pg.Config
	GetPGID() string
	GetRestartDelay() time.Duration
	ID() *resourceid.T
	IsActionDisabled() bool
	IsDisabled() bool
	IsEncap() bool
	IsMonitored() bool
	IsOptional() bool
	IsProvisionDisabled() bool
	IsUnprovisionDisabled() bool
	IsShared() bool
	IsStandby() bool
	IsStatusDisabled() bool
	Label() string
	Log() *plog.Logger
	Manifest() *manifest.T
	MatchRID(string) bool
	MatchSubset(string) bool
	MatchTag(string) bool
	Progress(context.Context, ...any)
	ProgressKey() []string
	Requires(string) *resourcereqs.T
	RestartCount() int
	RID() string
	RSubset() string
	SetObject(any)
	SetPG(*pg.Config)
	SetRID(string) error
	Status(context.Context) status.T
	StatusLog() StatusLogger
	TagSet() TagSet
	Trigger(context.Context, trigger.Blocking, trigger.Hook, trigger.Action) error
	VarDir() string
}

Driver exposes what can be done with a resource

type Drivers

type Drivers []Driver

func (Drivers) Add

func (t Drivers) Add(r Driver) Drivers

func (Drivers) GetRID

func (t Drivers) GetRID(rid string) Driver

func (Drivers) Has

func (t Drivers) Has(d Driver) bool

Has returns true if t has a driver whose RID() is the same as d.

func (Drivers) HasRID

func (t Drivers) HasRID(rid string) bool

HasRID returns true if t has a driver whose RID() is the same as rid.

func (Drivers) Intersection

func (t Drivers) Intersection(other Drivers) Drivers

Intersection returns a list of drivers ordered like t and purged from drivers in other.

func (Drivers) Len

func (t Drivers) Len() int

func (Drivers) Less

func (t Drivers) Less(i, j int) bool

func (Drivers) Linkers

func (t Drivers) Linkers(names []string) Drivers

func (Drivers) LinkersRID

func (t Drivers) LinkersRID(names []string) []string
func (t Drivers) ResolveLink(to string) (Driver, bool)

ResolveLink returns the driver intstance targeted by <to>

func (Drivers) Reverse

func (t Drivers) Reverse()

Reverse reverses the driver list sort.

func (Drivers) Sort

func (t Drivers) Sort()

Sort sorts the driver list.

func (Drivers) Swap

func (t Drivers) Swap(i, j int)

func (Drivers) Truncate

func (t Drivers) Truncate(rid string) (Drivers, bool)

Truncate returns the drivers list from first to the driver with <rid>. If rid is not set, return the whole driver list. The second return value is true if the rid was found, whatever the truncation done.

func (Drivers) Union

func (t Drivers) Union(other Drivers) Drivers

Union return a deduplicated list containing all drivers from t and other.

type EncapFlag

type EncapFlag bool

EncapFlag indicates that the resource is handled by the encapsulated agents, and ignored at the hypervisor level.

func (EncapFlag) FlagString

func (t EncapFlag) FlagString() string

FlagString returns a one character representation of the type instance.

type Hook

type Hook int
const (
	Pre Hook = iota
	Post
)

type Info

type Info struct {
	RID  string
	Keys InfoKeys
}

func GetInfo

func GetInfo(ctx context.Context, r Driver) (Info, error)

type InfoKey

type InfoKey struct {
	Key   string
	Value string
}

func (InfoKey) String

func (t InfoKey) String() string

type InfoKeys

type InfoKeys []InfoKey

type Infos

type Infos struct {
	ObjectPath naming.Path
	Resources  []Info
}

func NewInfos

func NewInfos(p naming.Path) Infos

func (Infos) String

func (t Infos) String() string

type IsRunninger

type IsRunninger interface {
	IsRunning() bool
}

IsRunninger implements the IsRunning func, which the core calls when evaluating an object instance status to build the "running" rid list.

type Level

type Level string

Level can be "error", "warn", "info"

type LinkNameser

type LinkNameser interface {
	LinkNames() []string
}

type LinkToer

type LinkToer interface {
	LinkTo() string
}

type Loader

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

Loader uses a Reader to load a JSON Resource configuration into the resource struct.

func NewLoader

func NewLoader(r io.Reader) *Loader

NewLoader allocates a new Loader and returns a reference.

func (*Loader) Load

func (l *Loader) Load(v interface{}) error

Load JSON-decodes data from the Reader and load it at a Resource address

type MonitorFlag

type MonitorFlag bool

MonitorFlag tells the daemon if it should trigger a monitor action when the resource is not up.

func (MonitorFlag) FlagString

func (t MonitorFlag) FlagString() string

FlagString returns a one character representation of the type instance.

type NetNSPathCtxer

type NetNSPathCtxer interface {
	NetNSPathCtx(ctx context.Context) (string, error)
}

type NetNSPather

type NetNSPather interface {
	NetNSPath() (string, error)
}

NetNSPather exposes a NetNSPath method a resource can call to get the string identifying the network namespace for libs like netlink. For example, the container.docker driver's NetNSPath() would return the SandboxKey

type ObjectDriver

type ObjectDriver interface {
	Log() *plog.Logger
	VarDir() string
	ResourceByID(string) Driver
	ResourcesByDrivergroups([]driver.Group) Drivers
}

type OptionalFlag

type OptionalFlag bool

OptionalFlag makes this resource status aggregated into Overall instead of Avail instance status. Errors in optional resource don't stop a state transition action.

func (OptionalFlag) FlagString

func (t OptionalFlag) FlagString() string

FlagString returns a one character representation of the type instance.

type PIDer

type PIDer interface {
	PID() int
}

PIDer exposes a PID method a resource can call to get the head pid of the head process started by the resource. Typically a container resource PID() returns the pid of the first process of the container. PID() must return 0 when no process is running.

type ProvisionLeadeder

type ProvisionLeadeder interface {
	ProvisionLeaded(context.Context) error
}

type ProvisionLeaderer

type ProvisionLeaderer interface {
	ProvisionLeader(context.Context) error
}

type ProvisionStarter

type ProvisionStarter interface {
	ProvisionStart(context.Context) error
}

type ProvisionStatus

type ProvisionStatus struct {
	Mtime time.Time     `json:"mtime,omitempty"`
	State provisioned.T `json:"state"`
}

ProvisionStatus define if and when the resource became provisioned.

type RestartFlag

type RestartFlag int

RestartFlag is the number of times the monitor will try restarting a resource gone down in a well-known started instance.

func (RestartFlag) FlagString

func (t RestartFlag) FlagString(retries int) string

FlagString returns a one character representation of the type instance.

type Runner

type Runner interface {
	Run(ctx context.Context) error
}

Runner implements the Run func, which runs a one-shot process Implemented by the resource. The object "run" action causes selected Runners to call Run().

type SCSIPersistentReservation

type SCSIPersistentReservation struct {
	Key            string
	NoPreemptAbort bool
	Enabled        bool
}

func (SCSIPersistentReservation) IsSCSIPersistentReservationEnabled

func (t SCSIPersistentReservation) IsSCSIPersistentReservationEnabled() bool

func (SCSIPersistentReservation) IsSCSIPersistentReservationPreemptAbortDisabled

func (t SCSIPersistentReservation) IsSCSIPersistentReservationPreemptAbortDisabled() bool

func (SCSIPersistentReservation) PersistentReservationKey

func (t SCSIPersistentReservation) PersistentReservationKey() string

type ScheduleOptions

type ScheduleOptions struct {
	Action              string
	Option              string
	Base                string
	RequireCollector    bool
	RequireProvisioned  bool
	RequireConfirmation bool
}

ScheduleOptions contains the information needed by the object to create a schedule.Entry to append to the object's schedule.Table.

type Scheduler

type Scheduler interface {
	Schedules() schedule.Table
}

Scheduler implements the Schedules func, which returns the list of schedulable job definition on behalf of the resource.

type Setenver

type Setenver interface {
	Setenv()
}

type StandbyFlag

type StandbyFlag bool

StandbyFlag tells the daemon this resource should always be up, even after a stop state transition action.

func (StandbyFlag) FlagString

func (t StandbyFlag) FlagString() string

FlagString returns a one character representation of the type instance.

type Status

type Status struct {
	ResourceID  *resourceid.T     `json:"-"`
	Label       string            `json:"label"`
	Log         []*StatusLogEntry `json:"log,omitempty"`
	Status      status.T          `json:"status"`
	Type        string            `json:"type"`
	Provisioned ProvisionStatus   `json:"provisioned,omitempty"`
	Monitor     MonitorFlag       `json:"monitor,omitempty"`
	Disable     DisableFlag       `json:"disable,omitempty"`
	Optional    OptionalFlag      `json:"optional,omitempty"`
	Encap       EncapFlag         `json:"encap,omitempty"`
	Standby     StandbyFlag       `json:"standby,omitempty"`

	// Subset is the name of the subset this resource is assigned to.
	Subset string `json:"subset,omitempty"`

	// Info is a list of key-value pairs providing interesting information to
	// collect site-wide about this resource.
	Info map[string]any `json:"info,omitempty"`

	// Restart is the number of restart to be tried before giving up.
	Restart RestartFlag `json:"restart,omitempty"`

	// Tags is a set of words attached to the resource.
	Tags TagSet `json:"tags,omitempty"`
}

Status is the structure representing the resource status, which is embedded in the instance status.

func GetStatus

func GetStatus(ctx context.Context, r Driver) Status

GetStatus returns the resource Status for embedding into the instance.Status.

func (Status) DeepCopy

func (t Status) DeepCopy() *Status

func (Status) Unstructured

func (t Status) Unstructured() map[string]any

type StatusInfoSchedAction

type StatusInfoSchedAction struct {
	Last time.Time `json:"last"`
}

type StatusInfoer

type StatusInfoer interface {
	StatusInfo() map[string]interface{}
}

StatusInfoer implements the StatusInfo func, which returns a resource specific key-val mapping pushed to the collector on "pushinfo" action.

type StatusLog

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

StatusLog holds the information, warning and alerts of a Resource

func (*StatusLog) Entries

func (l *StatusLog) Entries() []*StatusLogEntry

Entries the log entries

func (*StatusLog) Error

func (l *StatusLog) Error(s string, args ...any)

Error append an error message to the log

func (*StatusLog) Info

func (l *StatusLog) Info(s string, args ...any)

Info append an info message to the log

func (*StatusLog) Reset

func (l *StatusLog) Reset()

func (*StatusLog) Warn

func (l *StatusLog) Warn(s string, args ...any)

Warn append a warning message to the log

type StatusLogEntry

type StatusLogEntry struct {
	Level   Level  `json:"level"`
	Message string `json:"message"`
}

StatusLogEntry is an element of LogType.Log

func (StatusLogEntry) String

func (t StatusLogEntry) String() string

func (*StatusLogEntry) UnmarshalJSON

func (t *StatusLogEntry) UnmarshalJSON(data []byte) error

type StatusLogger

type StatusLogger interface {
	Info(string, ...any)
	Warn(string, ...any)
	Error(string, ...any)
	Reset()
	Entries() []*StatusLogEntry
}

type SubDeviceser

type SubDeviceser interface {
	SubDevices() device.L
}

type T

type T struct {
	Driver
	ResourceID              *resourceid.T
	Subset                  string
	Disable                 bool
	Monitor                 bool
	Optional                bool
	Standby                 bool
	Shared                  bool
	Encap                   bool
	Restart                 int
	RestartDelay            *time.Duration
	Tags                    *set.Set
	BlockingPreStart        string
	BlockingPreStop         string
	BlockingPreRun          string
	BlockingPreProvision    string
	BlockingPreUnprovision  string
	PreStart                string
	PreStop                 string
	PreRun                  string
	PreProvision            string
	PreUnprovision          string
	BlockingPostStart       string
	BlockingPostStop        string
	BlockingPostRun         string
	BlockingPostProvision   string
	BlockingPostUnprovision string
	PostStart               string
	PostStop                string
	PostRun                 string
	PostProvision           string
	PostUnprovision         string
	StartRequires           string
	StopRequires            string
	ProvisionRequires       string
	UnprovisionRequires     string
	SyncRequires            string
	RunRequires             string
	EnableProvision         bool
	EnableUnprovision       bool
	// contains filtered or unexported fields
}

T is the resource type, embedded in each drivers type

func (*T) ApplyPGChain

func (t *T) ApplyPGChain(ctx context.Context) error

ApplyPGChain fetches the pg manager from the action context and apply the pg configuration to all unconfigured pg on the pg id hierarchy (resource=>subset=>object).

The pg manager remembers which pg have been configured to avoid doing the config twice.

func (T) GetObject

func (t T) GetObject() any

GetObject returns the object interface set by SetObjectriver upon configure.

func (*T) GetObjectDriver

func (t *T) GetObjectDriver() ObjectDriver

GetObjectDriver returns the object driver interface of the object set by SetObject upon configure.

func (*T) GetPG

func (t *T) GetPG() *pg.Config

GetPG returns the private pg resource field

func (*T) GetPGID

func (t *T) GetPGID() string

GetPGID returns the pg id configured via SetPG, or "" if unset

func (T) GetRestartDelay

func (t T) GetRestartDelay() time.Duration

GetRestartDelay returns the duration between 2 restarts

func (T) ID

func (t T) ID() *resourceid.T

ID returns the resource id struct

func (T) IsActionDisabled

func (t T) IsActionDisabled() bool

IsActionDisabled returns true if the resource definition contains tag=noaction ... In this case, the resource actions like stop and start are skipped.

func (T) IsDisabled

func (t T) IsDisabled() bool

IsDisabled returns true if the resource definition contains disable=true.

func (T) IsEncap

func (t T) IsEncap() bool

IsEncap returns true if the resource definition contains encap=true.

func (T) IsMonitored

func (t T) IsMonitored() bool

IsMonitored returns true if the resource definition contains monitor=true.

func (T) IsOptional

func (t T) IsOptional() bool

IsOptional returns true if the resource definition contains optional=true. An optional resource does not break an object action on error.

Resource having actions disabled are always considered optional, because there is nothing we can do to change the state, which would cause orchestration loops.

func (T) IsProvisionDisabled

func (t T) IsProvisionDisabled() bool

IsProvisionDisabled returns true if the resource definition contains provision=false.

func (T) IsShared

func (t T) IsShared() bool

IsShared returns true if the resource definition contains shared=true.

func (T) IsStandby

func (t T) IsStandby() bool

IsStandby returns true if the resource definition contains standby=true.

func (T) IsStatusDisabled

func (t T) IsStatusDisabled() bool

IsStatusDisabled returns true if the resource definition contains tag=nostatus ... In this case, the resource status is always n/a

func (T) IsUnprovisionDisabled

func (t T) IsUnprovisionDisabled() bool

IsUnprovisionDisabled returns true if the resource definition contains unprovision=false.

func (*T) Lock

func (t *T) Lock(disable bool, timeout time.Duration, intent string) (func(), error)

func (*T) Log

func (t *T) Log() *plog.Logger

Log returns the resource logger

func (T) MatchRID

func (t T) MatchRID(s string) bool

MatchRID returns true if:

  • the pattern is a just a drivergroup name and this name matches this resource's drivergroup ex: fs#1 matches fs
  • the pattern is a fully qualified resourceid, and its string representation equals the pattern. ex: fs#1 matches fs#1

func (T) MatchSubset

func (t T) MatchSubset(s string) bool

MatchSubset returns true if the resource subset equals the pattern.

func (T) MatchTag

func (t T) MatchTag(s string) bool

MatchTag returns true if one of the resource tags equals the pattern.

func (*T) Progress

func (t *T) Progress(ctx context.Context, cols ...any)

func (*T) ProgressKey

func (t *T) ProgressKey() []string

func (T) RID

func (t T) RID() string

RID returns the string representation of the resource id

func (T) RSubset

func (t T) RSubset() string

RSubset returns the resource subset name

func (T) Requires

func (t T) Requires(action string) *resourcereqs.T

func (T) RestartCount

func (t T) RestartCount() int

RestartCount returns the value of the Restart field

func (*T) SetLoggerForTest

func (t *T) SetLoggerForTest(l *plog.Logger)

SetLoggerForTest can be used to set resource log for testing purpose

func (*T) SetObject

func (t *T) SetObject(o any)

SetObject holds the useful interface of the parent object of the resource.

func (*T) SetPG

func (t *T) SetPG(v *pg.Config)

SetPG sets the process group config parsed from the config

func (*T) SetRID

func (t *T) SetRID(v string) error

SetRID sets the resource identifier

func (*T) StatusLog

func (t *T) StatusLog() StatusLogger

StatusLog returns a reference to the resource log

func (T) TagSet

func (t T) TagSet() TagSet

func (T) Trigger

func (t T) Trigger(ctx context.Context, blocking trigger.Blocking, hook trigger.Hook, action trigger.Action) error

func (T) VarDir

func (t T) VarDir() string

VarDir is the full path of the directory where the resource can write its private variable data.

type TagSet

type TagSet []string

TagSet is the list of unique tag names found in the resource definition.

type UnprovisionLeadeder

type UnprovisionLeadeder interface {
	UnprovisionLeaded(context.Context) error
}

type UnprovisionLeaderer

type UnprovisionLeaderer interface {
	UnprovisionLeader(context.Context) error
}

type UnprovisionStoper

type UnprovisionStoper interface {
	UnprovisionStop(context.Context) error
}

Jump to

Keyboard shortcuts

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