disruptors

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package disruptors implements an API for disrupting targets

Index

Constants

View Source
const DefaultTargetPort = 80

DefaultTargetPort defines default target port if not specified in Fault

Variables

View Source
var ErrSelectorNoPods = errors.New("no pods found matching selector")

ErrSelectorNoPods is returned by NewPodDisruptor when the selector passed to it does not match any pod in the cluster.

View Source
var ErrServiceNoTargets = errors.New("service does not have any backing pods")

ErrServiceNoTargets is returned by NewServiceDisruptor when passed a service without any pod matching its selector.

Functions

This section is empty.

Types

type AgentController

type AgentController interface {
	// InjectDisruptorAgent injects the Disruptor agent in the target pods
	InjectDisruptorAgent(ctx context.Context) error
	// ExecCommand executes a command in the targets of the AgentController and reports any error
	ExecCommand(ctx context.Context, cmd []string) error
	// Targets retrieves the names of the target of the controller
	Targets(ctx context.Context) ([]string, error)
	// Visit allows executing a different command on each target returned by a visiting function
	Visit(ctx context.Context, visitor func(target corev1.Pod) (VisitCommands, error)) error
}

AgentController defines the interface for controlling agents in a set of targets

func NewAgentController added in v0.2.0

func NewAgentController(
	_ context.Context,
	helper helpers.PodHelper,
	namespace string,
	targets []corev1.Pod,
	timeout time.Duration,
) AgentController

NewAgentController creates a new controller for a list of target pods

type Disruptor added in v0.3.1

type Disruptor interface {
	// Targets returns the names of the targets for the disruptor
	Targets(ctx context.Context) ([]string, error)
}

Disruptor defines the generic interface implemented by all disruptors

type GrpcDisruptionOptions added in v0.2.0

type GrpcDisruptionOptions struct {
	// Port used by the agent for listening
	ProxyPort uint `js:"proxyPort"`
}

GrpcDisruptionOptions defines options for the injection of grpc faults in a target pod

type GrpcFault added in v0.2.0

type GrpcFault struct {
	// port the disruptions will be applied to
	Port uint
	// Average delay introduced to requests
	AverageDelay time.Duration `js:"averageDelay"`
	// Variation in the delay (with respect of the average delay)
	DelayVariation time.Duration `js:"delayVariation"`
	// Fraction (in the range 0.0 to 1.0) of requests that will return an error
	ErrorRate float32 `js:"errorRate"`
	// Status code to be returned by requests selected to return an error
	StatusCode int32 `js:"statusCode"`
	// Status message to be returned in requests selected to return an error
	StatusMessage string `js:"statusMessage"`
	// List of grpc services to be excluded from disruptions
	Exclude string `js:"exclude"`
}

GrpcFault specifies a fault to be injected in grpc requests

type HTTPDisruptionOptions

type HTTPDisruptionOptions struct {
	// Port used by the agent for listening
	ProxyPort uint `js:"proxyPort"`
}

HTTPDisruptionOptions defines options for the injection of HTTP faults in a target pod

type HTTPFault

type HTTPFault struct {
	// port the disruptions will be applied to
	Port uint
	// Average delay introduced to requests
	AverageDelay time.Duration `js:"averageDelay"`
	// Variation in the delay (with respect of the average delay)
	DelayVariation time.Duration `js:"delayVariation"`
	// Fraction (in the range 0.0 to 1.0) of requests that will return an error
	ErrorRate float32 `js:"errorRate"`
	// Error code to be returned by requests selected in the error rate
	ErrorCode uint `js:"errorCode"`
	// Body to be returned when an error is injected
	ErrorBody string `js:"errorBody"`
	// Comma-separated list of url paths to be excluded from disruptions
	Exclude string
}

HTTPFault specifies a fault to be injected in http requests

type PodAttributes

type PodAttributes struct {
	Labels map[string]string
}

PodAttributes defines the attributes a Pod must match for being selected/excluded

type PodDisruptor

type PodDisruptor interface {
	Disruptor
	ProtocolFaultInjector
}

PodDisruptor defines the types of faults that can be injected in a Pod

func NewPodDisruptor

func NewPodDisruptor(
	ctx context.Context,
	k8s kubernetes.Kubernetes,
	selector PodSelector,
	options PodDisruptorOptions,
) (PodDisruptor, error)

NewPodDisruptor creates a new instance of a PodDisruptor that acts on the pods that match the given PodSelector

type PodDisruptorOptions

type PodDisruptorOptions struct {
	// timeout when waiting agent to be injected in seconds. A zero value forces default.
	// A Negative value forces no waiting.
	InjectTimeout time.Duration `js:"injectTimeout"`
}

PodDisruptorOptions defines options that controls the PodDisruptor's behavior

type PodSelector

type PodSelector struct {
	Namespace string
	// Select Pods that match these PodAttributes
	Select PodAttributes
	// Select Pods that match these PodAttributes
	Exclude PodAttributes
}

PodSelector defines the criteria for selecting a pod for disruption

func (PodSelector) NamespaceOrDefault added in v0.3.8

func (p PodSelector) NamespaceOrDefault() string

NamespaceOrDefault returns the configured namespace for this selector, and the name of the default namespace if it is not configured.

func (PodSelector) String added in v0.3.8

func (p PodSelector) String() string

String returns a human-readable explanation of the pods matched by a PodSelector.

type ProtocolFaultInjector added in v0.3.1

type ProtocolFaultInjector interface {
	// InjectHTTPFault injects faults in the HTTP requests sent to the disruptor's targets
	// for the specified duration
	InjectHTTPFaults(ctx context.Context, fault HTTPFault, duration time.Duration, options HTTPDisruptionOptions) error
	// InjectGrpcFault injects faults in the grpc requests sent to the disruptor's targets
	// for the specified duration
	InjectGrpcFaults(ctx context.Context, fault GrpcFault, duration time.Duration, options GrpcDisruptionOptions) error
}

ProtocolFaultInjector defines the methods for injecting protocol faults

type ServiceDisruptor

type ServiceDisruptor interface {
	Disruptor
	ProtocolFaultInjector
}

ServiceDisruptor defines operations for injecting faults in services

func NewServiceDisruptor

func NewServiceDisruptor(
	ctx context.Context,
	k8s kubernetes.Kubernetes,
	service string,
	namespace string,
	options ServiceDisruptorOptions,
) (ServiceDisruptor, error)

NewServiceDisruptor creates a new instance of a ServiceDisruptor that targets the given service

type ServiceDisruptorOptions

type ServiceDisruptorOptions struct {
	// timeout when waiting agent to be injected (default 30s). A zero value forces default.
	// A Negative value forces no waiting.
	InjectTimeout time.Duration `js:"injectTimeout"`
}

ServiceDisruptorOptions defines options that controls the behavior of the ServiceDisruptor

type VisitCommands added in v0.3.8

type VisitCommands struct {
	// Exec defines the command to be executed
	Exec []string
	// Cleanup defines the command to execute for cleaning up if command execution fails
	Cleanup []string
}

VisitCommands define the commands used for visiting a Pod

Jump to

Keyboard shortcuts

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