Documentation
¶
Index ¶
- Constants
- Variables
- func GetRegisteredModules() map[string]func() Module
- func GetRegisteredPathNames() map[string]string
- func NewLogger(config *RuntimeConfig) *slog.Logger
- func NewTestingLogger() *slog.Logger
- func NewTextHandler(o io.Writer, opts *slog.HandlerOptions) slog.Handler
- func RegisterModule(module string, factory func() Module)
- func RegisterPathName(path, name string)
- type Input
- type InputValue
- type Module
- type ModuleContext
- type ModuleContextFlag
- type ModuleInfo
- type Operation
- type OutputValue
- type RuntimeConfig
- type Workflow
- type WorkflowResult
Constants ¶
const ( UserAgent = "blackstart/1.0" LoggerKey key = "logger" ConfigKey key = "config" SchemeKey key = "scheme" )
Variables ¶
var ErrInputDoesNotExist = errors.New("input does not exist")
var ErrOperationCycle = errors.New("operation cycle detected")
var K8sNamespaceEnv = getConfigEnv("KubeNamespace")
var LogOutputEnv = getConfigEnv("LogOutput")
Functions ¶
func GetRegisteredModules ¶
GetRegisteredModules returns a map of all registered modules and their factory functions.
func GetRegisteredPathNames ¶
GetRegisteredPathNames returns a map of all registered path names.
func NewLogger ¶
func NewLogger(config *RuntimeConfig) *slog.Logger
func NewTestingLogger ¶
func NewTextHandler ¶
func RegisterModule ¶
RegisterModule is used by modules to register themselves with the global module registry. Each module must provide its ID and a factory function that will be used to create new instances of the module. The module factory function should only create the module instance and not perform any setup or validation. It should also not need to return any error, setup and verification of the module will be done in the setup method.
func RegisterPathName ¶
func RegisterPathName(path, name string)
RegisterPathName is used by modules to register a friendly name for a path segment.
Types ¶
type Input ¶
type Input interface {
IsStatic() bool
String() string
Bool() bool
Number() int64
Float() float64
Any() any
Auto() (any, error)
DependencyId() string
OutputKey() string
}
--8<-- [start:Input]
func NewInputFromDep ¶
NewInputFromDep creates a new module input from a dependency output. This is used to reference the output of another operation as the input to this operation. These inputs are only available at runtime.
func NewInputFromValue ¶
func NewInputFromValue(value interface{}) Input
NewInputFromValue creates a new module input from a static value. It detects the type and assigns it to the correct field.
type InputValue ¶
type InputValue struct {
// Description is a short description of the value. This is used to provide context about what
// the value is and how it should be used.
Description string
// Type is the type of the value. This is used to provide context about what type of value is
// expected.
Type reflect.Type
// Required indicates whether the value is required. When used as an input, this indicates
// that the value must be provided for the module to function correctly.
Required bool
// Default is an optional default value for the input parameter.
Default any
}
InputValue is a structure that describes a value used in a module's inputs.
type Module ¶
type Module interface {
// Info returns a ModuleInfo structure that provides information about the module. This is used
// to provide context about the module and its capabilities.
Info() ModuleInfo
// Validate is used by the module to validate that the Operation settings and parameters are
// valid. If the Operation is invalid, then an error should be returned.
Validate(op Operation) error
// Check should be a safe, non-destructive method to ensure the expected state exists. If it
// does not exist, Check must return false. If an alternate error is encountered while checking
// the state, then an error should also be returned.
Check(ctx ModuleContext) (bool, error)
// Set configures the expected state if Check returns false or if tainted.
Set(ctx ModuleContext) error
}
Module is the interface that all modules must implement. Modules are used to configure resources in various systems, but they all provide the same "check then set" interface. When running a job, blackstart will orchestrate the execution of operations and the modules they use. --8<-- [start:Module]
type ModuleContext ¶
type ModuleContext interface {
context.Context
Input(key string) (Input, error)
Output(key string, value interface{}) error
DoesNotExist() bool
Tainted() bool
}
--8<-- [start:ModuleContext]
func InputsToContext ¶
func InputsToContext(ctx context.Context, si map[string]Input, flags ...ModuleContextFlag) ( mctx ModuleContext, )
InputsToContext is a helper function that takes a map of inputs and returns module context with the inputs set as if they were passed at runtime. This is available as a helper for module testing.
func OpContext ¶
func OpContext(ctx context.Context, op *Operation) ModuleContext
OpContext creates a ModuleContext from an Operation. This is available as an exported helper for testing and special cases where a ModuleContext needs to be created directly outside the normal execution flow.
Use caution when using this function, as it will panic if attempting to access a module which has not been registered.
type ModuleContextFlag ¶
type ModuleContextFlag int
const ( TaintedFlag ModuleContextFlag = iota DoesNotExistFlag )
type ModuleInfo ¶
type ModuleInfo struct {
// Id is the identifier of the module. This is used to identify the module in the
// configuration and in the logs.
Id string
// Name is the name of the module. This is a human-readable identifier.
Name string
// Description is a short description of the module. This is used to provide context about
// what the module does and how it should be used.
Description string
// Inputs is a map of input names to their configuration. This is used to provide context
// about what inputs the module requires and how they should be used.
Inputs map[string]InputValue
// Outputs is a map of output names to their descriptions. This is used to provide context
// about what outputs the module provides and how they should be used.
Outputs map[string]OutputValue
// Examples is a map of example titles to their YAML implementations. This is used to provide
// users with a quick way to understand how to use the module.
Examples map[string]string
}
ModuleInfo is a static structure that provides information about a module. It is used to provide metadata about the module, such as its name, description, and the inputs it requires and outputs it provides.
type Operation ¶
type Operation struct {
// Module is the identifier value of the module that will be used to configure the resource.
Module string
// Id is a unique identifier for the operation. This is used to reference the operation in
// other operations.
Id string
// Name is a human-readable name for the operation.
Name string
// Description is a human-readable description of the operation. Use this to provide more
// context about the operation.
Description string
// DependsOn is a list of operation IDs that this operation depends on. The operations that
// this operation depends on will be executed before this operation.
DependsOn []string
// Inputs are used to configure the module. The moduleContext are specific to each module and
// are used to configure the module's behavior.
Inputs map[string]Input
// DoesNotExist is a special parameter that can be used to indicate that the resource should
// not exist. This is useful for resources that are changed from a previous state and now
// should be deleted if they still exist.
DoesNotExist bool
// Tainted is a special parameter that can be used to indicate that the resource is tainted and
// should be replaced. This is useful for resources that always must be updated so that
// attributes / output values are known by Blackstart. This should not be configured by users,
// and should only be used explicitly by modules.
Tainted bool
}
Operation represents a single operation in a Workflow. Each operation uses a specific module to configure resources. In an imperative Workflow, operations could be a step to perform in the Workflow. In Blackstart's declarative Workflow, the order of the operations is determined at runtime based on the dependencies between operations. --8<-- [start:Operation]
type OutputValue ¶
type OutputValue struct {
// Description is a short description of the value. This is used to provide context
// about what the value is and how it should be used.
Description string
// Type is the type of the value. This is used to provide context about what type
// of value is expected.
Type reflect.Type
}
OutputValue is a structure that describes a value used in a module's outputs.
type RuntimeConfig ¶
type RuntimeConfig struct {
Version bool `short:"v" long:"version" description:"Show version information"`
LogOutput string `long:"log-output" env:"BLACKSTART_LOG_OUTPUT" description:"Logging output file name" default:""`
LogFormat string `long:"log-format" env:"BLACKSTART_LOG_FORMAT" description:"Logging format (json, text)" default:"text"`
LogLevel string `long:"log-level" env:"BLACKSTART_LOG_LEVEL" description:"Logging level" default:"info"`
WorkflowFile string `short:"f" long:"workflow-file" env:"BLACKSTART_WORKFLOW_FILE" description:"Path to the workflow file" required:"false"`
KubeNamespace string `` /* 136-byte string literal not displayed */
}
func ReadConfig ¶
func ReadConfig() (*RuntimeConfig, error)
type Workflow ¶
type Workflow struct {
// Name is a simple Name or identifier for the Workflow.
Name string `yaml:"name"`
// Description is an optional field to describe the Workflow in greater detail.
Description string `yaml:"description,omitempty"`
// Operations is a map of operations that will be executed in the Workflow.
Operations []Operation `yaml:"operations"`
// Source is the original source of the workflow definition, if available.
Source any
}
Workflow represents a series of operations to be executed. Each operation may depend on the outputs of other operations, forming a directed acyclic graph (DAG) of operations. The Workflow will be executed in an order that respects these dependencies. --8<-- [start:Workflow]
Directories
¶
| Path | Synopsis |
|---|---|
|
api
|
|
|
v1alpha1
Package v1alpha1 +groupName=blackstart.pezops.github.io
|
Package v1alpha1 +groupName=blackstart.pezops.github.io |
|
cmd
|
|
|
blackstart
command
|
|
|
internal
|
|
|
module_docs
command
|
|
|
modules
|
|