Documentation
¶
Overview ¶
Package context contains the ContextFactory and Context definitions. Context implements runner.Context and is used together with uniter.Runner to run hooks, commands and actions.
Index ¶
- Variables
- func ContextDependentEnvVars(env Environmenter) []string
- func UbuntuEnvVars(paths Paths, envVars Environmenter) []string
- type ActionData
- type Clock
- type CommandInfo
- type Context
- type ContextFactory
- type ContextRelation
- func (c *ContextRelation) ApplicationSettings(ctx context.Context) (jujuc.Settings, error)
- func (c *ContextRelation) FakeId() string
- func (c *ContextRelation) FinalSettings() (unitSettings, appSettings params.Settings)
- func (c *ContextRelation) Id() int
- func (c *ContextRelation) Life() life.Value
- func (c *ContextRelation) Name() string
- func (c *ContextRelation) ReadApplicationSettings(ctx context.Context, app string) (settings params.Settings, err error)
- func (c *ContextRelation) ReadSettings(ctx context.Context, unit string) (settings params.Settings, err error)
- func (c *ContextRelation) RelationTag() names.RelationTag
- func (c *ContextRelation) RemoteApplicationName() string
- func (ctx *ContextRelation) RemoteModelUUID() string
- func (c *ContextRelation) SetStatus(ctx context.Context, status relation.Status) error
- func (c *ContextRelation) Settings(ctx context.Context) (jujuc.Settings, error)
- func (c *ContextRelation) Suspended() bool
- func (c *ContextRelation) UnitNames() []string
- type EnvironmentWrapper
- type Environmenter
- type FactoryConfig
- type HookContext
- func (c *HookContext) ActionData() (*ActionData, error)
- func (c *HookContext) ActionParams() (map[string]interface{}, error)
- func (c *HookContext) AddMetric(key, value string, created time.Time) error
- func (c *HookContext) AddMetricLabels(key, value string, created time.Time, labels map[string]string) error
- func (c *HookContext) AddUnitStorage(cons map[string]params.StorageDirectives) error
- func (c *HookContext) ApplicationStatus(ctx context.Context) (jujuc.ApplicationStatusInfo, error)
- func (c *HookContext) AvailabilityZone() (string, error)
- func (c *HookContext) ClosePortRange(endpointName string, portRange network.PortRange) error
- func (c *HookContext) CloudSpec(ctx context.Context) (*params.CloudSpec, error)
- func (c *HookContext) ConfigSettings(ctx context.Context) (charm.Settings, error)
- func (c *HookContext) CreateSecret(ctx context.Context, args *jujuc.SecretCreateArgs) (*coresecrets.URI, error)
- func (c *HookContext) DeleteCharmStateValue(ctx context.Context, key string) error
- func (c *HookContext) Flush(ctx context.Context, process string, ctxErr error) error
- func (c *HookContext) GetCharmState(ctx context.Context) (map[string]string, error)
- func (c *HookContext) GetCharmStateValue(ctx context.Context, key string) (string, error)
- func (c *HookContext) GetLoggerByName(module string) logger.Logger
- func (c *HookContext) GetProcess() HookProcess
- func (c *HookContext) GetRebootPriority() jujuc.RebootPriority
- func (c *HookContext) GetSecret(ctx context.Context, uri *coresecrets.URI, label string, refresh, peek bool) (coresecrets.SecretValue, error)
- func (c *HookContext) GoalState(ctx context.Context) (*application.GoalState, error)
- func (c *HookContext) GrantSecret(uri *coresecrets.URI, arg *jujuc.SecretGrantRevokeArgs) error
- func (c *HookContext) HasExecutionSetUnitStatus() bool
- func (c *HookContext) HookRelation() (jujuc.ContextRelation, error)
- func (c *HookContext) HookStorage(ctx context.Context) (jujuc.ContextStorageAttachment, error)
- func (c *HookContext) HookVars(ctx context.Context, paths Paths, env Environmenter) ([]string, error)
- func (c *HookContext) Id() string
- func (c *HookContext) LogActionMessage(ctx context.Context, message string) error
- func (c *HookContext) ModelType() model.ModelType
- func (c *HookContext) NetworkInfo(ctx context.Context, bindingNames []string, relationId int) (map[string]params.NetworkInfoResult, error)
- func (c *HookContext) OpenPortRange(endpointName string, portRange network.PortRange) error
- func (c *HookContext) OpenedPortRanges() network.GroupedPortRanges
- func (c *HookContext) Prepare(ctx context.Context) error
- func (c *HookContext) PrivateAddress() (string, error)
- func (c *HookContext) PublicAddress(ctx context.Context) (string, error)
- func (c *HookContext) Relation(id int) (jujuc.ContextRelation, error)
- func (c *HookContext) RelationIds() ([]int, error)
- func (c *HookContext) RemoteApplicationName() (string, error)
- func (c *HookContext) RemoteUnitName() (string, error)
- func (c *HookContext) RemoveSecret(uri *coresecrets.URI, revision *int) error
- func (c *HookContext) RequestReboot(priority jujuc.RebootPriority) error
- func (c *HookContext) ResetExecutionSetUnitStatus()
- func (c *HookContext) RevokeSecret(uri *coresecrets.URI, args *jujuc.SecretGrantRevokeArgs) error
- func (c *HookContext) SecretLabel() string
- func (c *HookContext) SecretMetadata() (map[string]jujuc.SecretMetadata, error)
- func (c *HookContext) SecretRevision() int
- func (c *HookContext) SecretURI() (string, error)
- func (c *HookContext) SetActionFailed() error
- func (c *HookContext) SetActionMessage(message string) error
- func (c *HookContext) SetAgentStatus(ctx context.Context, agentStatus jujuc.StatusInfo) error
- func (c *HookContext) SetApplicationStatus(ctx context.Context, applicationStatus jujuc.StatusInfo) error
- func (c *HookContext) SetCharmStateValue(ctx context.Context, key, value string) error
- func (c *HookContext) SetProcess(process HookProcess)
- func (c *HookContext) SetUnitStatus(ctx context.Context, unitStatus jujuc.StatusInfo) error
- func (c *HookContext) SetUnitWorkloadVersion(ctx context.Context, version string) error
- func (c *HookContext) Storage(ctx context.Context, tag names.StorageTag) (jujuc.ContextStorageAttachment, error)
- func (c *HookContext) StorageTags(ctx context.Context) ([]names.StorageTag, error)
- func (c *HookContext) UnitName() string
- func (c *HookContext) UnitStatus(ctx context.Context) (*jujuc.StatusInfo, error)
- func (c *HookContext) UnitWorkloadVersion(ctx context.Context) (string, error)
- func (c *HookContext) UpdateActionResults(keys []string, value interface{}) error
- func (c *HookContext) UpdateSecret(uri *coresecrets.URI, args *jujuc.SecretUpdateArgs) error
- func (ctx *HookContext) WorkloadCheckName() (string, error)
- func (c *HookContext) WorkloadName() (string, error)
- func (ctx *HookContext) WorkloadNoticeKey() (string, error)
- func (ctx *HookContext) WorkloadNoticeType() (string, error)
- type HookProcess
- type HookUnit
- type LeadershipContext
- type Paths
- type RelationCache
- func (cache *RelationCache) ApplicationSettings(ctx context.Context, appName string) (params.Settings, error)
- func (cache *RelationCache) InvalidateApplication(appName string)
- func (cache *RelationCache) InvalidateMember(memberName string)
- func (cache *RelationCache) MemberNames() (memberNames []string)
- func (cache *RelationCache) Prune(memberNames []string)
- func (cache *RelationCache) RemoveMember(memberName string)
- func (cache *RelationCache) Settings(ctx context.Context, unitName string) (params.Settings, error)
- type RelationInfo
- type RelationUnit
- type RelationsFunc
- type SecretsBackendGetter
- type SettingsFunc
- type SettingsMap
- type StorageContextAccessor
Constants ¶
This section is empty.
Variables ¶
var ContextAllowedEnvVars = []string{
"KUBERNETES_PORT",
"KUBERNETES_PORT_443_TCP",
"KUBERNETES_PORT_443_TCP_ADDR",
"KUBERNETES_PORT_443_TCP_PORT",
"KUBERNETES_PORT_443_TCP_PROTO",
"KUBERNETES_SERVICE",
"KUBERNETES_SERVICE_HOST",
"KUBERNETES_SERVICE_PORT",
"KUBERNETES_SERVICE_PORT_HTTPS",
}
ContextAllowedEnvVars defines a list of allowed env vars to include from the given context
var ErrIsNotLeader = errors.Errorf("this unit is not the leader")
var ErrReboot = errors.New("reboot after hook")
var ErrRequeueAndReboot = errors.New("reboot now")
Functions ¶
func ContextDependentEnvVars ¶
func ContextDependentEnvVars(env Environmenter) []string
ContextDependentEnvVars returns the context aware enviormnent variables needed for charms depending on contexts they may be operating in. For example returning defined Kubernetes env variables when they're defined.
func UbuntuEnvVars ¶
func UbuntuEnvVars(paths Paths, envVars Environmenter) []string
UbuntuEnvVars returns the OS-dependent environment variables that should be set for a hook context.
Types ¶
type ActionData ¶
type ActionData struct { Name string Tag names.ActionTag Params map[string]interface{} Failed bool ResultsMessage string ResultsMap map[string]interface{} Cancel <-chan struct{} }
ActionData contains the tag, parameters, and results of an Action.
func NewActionData ¶
func NewActionData(name string, tag *names.ActionTag, params map[string]interface{}, cancel <-chan struct{}) *ActionData
NewActionData builds a suitable ActionData struct with no nil members. this should only be called in the event that an Action hook is being requested.
type Clock ¶
type Clock interface { // After waits for the duration to elapse and then sends the // current time on the returned channel. After(time.Duration) <-chan time.Time }
Clock defines the methods of the full clock.Clock that are needed here.
type CommandInfo ¶
type CommandInfo struct { // RelationId is the relation context to execute the commands in. RelationId int // RemoteUnitName is the remote unit for the relation context. RemoteUnitName string // TODO(jam): 2019-10-23 Add RemoteApplicationName // ForceRemoteUnit skips unit inference and existence validation. ForceRemoteUnit bool }
CommandInfo specifies the information necessary to run a command.
type Context ¶
type Context interface { jujuc.Context Id() string HookVars( ctx context.Context, paths Paths, env Environmenter) ([]string, error) ActionData() (*ActionData, error) SetProcess(process HookProcess) HasExecutionSetUnitStatus() bool ResetExecutionSetUnitStatus() ModelType() model.ModelType Prepare(ctx context.Context) error Flush(ctx context.Context, badge string, failure error) error GetLoggerByName(module string) logger.Logger }
Context exposes hooks.Context, and additional methods needed by Runner.
type ContextFactory ¶
type ContextFactory interface { // CommandContext creates a new context for running a juju command. CommandContext(ctx context.Context, commandInfo CommandInfo) (*HookContext, error) // HookContext creates a new context for running a juju hook. HookContext(ctx context.Context, hookInfo hook.Info) (*HookContext, error) // ActionContext creates a new context for running a juju action. ActionContext(ctx context.Context, actionData *ActionData) (*HookContext, error) }
ContextFactory represents a long-lived object that can create execution contexts relevant to a specific unit.
func NewContextFactory ¶
func NewContextFactory(ctx context.Context, config FactoryConfig) (ContextFactory, error)
NewContextFactory returns a ContextFactory capable of creating execution contexts backed by the supplied unit's supplied API connection.
type ContextRelation ¶
type ContextRelation struct {
// contains filtered or unexported fields
}
ContextRelation is the implementation of hooks.ContextRelation.
func NewContextRelation ¶
func NewContextRelation(ru RelationUnit, cache *RelationCache, broken bool) *ContextRelation
NewContextRelation creates a new context for the given relation unit. The unit-name keys of members supplies the initial membership.
func (*ContextRelation) ApplicationSettings ¶
func (*ContextRelation) FakeId ¶
func (c *ContextRelation) FakeId() string
func (*ContextRelation) FinalSettings ¶
func (c *ContextRelation) FinalSettings() (unitSettings, appSettings params.Settings)
FinalSettings returns the changes made to the relation settings (unit and application)
func (*ContextRelation) Id ¶
func (c *ContextRelation) Id() int
func (*ContextRelation) Life ¶
func (c *ContextRelation) Life() life.Value
Life returns the relation's current life state.
func (*ContextRelation) Name ¶
func (c *ContextRelation) Name() string
func (*ContextRelation) ReadApplicationSettings ¶
func (*ContextRelation) ReadSettings ¶
func (*ContextRelation) RelationTag ¶
func (c *ContextRelation) RelationTag() names.RelationTag
func (*ContextRelation) RemoteApplicationName ¶
func (c *ContextRelation) RemoteApplicationName() string
RemoteApplicationName returns the application on the other end of this relation from the perspective of this unit.
func (*ContextRelation) RemoteModelUUID ¶
func (ctx *ContextRelation) RemoteModelUUID() string
RemoteModelUUID returns the UUID of the model hosting the application on the other end of the relation.
func (*ContextRelation) Suspended ¶
func (c *ContextRelation) Suspended() bool
Suspended returns true if the relation is suspended.
func (*ContextRelation) UnitNames ¶
func (c *ContextRelation) UnitNames() []string
type EnvironmentWrapper ¶
type EnvironmentWrapper struct {
// contains filtered or unexported fields
}
func NewHostEnvironmenter ¶
func NewHostEnvironmenter() *EnvironmentWrapper
NewHostEnvironmenter constructs an EnvironmentWrapper target at the current process host
func NewRemoteEnvironmenter ¶
func NewRemoteEnvironmenter( environFn func() []string, getenvFn func(string) string, lookupEnvFn func(string) (string, bool), ) *EnvironmentWrapper
NewRemoveEnvironmenter constructs an EnviornmentWrapper with targets set to that of the functions provided.
func (*EnvironmentWrapper) Environ ¶
func (e *EnvironmentWrapper) Environ() []string
Environ implements Environmenter Environ
func (*EnvironmentWrapper) Getenv ¶
func (e *EnvironmentWrapper) Getenv(key string) string
Getenv implements Environmenter Getenv
type Environmenter ¶
type Environmenter interface { // Environ returns a copy of strings representing the environment, in the // form "key=value" Environ() []string // Getenv retrieves the value of the environment variable named by the key. // It returns the value, which will be empty if the variable is not present. Getenv(string) string // LookupEnv retrieves the value of the environment variable named by the // key. If the variable is present in the environment the value (which may // be empty) is returned and the boolean is true. Otherwise the returned // value will be empty and the boolean will be false. LookupEnv(string) (string, bool) }
Environmenter represent the os environ interface for fetching host level environment variables.
type FactoryConfig ¶
type FactoryConfig struct { Uniter api.UniterClient SecretsClient api.SecretsAccessor SecretsBackendGetter SecretsBackendGetter Unit api.Unit Resources resources.OpenedResourceClient Tracker leadership.Tracker GetRelationInfos RelationsFunc Paths Paths Clock Clock Logger logger.Logger }
FactoryConfig contains configuration values for the context factory.
type HookContext ¶
type HookContext struct { *resources.ResourcesHookContext // LeadershipContext supplies several hooks.Context methods. LeadershipContext // contains filtered or unexported fields }
HookContext is the implementation of runner.Context.
func (*HookContext) ActionData ¶
func (c *HookContext) ActionData() (*ActionData, error)
ActionData returns the context's internal action data. It's meant to be transitory; it exists to allow uniter and runner code to keep working as it did; it should be considered deprecated, and not used by new clients. Implements runner.Context.
func (*HookContext) ActionParams ¶
func (c *HookContext) ActionParams() (map[string]interface{}, error)
ActionParams simply returns the arguments to the Action. Implements jujuc.ActionHookContext.actionHookContext, part of runner.Context.
func (*HookContext) AddMetric ¶
func (c *HookContext) AddMetric(key, value string, created time.Time) error
AddMetric adds metrics to the hook context. Implements jujuc.HookContext.ContextMetrics, part of runner.Context.
func (*HookContext) AddMetricLabels ¶
func (c *HookContext) AddMetricLabels(key, value string, created time.Time, labels map[string]string) error
AddMetricLabels adds metrics with labels to the hook context. Implements jujuc.HookContext.ContextMetrics, part of runner.Context.
func (*HookContext) AddUnitStorage ¶
func (c *HookContext) AddUnitStorage(cons map[string]params.StorageDirectives) error
AddUnitStorage saves storage directives in the context. Implements jujuc.HookContext.ContextStorage, part of runner.Context.
func (*HookContext) ApplicationStatus ¶
func (c *HookContext) ApplicationStatus(ctx context.Context) (jujuc.ApplicationStatusInfo, error)
ApplicationStatus returns the status for the application and all the units on the application to which this context unit belongs, only if this unit is the leader. Implements jujuc.HookContext.ContextStatus, part of runner.Context.
func (*HookContext) AvailabilityZone ¶
func (c *HookContext) AvailabilityZone() (string, error)
AvailabilityZone returns the executing unit's availability zone or an error if it was not found (or is not available). Implements jujuc.HookContext.ContextInstance, part of runner.Context.
func (*HookContext) ClosePortRange ¶
func (c *HookContext) ClosePortRange(endpointName string, portRange network.PortRange) error
ClosePortRange ensures the supplied port range is closed even when the executing unit's application is exposed (unless it is opened separately by a co- located unit). Implements jujuc.HookContext.ContextNetworking, part of runner.Context.
func (*HookContext) CloudSpec ¶
CloudSpec return the cloud specification for the running unit's model. Implements jujuc.HookContext.ContextUnit, part of runner.Context.
func (*HookContext) ConfigSettings ¶
ConfigSettings returns the current application configuration of the executing unit. Implements jujuc.HookContext.ContextUnit, part of runner.Context.
func (*HookContext) CreateSecret ¶
func (c *HookContext) CreateSecret(ctx context.Context, args *jujuc.SecretCreateArgs) (*coresecrets.URI, error)
CreateSecret creates a secret with the specified data.
func (*HookContext) DeleteCharmStateValue ¶
func (c *HookContext) DeleteCharmStateValue(ctx context.Context, key string) error
DeleteCharmStateValue deletes the key/value pair for the given key from the cache. Implements jujuc.HookContext.unitCharmStateContext, part of runner.Context.
func (*HookContext) GetCharmState ¶
GetCharmState returns a copy of the cached charm state. Implements jujuc.HookContext.unitCharmStateContext, part of runner.Context.
func (*HookContext) GetCharmStateValue ¶
GetCharmStateValue returns the value of the given key. Implements jujuc.HookContext.unitCharmStateContext, part of runner.Context.
func (*HookContext) GetLoggerByName ¶
func (c *HookContext) GetLoggerByName(module string) logger.Logger
GetLoggerByName returns a Logger for the specified module name.
func (*HookContext) GetProcess ¶
func (c *HookContext) GetProcess() HookProcess
func (*HookContext) GetRebootPriority ¶
func (c *HookContext) GetRebootPriority() jujuc.RebootPriority
func (*HookContext) GetSecret ¶
func (c *HookContext) GetSecret(ctx context.Context, uri *coresecrets.URI, label string, refresh, peek bool) (coresecrets.SecretValue, error)
GetSecret returns the value of the specified secret.
func (*HookContext) GoalState ¶
func (c *HookContext) GoalState(ctx context.Context) (*application.GoalState, error)
GoalState returns the goal state for the current unit. Implements jujuc.HookContext.ContextUnit, part of runner.Context.
func (*HookContext) GrantSecret ¶
func (c *HookContext) GrantSecret(uri *coresecrets.URI, arg *jujuc.SecretGrantRevokeArgs) error
GrantSecret grants access to a specified secret.
func (*HookContext) HasExecutionSetUnitStatus ¶
func (c *HookContext) HasExecutionSetUnitStatus() bool
HasExecutionSetUnitStatus implements runner.Context.
func (*HookContext) HookRelation ¶
func (c *HookContext) HookRelation() (jujuc.ContextRelation, error)
HookRelation returns the ContextRelation associated with the executing hook if it was found, or an error if it was not found (or is not available). Implements jujuc.RelationHookContext.relationHookContext, part of runner.Context.
func (*HookContext) HookStorage ¶
func (c *HookContext) HookStorage(ctx context.Context) (jujuc.ContextStorageAttachment, error)
HookStorage returns the storage attachment associated the executing hook if it was found, and an error if it was not found or is not available. Implements jujuc.HookContext.ContextStorage, part of runner.Context.
func (*HookContext) HookVars ¶
func (c *HookContext) HookVars( ctx context.Context, paths Paths, env Environmenter, ) ([]string, error)
HookVars returns an os.Environ-style list of strings necessary to run a hook such that it can know what environment it's operating in, and can call back into context. Implements runner.Context.
func (*HookContext) Id ¶
func (c *HookContext) Id() string
Id returns an integer which uniquely identifies the relation. Implements jujuc.HookContext.ContextRelation, part of runner.Context.
func (*HookContext) LogActionMessage ¶
func (c *HookContext) LogActionMessage(ctx context.Context, message string) error
LogActionMessage logs a progress message for the Action. Implements jujuc.ActionHookContext.actionHookContext, part of runner.Context.
func (*HookContext) ModelType ¶
func (c *HookContext) ModelType() model.ModelType
ModelType of the context we are running in. SetProcess implements runner.Context.
func (*HookContext) NetworkInfo ¶
func (c *HookContext) NetworkInfo(ctx context.Context, bindingNames []string, relationId int) (map[string]params.NetworkInfoResult, error)
NetworkInfo returns the network info for the given bindings on the given relation. Implements jujuc.HookContext.ContextNetworking, part of runner.Context.
func (*HookContext) OpenPortRange ¶
func (c *HookContext) OpenPortRange(endpointName string, portRange network.PortRange) error
OpenPortRange marks the supplied port range for opening. Implements jujuc.HookContext.ContextNetworking, part of runner.Context.
func (*HookContext) OpenedPortRanges ¶
func (c *HookContext) OpenedPortRanges() network.GroupedPortRanges
OpenedPortRanges returns all port ranges currently opened by this unit on its assigned machine grouped by endpoint. Implements jujuc.HookContext.ContextNetworking, part of runner.Context.
func (*HookContext) Prepare ¶
func (c *HookContext) Prepare(ctx context.Context) error
Prepare implements the runner.Context interface.
func (*HookContext) PrivateAddress ¶
func (c *HookContext) PrivateAddress() (string, error)
PrivateAddress returns the executing unit's private address or an error if it is not available. Implements jujuc.HookContext.ContextNetworking, part of runner.Context.
func (*HookContext) PublicAddress ¶
func (c *HookContext) PublicAddress(ctx context.Context) (string, error)
PublicAddress fetches the executing unit's public address if it has not yet been retrieved. The cached value is returned, or an error if it is not available.
func (*HookContext) Relation ¶
func (c *HookContext) Relation(id int) (jujuc.ContextRelation, error)
Relation returns the relation with the supplied id if it was found, and an error if it was not found or is not available. Implements jujuc.HookContext.ContextRelations, part of runner.Context.
func (*HookContext) RelationIds ¶
func (c *HookContext) RelationIds() ([]int, error)
RelationIds returns the ids of all relations the executing unit is currently participating in or an error if they are not available. Implements jujuc.HookContext.ContextRelations, part of runner.Context.
func (*HookContext) RemoteApplicationName ¶
func (c *HookContext) RemoteApplicationName() (string, error)
RemoteApplicationName returns the name of the remote application the hook execution is associated with if it was found, and an error if it was not found or is not available. Implements jujuc.RelationHookContext.relationHookContext, part of runner.Context.
func (*HookContext) RemoteUnitName ¶
func (c *HookContext) RemoteUnitName() (string, error)
RemoteUnitName returns the name of the remote unit the hook execution is associated with if it was found, and an error if it was not found or is not available. Implements jujuc.RelationHookContext.relationHookContext, part of runner.Context.
func (*HookContext) RemoveSecret ¶
func (c *HookContext) RemoveSecret(uri *coresecrets.URI, revision *int) error
RemoveSecret removes a secret with the specified uri.
func (*HookContext) RequestReboot ¶
func (c *HookContext) RequestReboot(priority jujuc.RebootPriority) error
RequestReboot will set the reboot flag to true on the machine agent Implements jujuc.HookContext.ContextInstance, part of runner.Context.
func (*HookContext) ResetExecutionSetUnitStatus ¶
func (c *HookContext) ResetExecutionSetUnitStatus()
ResetExecutionSetUnitStatus implements runner.Context.
func (*HookContext) RevokeSecret ¶
func (c *HookContext) RevokeSecret(uri *coresecrets.URI, args *jujuc.SecretGrantRevokeArgs) error
RevokeSecret revokes access to a specified secret.
func (*HookContext) SecretLabel ¶
func (c *HookContext) SecretLabel() string
SecretLabel returns the secret label for secret hooks. This is not yet used by any hook commands - it is exported for tests to use.
func (*HookContext) SecretMetadata ¶
func (c *HookContext) SecretMetadata() (map[string]jujuc.SecretMetadata, error)
SecretMetadata gets the secret ids and their labels and latest revisions created by the charm. The result includes any pending updates.
func (*HookContext) SecretRevision ¶
func (c *HookContext) SecretRevision() int
SecretRevision returns the secret revision for secret hooks. This is not yet used by any hook commands - it is exported for tests to use.
func (*HookContext) SecretURI ¶
func (c *HookContext) SecretURI() (string, error)
SecretURI returns the secret URI for secret hooks. This is not yet used by any hook commands - it is exported for tests to use.
func (*HookContext) SetActionFailed ¶
func (c *HookContext) SetActionFailed() error
SetActionFailed sets the fail state of the action. Implements jujuc.ActionHookContext.actionHookContext, part of runner.Context.
func (*HookContext) SetActionMessage ¶
func (c *HookContext) SetActionMessage(message string) error
SetActionMessage sets a message for the Action, usually an error message. Implements jujuc.ActionHookContext.actionHookContext, part of runner.Context.
func (*HookContext) SetAgentStatus ¶
func (c *HookContext) SetAgentStatus(ctx context.Context, agentStatus jujuc.StatusInfo) error
SetAgentStatus will set the given status for this unit's agent. Implements jujuc.HookContext.ContextStatus, part of runner.Context.
func (*HookContext) SetApplicationStatus ¶
func (c *HookContext) SetApplicationStatus(ctx context.Context, applicationStatus jujuc.StatusInfo) error
SetApplicationStatus will set the given status to the application to which this unit's belong, only if this unit is the leader. Implements jujuc.HookContext.ContextStatus, part of runner.Context.
func (*HookContext) SetCharmStateValue ¶
func (c *HookContext) SetCharmStateValue(ctx context.Context, key, value string) error
SetCharmStateValue sets the key/value pair provided in the cache. Implements jujuc.HookContext.unitCharmStateContext, part of runner.Context.
func (*HookContext) SetProcess ¶
func (c *HookContext) SetProcess(process HookProcess)
SetProcess implements runner.Context.
func (*HookContext) SetUnitStatus ¶
func (c *HookContext) SetUnitStatus(ctx context.Context, unitStatus jujuc.StatusInfo) error
SetUnitStatus will set the given status for this unit. Implements jujuc.HookContext.ContextStatus, part of runner.Context.
func (*HookContext) SetUnitWorkloadVersion ¶
func (c *HookContext) SetUnitWorkloadVersion(ctx context.Context, version string) error
SetUnitWorkloadVersion sets the current unit's workload version to the specified value. Implements jujuc.HookContext.ContextVersion, part of runner.Context.
func (*HookContext) Storage ¶
func (c *HookContext) Storage(ctx context.Context, tag names.StorageTag) (jujuc.ContextStorageAttachment, error)
Storage returns the ContextStorageAttachment with the supplied tag if it was found, and an error if it was not found or is not available to the context. Implements jujuc.HookContext.ContextStorage, part of runner.Context.
func (*HookContext) StorageTags ¶
func (c *HookContext) StorageTags(ctx context.Context) ([]names.StorageTag, error)
StorageTags returns a list of tags for storage instances attached to the unit or an error if they are not available. Implements jujuc.HookContext.ContextStorage, part of runner.Context.
func (*HookContext) UnitName ¶
func (c *HookContext) UnitName() string
UnitName returns the executing unit's name. UnitName implements jujuc.HookContext.ContextUnit, part of runner.Context.
func (*HookContext) UnitStatus ¶
func (c *HookContext) UnitStatus(ctx context.Context) (*jujuc.StatusInfo, error)
UnitStatus will return the status for the current Unit. Implements jujuc.HookContext.ContextStatus, part of runner.Context.
func (*HookContext) UnitWorkloadVersion ¶
func (c *HookContext) UnitWorkloadVersion(ctx context.Context) (string, error)
UnitWorkloadVersion returns the version of the workload reported by the current unit. Implements jujuc.HookContext.ContextVersion, part of runner.Context.
func (*HookContext) UpdateActionResults ¶
func (c *HookContext) UpdateActionResults(keys []string, value interface{}) error
UpdateActionResults inserts new values for use with action-set and action-fail. The results struct will be delivered to the controller upon completion of the Action. It returns an error if not called on an Action-containing HookContext. Implements jujuc.ActionHookContext.actionHookContext, part of runner.Context.
func (*HookContext) UpdateSecret ¶
func (c *HookContext) UpdateSecret(uri *coresecrets.URI, args *jujuc.SecretUpdateArgs) error
UpdateSecret creates a secret with the specified data.
func (*HookContext) WorkloadCheckName ¶
func (ctx *HookContext) WorkloadCheckName() (string, error)
WorkloadCheckName returns the name of the check for workload check hooks.
func (*HookContext) WorkloadName ¶
func (c *HookContext) WorkloadName() (string, error)
WorkloadName returns the name of the container/workload for workload hooks.
func (*HookContext) WorkloadNoticeKey ¶
func (ctx *HookContext) WorkloadNoticeKey() (string, error)
WorkloadNoticeKey returns the key of the notice for workload notice hooks.
func (*HookContext) WorkloadNoticeType ¶
func (ctx *HookContext) WorkloadNoticeType() (string, error)
WorkloadNoticeType returns the type of the notice for workload notice hooks.
type HookProcess ¶
HookProcess is an interface representing a process running a hook.
type HookUnit ¶
type HookUnit interface { Application(context.Context) (api.Application, error) ApplicationName() string ConfigSettings(context.Context) (charm.Settings, error) LogActionMessage(context.Context, names.ActionTag, string) error Name() string NetworkInfo(ctx context.Context, bindings []string, relationId *int) (map[string]params.NetworkInfoResult, error) RequestReboot(context.Context) error SetUnitStatus(ctx context.Context, unitStatus status.Status, info string, data map[string]interface{}) error SetAgentStatus(ctx context.Context, agentStatus status.Status, info string, data map[string]interface{}) error State(context.Context) (params.UnitStateResult, error) Tag() names.UnitTag UnitStatus(context.Context) (params.StatusResult, error) CommitHookChanges(context.Context, params.CommitHookChangesArgs) error PublicAddress(context.Context) (string, error) }
HookUnit represents the functions needed by a unit in a hook context to call into state.
type LeadershipContext ¶
LeadershipContext provides several hooks.Context methods. It exists separately of HookContext for clarity, and ease of testing.
func NewLeadershipContext ¶
func NewLeadershipContext(tracker leadership.Tracker) LeadershipContext
NewLeadershipContext creates a leadership context for the specified unit.
type Paths ¶
type Paths interface { // GetToolsDir returns the filesystem path to the dirctory containing // the hook tool symlinks. GetToolsDir() string // GetBaseDir returns the filesystem path to the directory in which // the charm is installed. GetBaseDir() string // GetCharmDir returns the filesystem path to the directory in which // the charm is installed. GetCharmDir() string // GetJujucServerSocket returns the path to the socket used by the hook tools // to communicate back to the executing uniter process. It might be a // filesystem path, or it might be abstract. GetJujucServerSocket() sockets.Socket // GetJujucClientSocket returns the path to the socket used by the hook tools // to communicate back to the executing uniter process. It might be a // filesystem path, or it might be abstract. GetJujucClientSocket() sockets.Socket // GetMetricsSpoolDir returns the path to a metrics spool dir, used // to store metrics recorded during a single hook run. GetMetricsSpoolDir() string // GetResourcesDir returns the filesystem path to the directory // containing resource data files. GetResourcesDir() string }
Paths exposes the paths needed by Context.
type RelationCache ¶
type RelationCache struct {
// contains filtered or unexported fields
}
RelationCache stores a relation's remote unit membership and settings. Member settings are stored until invalidated or removed by name; settings of non-member units are stored only until the cache is pruned.
func NewRelationCache ¶
func NewRelationCache(readSettings SettingsFunc, memberNames []string) *RelationCache
NewRelationCache creates a new RelationCache that will use the supplied SettingsFunc to populate itself on demand. Initial membership is determined by memberNames.
func (*RelationCache) ApplicationSettings ¶
func (cache *RelationCache) ApplicationSettings(ctx context.Context, appName string) (params.Settings, error)
ApplicationSettings returns the relation settings of the named application.
func (*RelationCache) InvalidateApplication ¶
func (cache *RelationCache) InvalidateApplication(appName string)
InvalidateApplication ensures that contents cached for remote app will be wiped clean and that the next attempt to read its settings will use fresh data.
func (*RelationCache) InvalidateMember ¶
func (cache *RelationCache) InvalidateMember(memberName string)
InvalidateMember ensures that the named remote unit will be considered a member of the relation, and that the next attempt to read its settings will use fresh data.
func (*RelationCache) MemberNames ¶
func (cache *RelationCache) MemberNames() (memberNames []string)
MemberNames returns the names of the remote units present in the relation.
func (*RelationCache) Prune ¶
func (cache *RelationCache) Prune(memberNames []string)
Prune resets the membership to the supplied list, and discards the settings of all non-member units.
func (*RelationCache) RemoveMember ¶
func (cache *RelationCache) RemoveMember(memberName string)
RemoveMember ensures that the named remote unit will not be considered a member of the relation,
type RelationInfo ¶
type RelationInfo struct { RelationUnit RelationUnit MemberNames []string }
type RelationUnit ¶
type RelationUnit interface { // ApplicationSettings returns a Settings which allows access to this unit's // application settings within the relation. ApplicationSettings(context.Context) (*uniter.Settings, error) // Endpoint returns the relation endpoint that defines the unit's // participation in the relation. Endpoint() uniter.Endpoint // ReadSettings returns a map holding the settings of the unit with the // supplied name within this relation. ReadSettings(ctx context.Context, name string) (params.Settings, error) // Relation returns the relation associated with the unit. Relation() api.Relation // Settings returns a Settings which allows access to the unit's settings // within the relation. Settings(context.Context) (*uniter.Settings, error) }
type RelationsFunc ¶
type RelationsFunc func() map[int]*RelationInfo
RelationsFunc is used to get snapshots of relation membership at context creation time.
type SecretsBackendGetter ¶
type SecretsBackendGetter func() (api.SecretsBackend, error)
SecretsBackendGetter creates a secrets backend client.
type SettingsFunc ¶
SettingsFunc returns the relation settings for a unit.
type SettingsMap ¶
SettingsMap is a map from unit name to relation settings.
type StorageContextAccessor ¶
type StorageContextAccessor interface { // StorageTags returns the tags of storage instances attached to // the unit. StorageTags() ([]names.StorageTag, error) // Storage returns the hooks.ContextStorageAttachment with the // supplied tag if it was found, and whether it was found. Storage(names.StorageTag) (jujuc.ContextStorageAttachment, error) }
StorageContextAccessor is an interface providing access to StorageContexts for a hooks.Context.