Documentation
¶
Overview ¶
Package manager contains the plugin manager engine that handles the workflow.
Index ¶
- Constants
- Variables
- func RegisterCmdHandler(ctx context.Context) error
- type Manifest
- type Metric
- type Plugin
- func (p *Plugin) Apply(ctx context.Context, reqBytes []byte) (*pb.ApplyResponse, *status.Status)
- func (p *Plugin) Connect(ctx context.Context) error
- func (p *Plugin) FullName() string
- func (p *Plugin) GetStatus(ctx context.Context, req string) (*pb.Status, *status.Status)
- func (p *Plugin) IsRunning(ctx context.Context) bool
- func (p *Plugin) PluginService() pb.GuestAgentPluginClient
- func (p *Plugin) Start(ctx context.Context) (*pb.StartResponse, *status.Status)
- func (p *Plugin) State() acmpb.CurrentPluginStates_DaemonPluginState_StatusValue
- func (p *Plugin) Stop(ctx context.Context, cleanup bool) (*pb.StopResponse, *status.Status)
- func (p *Plugin) Store() error
- type PluginManager
- func (m *PluginManager) ConfigurePluginStates(ctx context.Context, req *acpb.ConfigurePluginStates, localPlugin bool)
- func (m *PluginManager) ListPluginStates(ctx context.Context, req *acpb.ListPluginStates) *acpb.CurrentPluginStates
- func (m *PluginManager) RemoveAllDynamicPlugins(ctx context.Context) error
- type PluginMetrics
- type PluginMonitor
- type PluginType
- type Request
- type RuntimeInfo
- type ServiceConfig
- type Step
- type Watcher
Constants ¶
const ( // WatcherID is the core plugin watcher's ID. WatcherID = "plugin-status-watcher" // EventID is the core plugin event type ID. EventID = "plugin-watcher,status" )
const (
// VMEventCmd is the command name that handler supports.
VMEventCmd = "VmEvent"
)
Variables ¶
var ( // SupportedEvents is the list of supported VM events. Specialize represents // windows sysprep specialize phase. SupportedEvents = []string{"startup", "shutdown", "specialize"} )
Functions ¶
func RegisterCmdHandler ¶
RegisterCmdHandler registers the command handler for VM events. [vmEventHandler]notifies all the plugins about the event over [Apply()] RPC. Plugins may choose to react to the event or ignore.
Types ¶
type Manifest ¶
type Manifest struct { // StartAttempts is the number of times to try launching the plugin. StartAttempts int // MaxMemoryUsage is the maximum allowed memory usage of the plugin, in bytes. MaxMemoryUsage int64 // MaxCPUUsage is the maximum allowed percent CPU usage of the plugin. MaxCPUUsage int32 // MaxMetricDatapoints is the maximum number of datapoints to report/collect. // Metrics are collected every [MetricsInterval] but are flushed from memory // only when reported back to the service. This count limits datapoints from // growing indefinitely. MaxMetricDatapoints uint // MetricsInterval is the interval at which metrics are collected. MetricsInterval time.Duration // StopTimeout is the timeout set on plugin stop request before process is // killed. StopTimeout time.Duration // StartTimeout is the timeout set on plugin start request. StartTimeout time.Duration // StartConfig is the config service has sent down for passing down to the // plugin on each start RPC request. StartConfig *ServiceConfig // LaunchArguments are extra arguments specified by plugin owners to pass down // during process launch. LaunchArguments []string }
Manifest is the plugin specific static config agent received from ACP.
type Metric ¶
type Metric struct {
// contains filtered or unexported fields
}
Metric is a struct to store the plugin's current memory and CPU usage at a specific timestamp.
type Plugin ¶
type Plugin struct { // PluginType identifies if the plugin type. PluginType PluginType // Name is the current plugin name. Name string // Revision is the current plugin revision. Revision string // Address is the current address plugin is listening on. Address string // InstallPath is the path to the directory where plugin is // installed/unpacked. InstallPath string // EntryPath is the path to the plugin/binary entry point from which its spun // up. EntryPath string // Protocol is the protocol used for communication with the plugin. Protocol string // Manifest is plugin configuration defining various agent/plugin behavior. Manifest *Manifest // RuntimeInfo holds plugin runtime information. RuntimeInfo *RuntimeInfo // contains filtered or unexported fields }
Plugin struct represents the plugin information.
func (*Plugin) GetStatus ¶
GetStatus makes the GetStatus RPC request, [req] includes provides the context on what the request is about. For e.g. if we want status for task A, context could be task ID. For regular health check leave it empty.
func (*Plugin) IsRunning ¶
IsRunning checks if the plugin is running by reconnecting and executing a health check.
func (*Plugin) PluginService ¶
func (p *Plugin) PluginService() pb.GuestAgentPluginClient
PluginService returns the underlying plugin service client.
func (*Plugin) State ¶
func (p *Plugin) State() acmpb.CurrentPluginStates_DaemonPluginState_StatusValue
State returns the plugin status.
type PluginManager ¶
type PluginManager struct { // IsInitialized indicates if plugin manager is initialized. IsInitialized atomic.Bool // contains filtered or unexported fields }
PluginManager struct represents the plugins that plugin manager manages.
func InitPluginManager ¶
func InitPluginManager(ctx context.Context, instanceID string) (*PluginManager, error)
InitPluginManager initializes and returns a PluginManager instance. Plugin Manager can be initialized and used to support core plugins even if ACS is disabled. Plugin Manager will be initialized during early Guest Agent startup to configure the core plugins.
func Instance ¶
func Instance() *PluginManager
Instance returns the previously initialized instance of plugin manager.
func (*PluginManager) ConfigurePluginStates ¶
func (m *PluginManager) ConfigurePluginStates(ctx context.Context, req *acpb.ConfigurePluginStates, localPlugin bool)
ConfigurePluginStates configures the plugin states as stated in the request. localPlugin identifies if the plugin is a core plugin. These core plugins are installed by package managers but not launched along with Guest Agent binary. Plugin Manager will launch and manage lifecycle of core plugins along with other dynamic plugins.
func (*PluginManager) ListPluginStates ¶
func (m *PluginManager) ListPluginStates(ctx context.Context, req *acpb.ListPluginStates) *acpb.CurrentPluginStates
ListPluginStates returns the plugin states and cached health check information.
func (*PluginManager) RemoveAllDynamicPlugins ¶
func (m *PluginManager) RemoveAllDynamicPlugins(ctx context.Context) error
RemoveAllDynamicPlugins generates a request and triggers plugin manager to remove all dynamic plugins on the host.
type PluginMetrics ¶
type PluginMetrics struct {
// contains filtered or unexported fields
}
PluginMetrics is a struct to monitor and store a plugin's metrics.
func NewPluginMetrics ¶
func NewPluginMetrics(plugin *Plugin, interval time.Duration) *PluginMetrics
NewPluginMetrics creates a new PluginMetrics.
func (*PluginMetrics) ID ¶
func (p *PluginMetrics) ID() string
ID returns the ID of the plugin metric.
func (*PluginMetrics) Interval ¶
func (p *PluginMetrics) Interval() (time.Duration, bool)
Interval returns the interval of the getting plugin metrics.
func (*PluginMetrics) Run ¶
func (p *PluginMetrics) Run(ctx context.Context) (bool, error)
Run gets and caches the plugin's metrics.
func (*PluginMetrics) ShouldEnable ¶
func (*PluginMetrics) ShouldEnable(ctx context.Context) bool
ShouldEnable returns true if this job should be scheduled or not by the scheduler.
type PluginMonitor ¶
type PluginMonitor struct {
// contains filtered or unexported fields
}
PluginMonitor is a monitor for a plugin which implements scheduler job interface. It runs a health check and restarts the plugin if found unhealthy.
func NewPluginMonitor ¶
func NewPluginMonitor(plugin *Plugin, interval time.Duration) *PluginMonitor
NewPluginMonitor creates a new plugin monitor.
func (*PluginMonitor) Interval ¶
func (m *PluginMonitor) Interval() (time.Duration, bool)
Interval returns the interval for scheduler to run this job.
func (*PluginMonitor) Run ¶
func (m *PluginMonitor) Run(ctx context.Context) (bool, error)
Run runs the plugin health check. Always return true to continue monitoring.
func (*PluginMonitor) ShouldEnable ¶
func (m *PluginMonitor) ShouldEnable(ctx context.Context) bool
ShouldEnable informs scheduler if this job should be scheduled job or not. Always return true to have plugin monitoring.
type PluginType ¶
type PluginType int
PluginType is the type of plugin.
const ( // PluginTypeCore represents plugin is a core plugin. These are generally // packaged with the Guest Agent and installed by package mangers and offer // core Guest Agent functionality and are required to support various GCE // features. PluginTypeCore PluginType = iota // PluginTypeDynamic represents plugin is a dynamic plugin. These type of // plugins are optional plugins that are dynamically downloaded and installed // by the Guest Agent. PluginTypeDynamic )
type Request ¶
type Request struct { command.Request // Event that triggered current request and must be one of [supportedEvents]. Event string `json:"Event"` }
Request struct represents the request from command handler.
type RuntimeInfo ¶
type RuntimeInfo struct { // Pid is the process id of the plugin. Pid int // contains filtered or unexported fields }
RuntimeInfo represent plugin metrics and health check information captured at run time. Expect info here to change during plugin execution.
type ServiceConfig ¶
type ServiceConfig struct { // Simple is simple string form of the config. Simple string // Structured is structured [*structpb.Struct] config message. It is marshaled // to a byte array to persist across agent restarts and reuse on every plugin // start request. Agent will unmarshal using [toProto] method before sending // it to plugins on Start RPC. Structured []byte }
ServiceConfig is agent agnostic data that is passed to the plugin on every start rpc request. At any given time only one of this can be set.
type Step ¶
type Step interface { // The name of the step. Name() string // Status returns the plugin state for current step. Status() acmpb.CurrentPluginStates_DaemonPluginState_StatusValue // ErrorStatus returns the plugin state if current step fails. ErrorStatus() acmpb.CurrentPluginStates_DaemonPluginState_StatusValue // Performs the step. Run(context.Context, *Plugin) error }
Step represents an interface for each step run as part of a plugin configuration.
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher is the plugin event watcher implementation.
func InitWatcher ¶
InitWatcher initializes and registers the watcher to monitor plugin status for a specific request. Runner also removes the watcher as soon as the condition is met.