customplugins

package
v0.5.0-rc-2 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package customplugins provides a way to register and run custom plugins.

Index

Constants

View Source
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.

View Source
const (
	MaxPluginNameLength = 32
	DefaultTimeout      = 1 * time.Minute
)

Variables

View Source
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

func ConvertToComponentName(name string) string

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.

func (*Plugin) Validate

func (p *Plugin) Validate() error

Validate validates all the plugin steps.

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

func (spec *Spec) ComponentName() string

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

func (spec *Spec) RunStatePlugin(ctx context.Context) ([]byte, int32, error)

RunStatePlugin runs the state plugin and returns the output and its exit code.

func (*Spec) Validate

func (spec *Spec) Validate() error

Validate validates the plugin spec.

type Specs

type Specs []Spec

Specs is a list of plugin specs.

func LoadSpecs

func LoadSpecs(path string) (Specs, error)

LoadSpecs loads the plugin specs from the given path.

func (Specs) Validate

func (specs Specs) Validate() error

Validate validates all the 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.

func (*Step) Validate

func (st *Step) Validate() error

Validate validates the plugin step.

Jump to

Keyboard shortcuts

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