Documentation
¶
Index ¶
Constants ¶
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.
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 ¶
var ConnKey = &key{}
ConnKey is the context key for storing/retrieving a connector in context.Context.
Functions ¶
func NewTestConnector ¶
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 ¶
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.
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 ¶
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.