Documentation
¶
Index ¶
- Constants
- Variables
- func EnvironmentIDFromRunnerID(jobID string) (dto.EnvironmentID, error)
- func EnvironmentIDFromTemplateJobID(id string) (dto.EnvironmentID, error)
- func FindAndValidateConfigTask(taskGroup *nomadApi.TaskGroup) *nomadApi.Task
- func FindAndValidateConfigTaskGroup(job *nomadApi.Job) *nomadApi.TaskGroup
- func FindAndValidateDefaultTask(taskGroup *nomadApi.TaskGroup) *nomadApi.Task
- func FindAndValidateDefaultTaskGroup(job *nomadApi.Job) *nomadApi.TaskGroup
- func FindTaskGroup(job *nomadApi.Job, name string) *nomadApi.TaskGroup
- func IsEnvironmentTemplateID(jobID string) bool
- func RunnerJobID(environmentID dto.EnvironmentID, id string) string
- func SetForcePullFlag(job *nomadApi.Job, value bool)
- func TemplateJobID(id dto.EnvironmentID) string
- type APIClient
- func (a *APIClient) ExecuteCommand(ctx context.Context, jobID string, command string, tty bool, ...) (int, error)
- func (a *APIClient) LoadEnvironmentJobs() ([]*nomadApi.Job, error)
- func (a *APIClient) LoadRunnerIDs(prefix string) (runnerIDs []string, err error)
- func (a *APIClient) LoadRunnerJobs(environmentID dto.EnvironmentID) ([]*nomadApi.Job, error)
- func (a *APIClient) LoadRunnerPortMappings(runnerID string) ([]nomadApi.PortMapping, error)
- func (a *APIClient) MonitorEvaluation(ctx context.Context, evaluationID string) (err error)
- func (a *APIClient) RegisterRunnerJob(template *nomadApi.Job) error
- func (a *APIClient) SetRunnerMetaUsed(runnerID string, used bool, duration int) error
- func (a *APIClient) WatchEventStream(ctx context.Context, callbacks *AllocationProcessing) error
- type AllocationProcessing
- type DeletedAllocationProcessor
- type ExecutorAPI
- type ExecutorAPIMock
- func (_m *ExecutorAPIMock) DeleteJob(jobID string) error
- func (_m *ExecutorAPIMock) EventStream(ctx context.Context) (<-chan *api.Events, error)
- func (_m *ExecutorAPIMock) Execute(ctx context.Context, jobID string, command string, tty bool, stdin io.Reader, ...) (int, error)
- func (_m *ExecutorAPIMock) ExecuteCommand(ctx context.Context, jobID string, command string, tty bool, ...) (int, error)
- func (_m *ExecutorAPIMock) LoadEnvironmentJobs() ([]*api.Job, error)
- func (_m *ExecutorAPIMock) LoadRunnerIDs(prefix string) ([]string, error)
- func (_m *ExecutorAPIMock) LoadRunnerJobs(environmentID dto.EnvironmentID) ([]*api.Job, error)
- func (_m *ExecutorAPIMock) LoadRunnerPortMappings(runnerID string) ([]api.PortMapping, error)
- func (_m *ExecutorAPIMock) MonitorEvaluation(ctx context.Context, evaluationID string) error
- func (_m *ExecutorAPIMock) RegisterNomadJob(job *api.Job) (string, error)
- func (_m *ExecutorAPIMock) RegisterRunnerJob(template *api.Job) error
- func (_m *ExecutorAPIMock) SetRunnerMetaUsed(runnerID string, used bool, duration int) error
- func (_m *ExecutorAPIMock) WatchEventStream(ctx context.Context, callbacks *AllocationProcessing) error
- type NewAllocationProcessor
- type RunnerDeletedReason
- type SentryDebugWriter
Constants ¶
const ( // PrivilegedExecution is to indicate the privileged execution of the passed command. PrivilegedExecution = true // UnprivilegedExecution is to indicate the unprivileged execution of the passed command. UnprivilegedExecution = false )
const ( TemplateJobPrefix = "template" TaskGroupName = "default-group" TaskName = "default-task" TaskCount = 1 TaskDriver = "docker" TaskCommand = "sleep" ConfigTaskGroupName = "config" ConfigTaskName = "config" ConfigTaskDriver = "exec" ConfigTaskCommand = "true" ConfigMetaUsedKey = "used" ConfigMetaUsedValue = "true" ConfigMetaUnusedValue = "false" ConfigMetaTimeoutKey = "timeout" ConfigMetaPoolSizeKey = "prewarmingPoolSize" TemplateJobNameParts = 2 RegisterTimeout = 10 * time.Second RunnerTimeoutFallback = 60 * time.Second )
Variables ¶
var ( ErrNoAllocationFound = errors.New("no allocation found") ErrNomadUnknownAllocation = errors.New("unknown allocation") )
var ( ErrInvalidJobID = errors.New("invalid job id") ErrMissingTaskGroup = errors.New("couldn't find config task group in job") TaskArgs = []string{"infinity"} )
var ( ErrExecutorCommunicationFailed = errors.New("communication with executor failed") ErrEvaluation = errors.New("evaluation could not complete") ErrPlacingAllocations = errors.New("failed to place all allocations") ErrLoadingJob = errors.New("failed to load job") ErrNoAllocatedResourcesFound = errors.New("no allocated resources found") ErrLocalDestruction RunnerDeletedReason = errors.New("the destruction should not cause external changes") ErrOOMKilled RunnerDeletedReason = fmt.Errorf("%s: %w", dto.ErrOOMKilled.Error(), ErrLocalDestruction) ErrAllocationRescheduled RunnerDeletedReason = fmt.Errorf("the allocation was rescheduled: %w", ErrLocalDestruction) ErrAllocationStopped RunnerDeletedReason = errors.New("the allocation was stopped") ErrAllocationStoppedUnexpectedly RunnerDeletedReason = fmt.Errorf("%w unexpectedly", ErrAllocationStopped) ErrAllocationRescheduledUnexpectedly RunnerDeletedReason = fmt.Errorf( "%w correctly but rescheduled", ErrAllocationStopped) // ErrAllocationCompleted is for reporting the reason for the stopped allocation. // We do not consider it as an error but add it anyway for a complete reporting. // It is a ErrLocalDestruction because another allocation might be replacing the allocation in the same job. ErrAllocationCompleted RunnerDeletedReason = fmt.Errorf("the allocation completed: %w", ErrLocalDestruction) ErrJobDeregistered RunnerDeletedReason = fmt.Errorf("the job got deregistered: %w", ErrLocalDestruction) )
Functions ¶
func EnvironmentIDFromRunnerID ¶
func EnvironmentIDFromRunnerID(jobID string) (dto.EnvironmentID, error)
EnvironmentIDFromRunnerID returns the environment id that is part of the passed runner job id.
func EnvironmentIDFromTemplateJobID ¶
func EnvironmentIDFromTemplateJobID(id string) (dto.EnvironmentID, error)
EnvironmentIDFromTemplateJobID returns the environment id that is part of the passed environment job id.
func FindAndValidateConfigTask ¶
FindAndValidateConfigTask returns the config task and ensures that a dummy task is in the task group so that the group is accepted by Nomad. It might modify the task.
func FindAndValidateDefaultTask ¶
FindAndValidateDefaultTask returns the default task and ensures that a default task is in the task group in that the executions are made. It might modify the task.
func IsEnvironmentTemplateID ¶
IsEnvironmentTemplateID checks if the passed job id belongs to a template job.
func RunnerJobID ¶
func RunnerJobID(environmentID dto.EnvironmentID, id string) string
RunnerJobID returns the nomad job id of the runner with the given environmentID and id.
func SetForcePullFlag ¶
SetForcePullFlag sets the flag of a job if the image should be pulled again.
func TemplateJobID ¶
func TemplateJobID(id dto.EnvironmentID) string
TemplateJobID returns the id of the nomad job for the environment with the given id.
Types ¶
type APIClient ¶
type APIClient struct {
// contains filtered or unexported fields
}
APIClient implements the ExecutorAPI interface and can be used to perform different operations on the real Executor API and its return values.
func (*APIClient) ExecuteCommand ¶
func (a *APIClient) ExecuteCommand(ctx context.Context, jobID string, command string, tty bool, privilegedExecution bool, stdin io.Reader, stdout, stderr io.Writer, ) (int, error)
ExecuteCommand executes the given command in the given job. If tty is true, Nomad would normally write stdout and stderr of the command both on the stdout stream. However, if the InteractiveStderr server config option is true, we make sure that stdout and stderr are split correctly.
func (*APIClient) LoadEnvironmentJobs ¶
func (*APIClient) LoadRunnerIDs ¶
func (*APIClient) LoadRunnerJobs ¶
func (*APIClient) LoadRunnerPortMappings ¶
func (a *APIClient) LoadRunnerPortMappings(runnerID string) ([]nomadApi.PortMapping, error)
func (*APIClient) MonitorEvaluation ¶
func (*APIClient) RegisterRunnerJob ¶
func (*APIClient) SetRunnerMetaUsed ¶
func (*APIClient) WatchEventStream ¶
func (a *APIClient) WatchEventStream(ctx context.Context, callbacks *AllocationProcessing) error
type AllocationProcessing ¶
type AllocationProcessing struct { OnNew NewAllocationProcessor OnDeleted DeletedAllocationProcessor }
AllocationProcessing includes the callbacks to interact with allocation events.
type DeletedAllocationProcessor ¶
type DeletedAllocationProcessor func(ctx context.Context, jobID string, RunnerDeletedReason error) (removedByPoseidon bool)
DeletedAllocationProcessor is a handler that will be called for each deleted allocation. removedByPoseidon should be true iff the Nomad Manager has removed the runner before.
type ExecutorAPI ¶
type ExecutorAPI interface { // LoadEnvironmentJobs loads all environment jobs. LoadEnvironmentJobs() ([]*nomadApi.Job, error) // LoadRunnerJobs loads all runner jobs specific for the environment. LoadRunnerJobs(environmentID dto.EnvironmentID) ([]*nomadApi.Job, error) // LoadRunnerIDs returns the IDs of all runners with the specified id prefix which are not about to // get stopped. LoadRunnerIDs(prefix string) (runnerIDs []string, err error) // LoadRunnerPortMappings returns the mapped ports of the runner. LoadRunnerPortMappings(runnerID string) ([]nomadApi.PortMapping, error) // RegisterRunnerJob creates a runner job based on the template job. // It registers the job and waits until the registration completes. RegisterRunnerJob(template *nomadApi.Job) error // MonitorEvaluation monitors the given evaluation ID. // It waits until the evaluation reaches one of the states complete, canceled or failed. // If the evaluation was not successful, an error containing the failures is returned. // See also https://github.com/hashicorp/nomad/blob/7d5a9ecde95c18da94c9b6ace2565afbfdd6a40d/command/monitor.go#L175 MonitorEvaluation(ctx context.Context, evaluationID string) error // WatchEventStream listens on the Nomad event stream for allocation and evaluation events. // Depending on the incoming event, any of the given function is executed. // Do not run multiple times simultaneously. WatchEventStream(ctx context.Context, callbacks *AllocationProcessing) error // ExecuteCommand executes the given command in the job/runner with the given id. // It writes the output of the command to stdout/stderr and reads input from stdin. // If tty is true, the command will run with a tty. // Iff privilegedExecution is true, the command will be executed privileged. // The command is passed in the shell form (not the exec array form) and will be executed in a shell. ExecuteCommand(ctx context.Context, jobID string, command string, tty bool, privilegedExecution bool, stdin io.Reader, stdout, stderr io.Writer) (int, error) // SetRunnerMetaUsed marks the runner with the given ID as used or unused. // If used, also the timeout duration is stored in the metadata. SetRunnerMetaUsed(runnerID string, used bool, duration int) error // contains filtered or unexported methods }
ExecutorAPI provides access to a container orchestration solution.
func NewExecutorAPI ¶
NewExecutorAPI creates a new api client. One client is usually sufficient for the complete runtime of the API.
type ExecutorAPIMock ¶
ExecutorAPIMock is an autogenerated mock type for the ExecutorAPI type
func NewExecutorAPIMock ¶
func NewExecutorAPIMock(t interface { mock.TestingT Cleanup(func()) }) *ExecutorAPIMock
NewExecutorAPIMock creates a new instance of ExecutorAPIMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*ExecutorAPIMock) DeleteJob ¶
func (_m *ExecutorAPIMock) DeleteJob(jobID string) error
DeleteJob provides a mock function with given fields: jobID
func (*ExecutorAPIMock) EventStream ¶
EventStream provides a mock function with given fields: ctx
func (*ExecutorAPIMock) Execute ¶
func (_m *ExecutorAPIMock) Execute(ctx context.Context, jobID string, command string, tty bool, stdin io.Reader, stdout io.Writer, stderr io.Writer) (int, error)
Execute provides a mock function with given fields: ctx, jobID, command, tty, stdin, stdout, stderr
func (*ExecutorAPIMock) ExecuteCommand ¶
func (_m *ExecutorAPIMock) ExecuteCommand(ctx context.Context, jobID string, command string, tty bool, privilegedExecution bool, stdin io.Reader, stdout io.Writer, stderr io.Writer) (int, error)
ExecuteCommand provides a mock function with given fields: ctx, jobID, command, tty, privilegedExecution, stdin, stdout, stderr
func (*ExecutorAPIMock) LoadEnvironmentJobs ¶
func (_m *ExecutorAPIMock) LoadEnvironmentJobs() ([]*api.Job, error)
LoadEnvironmentJobs provides a mock function with given fields:
func (*ExecutorAPIMock) LoadRunnerIDs ¶
func (_m *ExecutorAPIMock) LoadRunnerIDs(prefix string) ([]string, error)
LoadRunnerIDs provides a mock function with given fields: prefix
func (*ExecutorAPIMock) LoadRunnerJobs ¶
func (_m *ExecutorAPIMock) LoadRunnerJobs(environmentID dto.EnvironmentID) ([]*api.Job, error)
LoadRunnerJobs provides a mock function with given fields: environmentID
func (*ExecutorAPIMock) LoadRunnerPortMappings ¶
func (_m *ExecutorAPIMock) LoadRunnerPortMappings(runnerID string) ([]api.PortMapping, error)
LoadRunnerPortMappings provides a mock function with given fields: runnerID
func (*ExecutorAPIMock) MonitorEvaluation ¶
func (_m *ExecutorAPIMock) MonitorEvaluation(ctx context.Context, evaluationID string) error
MonitorEvaluation provides a mock function with given fields: ctx, evaluationID
func (*ExecutorAPIMock) RegisterNomadJob ¶
func (_m *ExecutorAPIMock) RegisterNomadJob(job *api.Job) (string, error)
RegisterNomadJob provides a mock function with given fields: job
func (*ExecutorAPIMock) RegisterRunnerJob ¶
func (_m *ExecutorAPIMock) RegisterRunnerJob(template *api.Job) error
RegisterRunnerJob provides a mock function with given fields: template
func (*ExecutorAPIMock) SetRunnerMetaUsed ¶
func (_m *ExecutorAPIMock) SetRunnerMetaUsed(runnerID string, used bool, duration int) error
SetRunnerMetaUsed provides a mock function with given fields: runnerID, used, duration
func (*ExecutorAPIMock) WatchEventStream ¶
func (_m *ExecutorAPIMock) WatchEventStream(ctx context.Context, callbacks *AllocationProcessing) error
WatchEventStream provides a mock function with given fields: ctx, callbacks
type NewAllocationProcessor ¶
DeletedAllocationProcessor is a handler that will be called for each deleted allocation. removedByPoseidon should be true iff the Nomad Manager has removed the runner before.
type RunnerDeletedReason ¶
type RunnerDeletedReason error
type SentryDebugWriter ¶
type SentryDebugWriter struct { Target io.Writer //nolint:containedctx // See #630. Ctx context.Context // contains filtered or unexported fields }
SentryDebugWriter is scanning the input for the debug message pattern. For matches, it creates a Sentry Span. Otherwise, the data will be forwarded to the Target. The passed context Ctx should contain the Sentry data.
func NewSentryDebugWriter ¶
func NewSentryDebugWriter(ctx context.Context, target io.Writer) *SentryDebugWriter
func (*SentryDebugWriter) Close ¶
func (s *SentryDebugWriter) Close(exitCode int)