entrypoint

package
v0.0.0-...-ace5c41 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: Apache-2.0 Imports: 16 Imported by: 6

Documentation

Overview

Package entrypoint is a library that knows how to wrap a process and write it's output and exit code to disk

Index

Constants

View Source
const (

	// InternalErrorCode is what we write to the marker file to
	// indicate that we failed to start the wrapped command
	InternalErrorCode = 127
	// AbortedErrorCode is what we write to the marker file to
	// indicate that we were terminated via a signal.
	AbortedErrorCode = 130

	// PreviousErrorCode indicates a previous step failed so we
	// did not run this step.
	PreviousErrorCode = internalCode + AbortedErrorCode

	// DefaultTimeout is the default timeout for the test
	// process before SIGINT is sent
	DefaultTimeout = 120 * time.Minute

	// DefaultGracePeriod is the default timeout for the test
	// process after SIGINT is sent before SIGKILL is sent
	DefaultGracePeriod = 15 * time.Second
)
View Source
const (
	// JSONConfigEnvVar is the environment variable that
	// utilities expect to find a full JSON configuration
	// in when run.
	JSONConfigEnvVar = "ENTRYPOINT_OPTIONS"
)

Variables

This section is empty.

Functions

func Encode

func Encode(options Options) (string, error)

Encode will encode the set of options in the format that is expected for the configuration environment variable

Types

type Options

type Options struct {
	// Timeout determines how long to wait before the
	// entrypoint sends SIGINT to the process
	Timeout time.Duration `json:"timeout"`
	// GracePeriod determines how long to wait after
	// sending SIGINT before the entrypoint sends
	// SIGKILL.
	GracePeriod time.Duration `json:"grace_period"`
	// ArtifactDir is a directory where test processes can dump artifacts
	// for upload to persistent storage (courtesy of sidecar).
	// If specified, it is created by entrypoint before starting the test process.
	// May be ignored if not using sidecar.
	ArtifactDir string `json:"artifact_dir,omitempty"`

	// PreviousMarker has no effect when empty (default).
	// When set it causes entrypoint to:
	// a) wait until previous_marker exists
	// b) run args as normal if previous_marker == 0
	// c) otherwise immediately write PreviousErrorCode to marker_file without running args
	PreviousMarker string `json:"previous_marker,omitempty"`

	// AlwaysZero will cause entrypoint to exit zero, regardless of the marker it writes.
	// Primarily useful in case a subsequent entrypoint will read this entrypoint's marker
	AlwaysZero bool `json:"always_zero,omitempty"`

	// PropagateErrorCode will cause entrypoint to propagate the error code from its child.
	// Primarily useful in case you want to exit with a specific error code.
	PropagateErrorCode bool `json:"propagate_error_code,omitempty"`

	CopyModeOnly bool   `json:"copy_mode_only,omitempty"`
	CopyDst      string `json:"copy_dst,omitempty"`

	*wrapper.Options
}

Options exposes the configuration necessary for defining the process being watched and where in GCS an upload will land.

func NewOptions

func NewOptions() *Options

NewOptions returns an empty Options with no nil fields

func (*Options) AddFlags

func (o *Options) AddFlags(flags *flag.FlagSet)

AddFlags binds flags to options

func (*Options) Complete

func (o *Options) Complete(args []string)

Complete internalizes command line arguments

func (*Options) ConfigVar

func (o *Options) ConfigVar() string

ConfigVar exposes the environment variable used to store serialized configuration

func (Options) ExecuteProcess

func (o Options) ExecuteProcess(signaledInterrupt chan os.Signal) (int, error)

ExecuteProcess creates the artifact directory then executes the process as configured, writing the output to the process log.

func (*Options) LoadConfig

func (o *Options) LoadConfig(config string) error

LoadConfig loads options from serialized config

func (*Options) Mark

func (o *Options) Mark(exitCode int) error

func (Options) Run

func (o Options) Run() int

Run executes the test process then writes the exit code to the marker file. This function returns the status code that should be passed to os.Exit().

func (*Options) Validate

func (o *Options) Validate() error

Validate ensures that the set of options are self-consistent and valid

Jump to

Keyboard shortcuts

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