Documentation
¶
Index ¶
- Variables
- func AddSnapToQuotaGroup(st *state.State, snapName string, quotaGroup string) (*state.Task, error)
- func AllQuotas(st *state.State) (map[string]*quota.Group, error)
- func CheckQuotaChangeConflictMany(st *state.State, quotaNames []string) error
- func Control(st *state.State, appInfos []*snap.AppInfo, inst *Instruction, flags *Flags, ...) ([]*state.TaskSet, error)
- func CreateQuota(st *state.State, name string, parentName string, snaps []string, ...) (*state.TaskSet, error)
- func EnsureQuotaUsability() (restore func())
- func EnsureSnapAbsentFromQuota(st *state.State, snap string) error
- func GetQuota(st *state.State, name string) (*quota.Group, error)
- func LogReader(appInfos []*snap.AppInfo, n int, follow bool) (io.ReadCloser, error)
- func MockEnsuredSnapServices(mgr *ServiceManager, ensured bool) (restore func())
- func RegisterAffectedQuotasByKind(kind string, f AffectedQuotasFunc)
- func RemoveQuota(st *state.State, name string) (*state.TaskSet, error)
- func SnapServiceOptions(st *state.State, instanceName string, quotaGroups map[string]*quota.Group) (opts *wrappers.SnapServiceOptions, err error)
- func UpdateQuota(st *state.State, name string, updateOpts QuotaGroupUpdate) (*state.TaskSet, error)
- type AffectedQuotasFunc
- type Flags
- type Instruction
- type QuotaChangeConflictError
- type QuotaControlAction
- type QuotaGroupUpdate
- type ServiceAction
- type ServiceActionConflictError
- type ServiceManager
- type StatusDecorator
Constants ¶
This section is empty.
Variables ¶
var ErrQuotaNotFound = errors.New("quota not found")
Functions ¶
func AddSnapToQuotaGroup ¶
AddSnapToQuotaGroup returns a task for adding a snap to a quota group. It wraps the task creation with proper conflict detection for the affected quota-group. Conflict detection for the snap being added must be done by the larger context, as this function is intended to be used in the context of a more complex change.
func AllQuotas ¶
AllQuotas returns all currently tracked quota groups in the state. They are validated for consistency using ResolveCrossReferences before being returned.
func CheckQuotaChangeConflictMany ¶
CheckQuotaChangeConflictMany ensures that for the given quota groups no other changes that alters them (like create, update, remove) are in progress. If a conflict is detected an error is returned.
func Control ¶
func Control(st *state.State, appInfos []*snap.AppInfo, inst *Instruction, flags *Flags, context *hookstate.Context) ([]*state.TaskSet, error)
Control creates a taskset for starting/stopping/restarting services via systemctl. The appInfos and inst define the services and the command to execute. Context is used to determine change conflicts - we will not conflict with tasks from same change as that of context's.
func CreateQuota ¶
func CreateQuota(st *state.State, name string, parentName string, snaps []string, resourceLimits quota.Resources) (*state.TaskSet, error)
CreateQuota attempts to create the specified quota group with the specified snaps in it. TODO: should this use something like QuotaGroupUpdate with fewer fields?
func EnsureQuotaUsability ¶
func EnsureQuotaUsability() (restore func())
EnsureQuotaUsability is exported for unit tests from other packages to re-run the init() time checks for quota usability which set the errors which quotaGroupsAvailable() checks for. It saves the previous state of the usability errors to be restored via the provided restore function.
func EnsureSnapAbsentFromQuota ¶
EnsureSnapAbsentFromQuota ensures that the specified snap is not present in any quota group, usually in preparation for removing that snap from the system to keep the quota group itself consistent. This function is idempotent, since if it was interrupted after unlocking the state inside ensureSnapServicesForGroup it will not re-execute since the specified snap will not be present inside the group reference in the state.
func LogReader ¶
LogReader returns an io.ReadCloser which produce logs for the provided snap AppInfo's. It is a convenience wrapper around the systemd.LogReader implementation.
func MockEnsuredSnapServices ¶
func MockEnsuredSnapServices(mgr *ServiceManager, ensured bool) (restore func())
func RegisterAffectedQuotasByKind ¶
func RegisterAffectedQuotasByKind(kind string, f AffectedQuotasFunc)
RegisterAffectedQuotasByKind registers an AffectedQuotasFunc for returning the affected quotas for tasks of the given kind, to use in conflicts detection.
func RemoveQuota ¶
RemoveQuota deletes the specific quota group. Any snaps currently in the quota will no longer be in any quota group, even if the quota group being removed is a sub-group. TODO: currently this only supports removing leaf sub-group groups, it doesn't support removing parent quotas, but probably it makes sense to allow that too
func SnapServiceOptions ¶
func SnapServiceOptions(st *state.State, instanceName string, quotaGroups map[string]*quota.Group) (opts *wrappers.SnapServiceOptions, err error)
SnapServiceOptions computes the options to configure services for the given snap. This function might not check for the existence of instanceName. It also takes as argument a map of all quota groups as an optimization, the map if non-nil is used in place of checking state for whether or not the specified snap is in a quota group or not. If nil, state is consulted directly instead.
func UpdateQuota ¶
UpdateQuota updates the quota as per the options. TODO: this should support more kinds of updates such as moving groups between parents, removing sub-groups from their parents, and removing snaps from the group.
Types ¶
type AffectedQuotasFunc ¶
An AffectedQuotasFunc returns a list of affected quota group names for the given supported task.
type Flags ¶
type Flags struct { // CreateExecCommandTasks tells Control method to create exec-command tasks // (alongside service-control tasks) for compatibility with old snapd. CreateExecCommandTasks bool }
Flags carries extra flags for Control
type Instruction ¶
type Instruction struct { Action string `json:"action"` Names []string `json:"names"` client.StartOptions client.StopOptions client.RestartOptions }
type QuotaChangeConflictError ¶
type QuotaChangeConflictError struct { Quota string ChangeKind string // a Message is optional, otherwise one is composed from the other information Message string }
QuotaChangeConflictError represents an error because of quota group conflicts between changes.
func (*QuotaChangeConflictError) Error ¶
func (e *QuotaChangeConflictError) Error() string
type QuotaControlAction ¶
type QuotaControlAction struct { // QuotaName is the name of the quota group being controlled. QuotaName string `json:"quota-name,omitempty"` // Action is the action being taken on the quota group. It can be either // "create", "update", or "remove". Action string `json:"action,omitempty"` // AddSnaps is the set of snaps to add to the quota group, valid for either // the "update" or the "create" actions. AddSnaps []string `json:"snaps,omitempty"` // ResourceLimits is the set of resource limits to set on the quota group. // Either the initial limit the group is created with for the "create" // action, or if non-zero for the "update" the memory limit, then the new // value to be set. ResourceLimits quota.Resources `json:"resource-limits,omitempty"` // ParentName is the name of the parent for the quota group if it is being // created. Eventually this could be used with the "update" action to // support moving quota groups from one parent to another, but that is // currently not supported. ParentName string `json:"parent-name,omitempty"` }
QuotaControlAction is the serialized representation of a quota group modification that lives in a task.
type QuotaGroupUpdate ¶
type QuotaGroupUpdate struct { // AddSnaps is the set of snaps to add to the quota group. These are // instance names of snaps, and are appended to the existing snaps in // the quota group AddSnaps []string // NewResourceLimits is the new resource limits to be used for the quota group. A // limit is only changed if the corresponding limit is != nil. NewResourceLimits quota.Resources }
QuotaGroupUpdate reflects all of the modifications that can be performed on a quota group in one operation.
type ServiceAction ¶
type ServiceAction struct { SnapName string `json:"snap-name"` Action string `json:"action"` ActionModifier string `json:"action-modifier,omitempty"` Services []string `json:"services,omitempty"` // ExplicitServices is used when there are explicit services that should be // restarted. This is used for the `snap restart snap-name.svc1` case, // where we create a task with specific services to work on - in this case // ExplicitServices ends up being the list of services that were explicitly // mentioned by the user to be restarted, regardless of their state. This is // needed because in the case that one does `snap restart snap-name`, // Services gets populated with all services in the snap, which we now // interpret to mean that only inactive services of that set are to be // restarted, but there could be additional explicit services that need to // be restarted at the same time in the case that someone does something // like `snap restart snap-name snap-name.svc1`, we will restart all the // inactive and not disabled services in snap-name, and also svc1 regardless // of the state svc1 is in. ExplicitServices []string `json:"explicit-services,omitempty"` }
ServiceAction encapsulates a single service-related action (such as starting, stopping or restarting) run against services of a given snap. The action is run for services listed in services attribute, or for all services of the snap if services list is empty. The names of services and explicit-services are app names (as defined in snap yaml).
type ServiceActionConflictError ¶
type ServiceActionConflictError struct {
// contains filtered or unexported fields
}
type ServiceManager ¶
type ServiceManager struct {
// contains filtered or unexported fields
}
ServiceManager is responsible for starting and stopping snap services.
func Manager ¶
func Manager(st *state.State, runner *state.TaskRunner) *ServiceManager
Manager returns a new service manager.
func (*ServiceManager) Ensure ¶
func (m *ServiceManager) Ensure() error
Ensure implements StateManager.Ensure.
type StatusDecorator ¶
type StatusDecorator struct {
// contains filtered or unexported fields
}
StatusDecorator supports decorating client.AppInfos with service status.
func NewStatusDecorator ¶
func NewStatusDecorator(rep interface { Notify(string) }) *StatusDecorator
NewStatusDecorator returns a new StatusDecorator.
func (*StatusDecorator) DecorateWithStatus ¶
DecorateWithStatus adds service status information to the given client.AppInfo associated with the given snap.AppInfo. If the snap is inactive or the app is not service it does nothing.