disruptors

package
v0.3.13 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package disruptors implements an API for disrupting targets

Index

Constants

This section is empty.

Variables

View Source
var DefaultTargetPort = intstr.FromInt32(80) //nolint:gochecknoglobals

DefaultTargetPort defines the default value for a target HTTP

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 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 intstr.IntOrString
	// 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 intstr.IntOrString
	// 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 PodAgentVisitor added in v0.3.10

type PodAgentVisitor struct {
	// contains filtered or unexported fields
}

PodAgentVisitor implements PodVisitor, performing actions in a Pod by means of running a PodVisitCommand on the pod.

func NewPodAgentVisitor added in v0.3.10

func NewPodAgentVisitor(
	helper helpers.PodHelper,
	options PodAgentVisitorOptions,
	command PodVisitCommand,
) *PodAgentVisitor

NewPodAgentVisitor creates a new pod visitor

func (*PodAgentVisitor) Visit added in v0.3.10

func (c *PodAgentVisitor) Visit(ctx context.Context, pod corev1.Pod) error

Visit allows executing a different command on each target returned by a visiting function

type PodAgentVisitorOptions added in v0.3.10

type PodAgentVisitorOptions struct {
	// Defines the timeout for injecting the agent
	Timeout time.Duration
}

PodAgentVisitorOptions defines the options for the PodVisitor

type PodAttributes

type PodAttributes struct {
	Labels map[string]string
}

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

type PodController added in v0.3.10

type PodController struct {
	// contains filtered or unexported fields
}

PodController uses a PodVisitor to perform a certain action (Visit) on a list of pods. The PodVisitor is responsible for executing the action in one target pod, while the PorController is responsible for coordinating the action of the PodVisitor on multiple target pods

func NewPodController added in v0.3.10

func NewPodController(targets []corev1.Pod) *PodController

NewPodController creates a new controller for a collection of pods

func (*PodController) Visit added in v0.3.10

func (c *PodController) Visit(ctx context.Context, visitor PodVisitor) error

Visit allows executing a different command on each target returned by a visiting function

type PodDisruptor

type PodDisruptor interface {
	Disruptor
	ProtocolFaultInjector
	PodFaultInjector
}

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

func NewPodDisruptor

func NewPodDisruptor(
	_ context.Context,
	k8s kubernetes.Kubernetes,
	spec PodSelectorSpec,
	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 PodFaultInjector added in v0.3.10

type PodFaultInjector interface {
	// Terminates a set of pods. Returns the list of pods affected. If any of the target pods
	// is not terminated after the timeout defined in the TerminatePodsFault, an error is returned
	TerminatePods(context.Context, PodTerminationFault) ([]string, error)
}

PodFaultInjector defines methods for injecting faults into Pods

type PodGrpcFaultCommand added in v0.3.10

type PodGrpcFaultCommand struct {
	// contains filtered or unexported fields
}

PodGrpcFaultCommand implements the PodVisitCommands interface for injecting GrpcFaults in a Pod

func (PodGrpcFaultCommand) Commands added in v0.3.10

func (c PodGrpcFaultCommand) Commands(pod corev1.Pod) (VisitCommands, error)

Commands return the command for injecting a GrpcFault in a Pod

type PodHTTPFaultCommand added in v0.3.10

type PodHTTPFaultCommand struct {
	// contains filtered or unexported fields
}

PodHTTPFaultCommand implements the PodVisitCommands interface for injecting HttpFaults in a Pod

func (PodHTTPFaultCommand) Commands added in v0.3.10

func (c PodHTTPFaultCommand) Commands(pod corev1.Pod) (VisitCommands, error)

Commands return the command for injecting a HttpFault in a Pod

type PodSelector

type PodSelector struct {
	// contains filtered or unexported fields
}

PodSelector returns the target of a PodSelectorSpec

func NewPodSelector added in v0.3.10

func NewPodSelector(spec PodSelectorSpec, helper helpers.PodHelper) (*PodSelector, error)

NewPodSelector creates a new PodSelector

func (*PodSelector) Targets added in v0.3.10

func (s *PodSelector) Targets(ctx context.Context) ([]corev1.Pod, error)

Targets returns the list of target pods

type PodSelectorSpec added in v0.3.10

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

PodSelectorSpec defines the criteria for selecting a pod for disruption

func (PodSelectorSpec) NamespaceOrDefault added in v0.3.10

func (p PodSelectorSpec) NamespaceOrDefault() string

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

func (PodSelectorSpec) String added in v0.3.10

func (p PodSelectorSpec) String() string

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

type PodTerminationFault added in v0.3.10

type PodTerminationFault struct {
	// Count indicates how many pods to terminate. Can be a number or a percentage or targets
	Count intstr.IntOrString
	// Timeout specifies the maximum time to wait for a pod to terminate
	Timeout time.Duration
}

PodTerminationFault specifies a fault that will terminate a set of pods

type PodTerminationVisitor added in v0.3.10

type PodTerminationVisitor struct {
	// contains filtered or unexported fields
}

PodTerminationVisitor defines a Visitor that terminates its target pod

func (PodTerminationVisitor) Visit added in v0.3.10

Visit executes a Terminate action on the target Pod

type PodVisitCommand added in v0.3.10

type PodVisitCommand interface {
	// Commands defines the command to be executed, and optionally a cleanup command
	Commands(corev1.Pod) (VisitCommands, error)
}

PodVisitCommand is a command that can be run on a given pod. Implementations build the VisitCommands according to properties of the pod where it is going to run

type PodVisitor added in v0.3.10

type PodVisitor interface {
	Visit(context.Context, corev1.Pod) error
}

PodVisitor is the interface implemented by objects that perform actions on a Pod

type PodVisitorFunc added in v0.3.10

type PodVisitorFunc func(context.Context, corev1.Pod) error

PodVisitorFunc defines a function that implements the PodVisitor interface This allows using anonymous functions as pod visitor:

func (PodVisitorFunc) Visit added in v0.3.10

func (f PodVisitorFunc) Visit(ctx context.Context, pod corev1.Pod) error

Visit implements PodVisitor interface's Visit function

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
	PodFaultInjector
}

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 ServicePodSelector added in v0.3.10

type ServicePodSelector struct {
	// contains filtered or unexported fields
}

ServicePodSelector returns the targets of a Service

func NewServicePodSelector added in v0.3.10

func NewServicePodSelector(
	service string,
	namespace string,
	helper helpers.ServiceHelper,
) (*ServicePodSelector, error)

NewServicePodSelector returns a new ServicePodSelector

func (*ServicePodSelector) Targets added in v0.3.10

func (s *ServicePodSelector) Targets(ctx context.Context) ([]corev1.Pod, error)

Targets returns the list of target pods

type VisitCommands added in v0.3.8

type VisitCommands struct {
	Exec    []string
	Cleanup []string
}

VisitCommands contains the commands to be executed when visiting a pod

Jump to

Keyboard shortcuts

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