Documentation
¶
Overview ¶
Package customplugins provides a way to register and run custom plugins.
Index ¶
Constants ¶
const ( HealthStateOutputPrefixType = "GPUD_HEALTH_STATE_TYPE:" HealthStateOutputPrefixReason = "GPUD_HEALTH_STATE_REASON:" )
HealthStateOutputPrefixType defines the prefix for the line, where each plugin is expected to emit its state data in JSON format. The JSON data schema for the state is defined in api/v1/types.go.
const ( MaxPluginNameLength = 32 DefaultTimeout = 1 * time.Minute )
Variables ¶
var ( ErrComponentNameRequired = errors.New("component name is required") ErrStepNameRequired = errors.New("step name is required") ErrMissingPluginStep = errors.New("plugin step cannot be empty") ErrMissingStatePlugin = errors.New("state plugin is required") ErrScriptRequired = errors.New("script is required") ErrIntervalTooShort = errors.New("interval is too short") )
Functions ¶
func ConvertToComponentName ¶
ConvertToComponentName converts the plugin name to a component name. It replaces all whitespace characters with underscores.
func ReadHealthStateFromLines ¶
func ReadHealthStateFromLines(lines []string) (apiv1.HealthStateType, string, error)
ReadHealthStateFromLines reads the health state from the lines.
Types ¶
type CustomPluginRegisteree ¶
type CustomPluginRegisteree interface {
// IsCustomPlugin returns true if the component is a custom plugin.
IsCustomPlugin() bool
// Spec returns the custom plugin spec.
Spec() Spec
}
CustomPluginRegisteree is an optional interface that can be implemented by components to allow them to be registered as custom plugins.
type Plugin ¶
type Plugin struct {
// Steps is a sequence of steps to run for this plugin.
// Multiple steps are executed in order.
// If a step fails, the execution stops and the error is returned.
// Which means, the final success requires all steps to succeed.
Steps []Step `json:"steps,omitempty"`
}
Plugin represents a plugin spec.
type RunBashScript ¶
type RunBashScript struct {
// ContentType is the content encode type of the script.
// Possible values: "plaintext", "base64".
ContentType string `json:"content_type"`
// Script is the script to run for this job.
// Assumed to be base64 encoded.
Script string `json:"script"`
}
RunBashScript represents the bash script runtime.
func (*RunBashScript) Validate ¶
func (b *RunBashScript) Validate() error
Validate validates the run bash script.
type Spec ¶
type Spec struct {
// PluginName describes the plugin.
// It is used for generating the component name.
PluginName string `json:"plugin_name"`
// StatePlugin represents the jobs to run for /states API.
StatePlugin *Plugin `json:"state_plugin,omitempty"`
// DryRun is set to true to allow non-zero exit code on the script
// useful for dry runs.
DryRun bool `json:"dry_run,omitempty"`
// Timeout is the timeout for the script execution.
// If zero, it uses the default timeout (1-minute).
Timeout metav1.Duration `json:"timeout"`
// Interval is the interval for the script execution.
// If zero, it runs only once.
Interval metav1.Duration `json:"interval"`
}
Spec is a plugin spec and configuration. Each spec represents a single state or event, in the external-plugin component.
func (*Spec) ComponentName ¶
ComponentName returns the component name for the plugin spec.
func (*Spec) NewInitFunc ¶
func (spec *Spec) NewInitFunc() components.InitFunc
NewInitFunc creates a new component initializer for the given plugin spec.
func (*Spec) RunStatePlugin ¶
RunStatePlugin runs the state plugin and returns the output and its exit code.
type Specs ¶
type Specs []Spec
Specs is a list of plugin specs.
type Step ¶
type Step struct {
// Name is the name of the step.
Name string `json:"name,omitempty"`
// RunBashScript is the bash script to run for this step.
RunBashScript *RunBashScript `json:"run_bash_script,omitempty"`
}
Step represents a step in a plugin.