Documentation
¶
Index ¶
- func CommandString(base, extra []string) string
- func RegisterSectionExtension(field string, ext SectionExtension)
- func SectionDecode(data *yaml.Node, v any) error
- func UnregisterSectionExtension(field string)
- type Check
- type CheckLevel
- type CheckStartup
- type ContextOptions
- type ExecCheck
- type FormatError
- type HTTPCheck
- type ImmutableSection
- type Layer
- type LogTarget
- type LogTargetType
- type OptionalDuration
- type OptionalFloat
- type Override
- type Plan
- type Section
- type SectionExtension
- type Service
- type ServiceAction
- type ServiceStartup
- type TCPCheck
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CommandString ¶
CommandString returns a service command as a string after appending the arguments in "extra" to the command in "base"
func RegisterSectionExtension ¶ added in v1.17.0
func RegisterSectionExtension(field string, ext SectionExtension)
RegisterSectionExtension adds a plan schema extension. All registrations must be done before the plan library is used. The order in which extensions are registered determines the order in which the sections are marshalled. Extension sections are marshalled after the built-in sections.
func UnregisterSectionExtension ¶ added in v1.17.0
func UnregisterSectionExtension(field string)
UnregisterSectionExtension removes a plan schema extension. This is only intended for use by tests during cleanup.
Types ¶
type Check ¶
type Check struct {
// Basic details
Name string `yaml:"-"`
Override Override `yaml:"override,omitempty"`
Level CheckLevel `yaml:"level,omitempty"`
Startup CheckStartup `yaml:"startup,omitempty"`
// Common check settings
Period OptionalDuration `yaml:"period,omitempty"`
Timeout OptionalDuration `yaml:"timeout,omitempty"`
Threshold int `yaml:"threshold,omitempty"`
// Type-specific check settings (only one of these can be set)
HTTP *HTTPCheck `yaml:"http,omitempty"`
TCP *TCPCheck `yaml:"tcp,omitempty"`
Exec *ExecCheck `yaml:"exec,omitempty"`
}
Check specifies configuration for a single health check.
type CheckLevel ¶
type CheckLevel string
CheckLevel specifies the optional check level.
const ( UnsetLevel CheckLevel = "" AliveLevel CheckLevel = "alive" ReadyLevel CheckLevel = "ready" )
type CheckStartup ¶ added in v1.19.0
type CheckStartup string
CheckStartup defines the different startup modes for a check.
const ( CheckStartupUnknown CheckStartup = "" CheckStartupEnabled CheckStartup = "enabled" CheckStartupDisabled CheckStartup = "disabled" )
type ContextOptions ¶
type ContextOptions struct {
Environment map[string]string
UserID *int
User string
GroupID *int
Group string
WorkingDir string
}
ContextOptions holds service context config fields.
func MergeServiceContext ¶
func MergeServiceContext(p *Plan, serviceName string, overrides ContextOptions) (ContextOptions, error)
MergeServiceContext merges the overrides on top of the service context specified by serviceName, returning a new ContextOptions value. If serviceName is "" (context not specified), return overrides directly.
type ExecCheck ¶
type ExecCheck struct {
Command string `yaml:"command,omitempty"`
ServiceContext string `yaml:"service-context,omitempty"`
Environment map[string]string `yaml:"environment,omitempty"`
UserID *int `yaml:"user-id,omitempty"`
User string `yaml:"user,omitempty"`
GroupID *int `yaml:"group-id,omitempty"`
Group string `yaml:"group,omitempty"`
WorkingDir string `yaml:"working-dir,omitempty"`
}
ExecCheck holds the configuration for an exec health check.
type FormatError ¶
type FormatError struct {
Message string
}
FormatError is the error returned when a layer has a format error, such as a missing "override" field.
func (*FormatError) Error ¶
func (e *FormatError) Error() string
type HTTPCheck ¶
type HTTPCheck struct {
URL string `yaml:"url,omitempty"`
Headers map[string]string `yaml:"headers,omitempty"`
}
HTTPCheck holds the configuration for an HTTP health check.
type ImmutableSection ¶ added in v1.29.0
type Layer ¶
type Layer struct {
Order int `yaml:"-"`
Label string `yaml:"-"`
Summary string `yaml:"summary,omitempty"`
Description string `yaml:"description,omitempty"`
Services map[string]*Service `yaml:"services,omitempty"`
Checks map[string]*Check `yaml:"checks,omitempty"`
LogTargets map[string]*LogTarget `yaml:"log-targets,omitempty"`
Sections map[string]Section `yaml:",inline"`
}
Layer represents an unmarshalled YAML layer configuration file. Layer files are maintained as part of the Plan, ordered by their respective order number. Each layer configuration also has a unique label, used for locating and updating a specific layer configuration.
Pebble supports a two-level layer configuration directory structure. In the root layers directory, both layer files and layer sub-directories are allowed. Within a sub-directory, only layer files are allowed.
Please see ReadLayersDir for more details.
func CombineLayers ¶
CombineLayers combines the given layers into a single layer, with the later layers overriding earlier ones. Neither the individual layers nor the combined layer are validated here - the caller should have validated the individual layers prior to calling, and validate the combined output if required.
func ReadLayersDir ¶
ReadLayersDir loads the YAML layer files from the first two directory levels starting at layersDir in the order as specified by the order directory and file order prefixes. The directory and file suffixes are dropped in the returned labels.
| File (inside layersDir) | Order | Label | | -------------------------- | --------------- | ------- | | 001-foo.yaml | 001-000 => 1000 | foo | | 002-bar.d/001-aaa.yaml | 002-001 => 2001 | bar/aaa | | 002-bar.d/002-bbb.yaml | 002-002 => 2002 | bar/bbb | | 003-baz.yaml | 003-000 => 3000 | baz |
type LogTarget ¶
type LogTarget struct {
Name string `yaml:"-"`
Type LogTargetType `yaml:"type"`
Location string `yaml:"location"`
Services []string `yaml:"services"`
Override Override `yaml:"override,omitempty"`
Labels map[string]string `yaml:"labels,omitempty"`
}
LogTarget specifies a remote server to forward logs to.
type LogTargetType ¶
type LogTargetType string
LogTargetType defines the protocol to use to forward logs.
const ( LokiTarget LogTargetType = "loki" OpenTelemetryTarget LogTargetType = "opentelemetry" SyslogTarget LogTargetType = "syslog" UnsetLogTarget LogTargetType = "" )
type OptionalDuration ¶
func (OptionalDuration) IsZero ¶
func (o OptionalDuration) IsZero() bool
func (OptionalDuration) MarshalYAML ¶
func (o OptionalDuration) MarshalYAML() (any, error)
func (*OptionalDuration) UnmarshalYAML ¶
func (o *OptionalDuration) UnmarshalYAML(value *yaml.Node) error
type OptionalFloat ¶
func (OptionalFloat) IsZero ¶
func (o OptionalFloat) IsZero() bool
func (OptionalFloat) MarshalYAML ¶
func (o OptionalFloat) MarshalYAML() (any, error)
func (*OptionalFloat) UnmarshalYAML ¶
func (o *OptionalFloat) UnmarshalYAML(value *yaml.Node) error
type Plan ¶
type Plan struct {
Layers []*Layer `yaml:"-"`
Services map[string]*Service `yaml:"services,omitempty"`
Checks map[string]*Check `yaml:"checks,omitempty"`
LogTargets map[string]*LogTarget `yaml:"log-targets,omitempty"`
Sections map[string]Section `yaml:",inline"`
}
func NewPlan ¶ added in v1.20.0
func NewPlan() *Plan
NewPlan creates an empty plan which includes empty registered extension fields. In the case of no plan layers, this ensures that plan callback handlers always get a valid extension backing type to access.
func ReadDir ¶
ReadDir reads the configuration layers from layersDir, and returns the resulting Plan. If layersDir doesn't exist, it returns a valid Plan with no layers. If base is not nil, layers read from the given layersDir will be stacked on top of the given base plan.
func (*Plan) MarshalYAML ¶ added in v1.17.0
MarshalYAML implements an override for top level omitempty tags handling. This is required since Sections are based on an inlined map, for which omitempty and inline together is not currently supported.
func (*Plan) StartOrder ¶
StartOrder returns the required services that must be started for the named services to be properly started, in the order that they must be started. An error is returned when a provided service name does not exist, or there is an order cycle involving the provided service or its dependencies.
func (*Plan) StopOrder ¶
StopOrder returns the required services that must be stopped for the named services to be properly stopped, in the order that they must be stopped. An error is returned when a provided service name does not exist, or there is an order cycle involving the provided service or its dependencies.
type SectionExtension ¶ added in v1.17.0
type SectionExtension interface {
// ParseSection returns a newly allocated concrete type containing the
// unmarshalled section content.
ParseSection(data yaml.Node) (Section, error)
// CombineSections returns a newly allocated concrete type containing the
// result of combining the supplied sections in order.
CombineSections(sections ...Section) (Section, error)
// ValidatePlan takes the complete plan as input, and allows the
// extension to validate the plan. This can be used for cross section
// dependency validation.
ValidatePlan(plan *Plan) error
}
SectionExtension allows the plan layer schema to be extended without adding centralised schema knowledge to the plan library.
type Service ¶
type Service struct {
// Basic details
Name string `yaml:"-"`
Summary string `yaml:"summary,omitempty"`
Description string `yaml:"description,omitempty"`
Startup ServiceStartup `yaml:"startup,omitempty"`
Override Override `yaml:"override,omitempty"`
Command string `yaml:"command,omitempty"`
// Service dependencies
After []string `yaml:"after,omitempty"`
Before []string `yaml:"before,omitempty"`
Requires []string `yaml:"requires,omitempty"`
// Options for command execution
Workload string `yaml:"workload,omitempty"`
Environment map[string]string `yaml:"environment,omitempty"`
UserID *int `yaml:"user-id,omitempty"`
User string `yaml:"user,omitempty"`
GroupID *int `yaml:"group-id,omitempty"`
Group string `yaml:"group,omitempty"`
WorkingDir string `yaml:"working-dir,omitempty"`
// Auto-restart and backoff functionality
OnSuccess ServiceAction `yaml:"on-success,omitempty"`
OnFailure ServiceAction `yaml:"on-failure,omitempty"`
OnCheckFailure map[string]ServiceAction `yaml:"on-check-failure,omitempty"`
BackoffDelay OptionalDuration `yaml:"backoff-delay,omitempty"`
BackoffFactor OptionalFloat `yaml:"backoff-factor,omitempty"`
BackoffLimit OptionalDuration `yaml:"backoff-limit,omitempty"`
KillDelay OptionalDuration `yaml:"kill-delay,omitempty"`
}
func (*Service) ParseCommand ¶
ParseCommand returns a service command as two stream of strings. The base command is returned as a stream and the default arguments in [ ... ] group is returned as another stream.
type ServiceAction ¶
type ServiceAction string
const ( // Actions allowed in all contexts ActionUnset ServiceAction = "" ActionRestart ServiceAction = "restart" ActionShutdown ServiceAction = "shutdown" ActionIgnore ServiceAction = "ignore" // Actions only allowed in specific contexts ActionFailureShutdown ServiceAction = "failure-shutdown" ActionSuccessShutdown ServiceAction = "success-shutdown" )
type ServiceStartup ¶
type ServiceStartup string
const ( StartupUnknown ServiceStartup = "" StartupEnabled ServiceStartup = "enabled" StartupDisabled ServiceStartup = "disabled" )