internal

package
v4.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StdoutSuccess is the value returned when a module finishes successfully.
	// Usually, this means the module executed its task as expected without errors.
	StdoutSuccess = "success"

	// StdoutFailed is the value returned when a module fails to complete its task.
	// Any fatal error in execution will typically result in this status.
	StdoutFailed = "failed"

	// StdoutSkip is used when a module decides to skip its operation, for example,
	// due to a "when" condition being false, or a particular host/state not requiring action.
	StdoutSkip = "skip"
)

Standard output results for module execution. These constants are used to standardize the messages returned by modules for their basic result states.

View Source
const (
	// StderrGetConnector indicates that the connector (responsible for host communication)
	// could not be obtained or initialized. This can occur if connection details are missing,
	// invalid, or initialization logic fails.
	StderrGetConnector = "failed to get connector"

	// StderrGetHostVariable indicates a failure to retrieve the required host variables.
	// The module likely depends on host-scoped data that could not be loaded or parsed.
	StderrGetHostVariable = "failed to get host variable"

	// StderrParseArgument means module arguments could not be parsed.
	// For example, if user-provided arguments are malformed, missing, or not valid YAML/JSON/etc.
	StderrParseArgument = "failed to parse argument"

	// StderrUnsupportArgs means the arguments provided are syntactically valid but
	// not recognized or not supported by the current module's implementation.
	StderrUnsupportArgs = "unsupport args"

	// StderrGetPlaybook is returned when the playbook (the sequence of tasks or operations)
	// could not be loaded, parsed, or found. Module execution often depends on an existing playbook context.
	StderrGetPlaybook = "failed to get playbook"
)

Standard error messages for module execution failures. Each error string describes a specific reason for failure, facilitating debugging and log interpretation.

Variables

View Source
var ConnKey = &key{}

ConnKey is the context key for storing/retrieving a connector in context.Context.

Functions

func NewTestConnector

func NewTestConnector(stdout, stderr string, err error) connector.Connector

NewTestConnector creates a mock implementation of the connector.Connector interface for testing purposes. The returned connector uses the provided stdout, stderr, and err to simulate the result of operations. All methods will behave as follows: - ExecuteCommand returns the preset stdout, stderr, and err values. - PutFile, FetchFile, Init, and Close all simply return the err value. This allows unit tests to simulate various outputs and errors from a module's connector-dependent calls.

func NewTestVariable

func NewTestVariable(hosts []string, vars map[string]any) variable.Variable

NewTestVariable creates a new variable.Variable for testing purposes. It initializes a test playbook and client via _const.NewTestPlaybook, then creates an in-memory variable source. It merges the provided vars as remote variables for the specified hosts. This allows you to customize the per-host variable context for unit tests needing module execution context.

func RegisterModule

func RegisterModule(exec ModuleExecFunc, moduleName ...string) error

RegisterModule registers a module execution function under the given module name.

Types

type Error

type Error struct {
	Msg string
}

Error is a simple error type for module registration errors.

func (*Error) Error

func (e *Error) Error() string

type ExecOptions

type ExecOptions struct {
	// Args contains the defined arguments for the module.
	Args runtime.RawExtension
	// Host specifies which host to execute the module on.
	Host string
	// Variable provides the variables needed by the module.
	variable.Variable
	// Task is the task to be executed.
	Task kkcorev1alpha1.Task
	// Playbook is the playbook to be executed.
	Playbook kkcorev1.Playbook
	// LogOutput is the output writer for module logs.
	// +optional
	LogOutput io.Writer
}

ExecOptions represents options for module execution.

func (ExecOptions) GetAllVariables

func (o ExecOptions) GetAllVariables() (map[string]any, error)

GetAllVariables retrieves all variables for the specified host in Execinternal.

func (ExecOptions) GetConnector

func (o ExecOptions) GetConnector(ctx context.Context) (connector.Connector, error)

GetConnector returns a connector for the specified host in Execinternal.

type ModuleExecFunc

type ModuleExecFunc func(ctx context.Context, opts ExecOptions) (stdout string, stderr string, err error)

ModuleExecFunc defines the function signature for executing a module.

func FindModule

func FindModule(moduleName string) ModuleExecFunc

FindModule retrieves a registered module execution function by its name.

Jump to

Keyboard shortcuts

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