firecracker
Last updated: 2024-12-24 01:09:50.566046 File source: link on GitLab
firecracker
Table of Contents
Specification
Description
This sub-package contains functionality including drivers and api for the Firecracker executor.
Structure and Organisation
Here is quick overview of the contents of this pacakge:
README: Current file which is aimed towards developers who wish to use and modify the Firecracker functionality.
client: This file provides a high level wrapper around the Firecracker library.
executor: This is the main implementation of the executor interface for Firecracker. It is the entry point of the sub-package. It is intended to be used as a singleton.
handler: This file contains a handler implementation to manage the lifecycle of a single job.
init: This file is responsible for initialization of the package. Currently it only initializes a logger to be used through out the sub-package.
types: This file contains Models that are specifically related to the Firecracker executor. Mainly it contains the engine spec model that describes a Firecracker job.
Files with *_test.go
suffix contain unit tests for the functionality in corresponding file.
Class Diagram
Source
Rendered from source file
Functionality
Below methods have been implemented in this package:
NewExecutor
signature:
NewExecutor(_ context.Context, id string) -> (executor.firecracker.Executor, error)
input #1:
Go context
input #2: identifier of the executor
output (sucess): Executor instance of type
executor.firecracker.Executor
output (error): error
NewExecutor
function initializes a new Executor instance for Firecracker VMs.
It is expected that NewExecutor
would be called prior to calling any other executor functions. The Executor instance returned would then be used to call other functions like Start
, Stop
etc.
Start
For function signature refer to the package readme
Start
function begins the execution of a request by starting a Firecracker VM. It creates the VM based on the configuration parameters provided in the execution request. It returns an error message if
execution is already started
execution is already finished
there is failure is creation of a new VM
Wait
For function signature refer to the package readme
Wait
initiates a wait for the completion of a specific execution using its executionID
. The function returns two channels: one for the result and another for any potential error.
If the executionID
is not found, an error is immediately sent to the error channel.
Otherwise, an internal goroutine is spawned to handle the asynchronous waiting. The entity calling should use the two returned channels to wait for the result of the execution or an error. If there is a cancellation request (context is done) before completion, an error is relayed to the error channel. When the execution is finished, both the channels are closed.
Cancel
For function signature refer to the package readme
Cancel
tries to terminate an ongoing execution identified by its executionID
. It returns an error if the execution does not exist.
Run
For function signature refer to the package readme
Run
initiates and waits for the completion of an execution in one call. This method serves as a higher-level convenience function that internally calls Start
and Wait
methods. It returns the result of the execution as executor.ExecutionResult
type.
It returns an error in case of:
failure in starting the VM
failure in waiting
context is cancelled
Cleanup
signature:
Cleanup(ctx context.Context) -> error
input:
Go context
output (sucess): None
output (error): error
Cleanup
removes all firecracker resources associated with the executor. This includes stopping and removing all running VMs and deleting their socket paths. It returns an error it it is unable to remove the containers.
Data Types
executor.firecracker.Executor
: This is the instance of the executor created by NewExecutor
function. It contains the firecracker client and other resources required to execute requests.
executor.firecracker.executionHandler
: This contains necessary information to manage the execution of a firecracker VM.
Refer to package readme for other data types.
Testing
Unit tests for each functionality are defined in files with *_test.go
naming convention.
Proposed Functionality / Requirements
List of issues
All issues that are related to the implementation of executor
package can be found below. These include any proposals for modifications to the package or new functionality needed to cover the requirements of other packages.
References
Last updated