agent

package
v0.0.0-...-9bdbb14 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const ReasonInvalid = "InvalidReason"

ReasonInvalid indicates a reason provided by the runtime was invalid.

View Source
const ReasonRuntimeError = "RuntimeError"

ReasonRuntimeError is the default reason used when no reason is provided by the runtime.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent struct {
	Log logr.Logger

	// ID is the unique identifier for the agent. It is used by the transport to identify workflows
	// scheduled for this agent.
	ID string

	// Transport is the transport used by the agent for communicating workflows and events.
	Transport Transport

	// Runtime is the container runtime used to execute workflow actions.
	Runtime ContainerRuntime
	// contains filtered or unexported fields
}

Agent is the core data structure for handling workflow execution on target nodes. It leverages a Transport and a ContainerRuntime to retrieve workflows and execute actions.

The agent runs a single workflow at a time. Concurrent requests to run workflows will have the second workflow rejected with an event.WorkflowRejected event.

func (*Agent) CancelWorkflow

func (agent *Agent) CancelWorkflow(workflowID string)

func (*Agent) HandleWorkflow

func (agent *Agent) HandleWorkflow(ctx context.Context, wflw workflow.Workflow, events event.Recorder)

HandleWorkflow satisfies transport.

func (*Agent) Start

func (agent *Agent) Start(ctx context.Context) error

Start finalizes the Agent configuration and starts the configured Transport so it is ready to receive workflows. On receiving a workflow, it will leverage the configured Runtime to execute workflow actions.

type ContainerRuntime

type ContainerRuntime interface {
	// Run executes the action. The runtime should mount the following files for the action
	// implementation to communicate a reason and message in the event of failure:
	//
	//	/tinkerbell/failure-reason
	//	/tinkerbell/failure-message
	//
	// The reason and message should be communicataed via the returned error. The message should
	// be the error message and the reason should be provided as defined in failure.Reason().
	Run(context.Context, workflow.Action) error
}

ContainerRuntime is a runtime capable of executing workflow actions.

type ContainerRuntimeMock

type ContainerRuntimeMock struct {
	// RunFunc mocks the Run method.
	RunFunc func(contextMoqParam context.Context, action workflow.Action) error
	// contains filtered or unexported fields
}

ContainerRuntimeMock is a mock implementation of ContainerRuntime.

func TestSomethingThatUsesContainerRuntime(t *testing.T) {

	// make and configure a mocked ContainerRuntime
	mockedContainerRuntime := &ContainerRuntimeMock{
		RunFunc: func(contextMoqParam context.Context, action workflow.Action) error {
			panic("mock out the Run method")
		},
	}

	// use mockedContainerRuntime in code that requires ContainerRuntime
	// and then make assertions.

}

func (*ContainerRuntimeMock) Run

func (mock *ContainerRuntimeMock) Run(contextMoqParam context.Context, action workflow.Action) error

Run calls RunFunc.

func (*ContainerRuntimeMock) RunCalls

func (mock *ContainerRuntimeMock) RunCalls() []struct {
	ContextMoqParam context.Context
	Action          workflow.Action
}

RunCalls gets all the calls that were made to Run. Check the length with:

len(mockedContainerRuntime.RunCalls())

type Transport

type Transport interface {
	// Start is a blocking call that starts the transport and begins retrieving workflows for the
	// given agentID. The transport should pass workflows to the Handler. The transport
	// should block until its told to cancel via the context.
	Start(_ context.Context, agentID string, _ transport.WorkflowHandler) error
}

Transport is a transport mechanism for communicating workflows to the agent.

type TransportMock

type TransportMock struct {
	// StartFunc mocks the Start method.
	StartFunc func(contextMoqParam context.Context, agentID string, workflowHandler transport.WorkflowHandler) error
	// contains filtered or unexported fields
}

TransportMock is a mock implementation of Transport.

func TestSomethingThatUsesTransport(t *testing.T) {

	// make and configure a mocked Transport
	mockedTransport := &TransportMock{
		StartFunc: func(contextMoqParam context.Context, agentID string, workflowHandler transport.WorkflowHandler) error {
			panic("mock out the Start method")
		},
	}

	// use mockedTransport in code that requires Transport
	// and then make assertions.

}

func (*TransportMock) Start

func (mock *TransportMock) Start(contextMoqParam context.Context, agentID string, workflowHandler transport.WorkflowHandler) error

Start calls StartFunc.

func (*TransportMock) StartCalls

func (mock *TransportMock) StartCalls() []struct {
	ContextMoqParam context.Context
	AgentID         string
	WorkflowHandler transport.WorkflowHandler
}

StartCalls gets all the calls that were made to Start. Check the length with:

len(mockedTransport.StartCalls())

Directories

Path Synopsis
Package event describes the event set and an interface for recording events.
Package event describes the event set and an interface for recording events.
Package runtime contains runtime implementations that can execute workflow actions.
Package runtime contains runtime implementations that can execute workflow actions.
Package transport contains data structures that implement agent transport capabilities.
Package transport contains data structures that implement agent transport capabilities.
Package workflow contains workflow domain objects.
Package workflow contains workflow domain objects.

Jump to

Keyboard shortcuts

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