utils

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2020 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// The chaos just started
	EventChaosInjected string = "ChaosInjected"

	// The chaos just failed when injecting. The message should include detailed error
	EventChaosInjectFailed string = "ChaosInjectFailed"

	// The chaos just failed when recovering. The message should include detailed error
	EventChaosRecoverFailed string = "ChaosRecoverFailed"

	// The chaos just completed
	EventChaosRecovered string = "ChaosRecovered"
)

For each chaos resource, the controller manager will record events once the chaos is started or completed or failed. The starting and completing events should be of type "Normal". And the failed events should be of type "Warning". The reasons are defined as following.

View Source
const (
	// AnnotationPrefix defines the prefix of annotation key for chaos-mesh.
	AnnotationPrefix = "chaos-mesh"
)
View Source
const DefaultRPCTimeout = 60 * time.Second

DefaultRPCTimeout specifies default timeout of RPC between controller and chaos-operator

Variables

View Source
var RPCTimeout = DefaultRPCTimeout

RPCTimeout specifies timeout of RPC between controller and chaos-operator

Functions

func CheckPodMeetSelector

func CheckPodMeetSelector(pod v1.Pod, selector v1alpha1.SelectorSpec) (bool, error)

CheckPodMeetSelector checks if this pod meets the selection criteria. TODO: support to check fieldsSelector

func Coalescer

func Coalescer(interval time.Duration, input chan interface{}, stopCh <-chan struct{}) <-chan interface{}

Coalescer takes an input channel, and coalesced inputs with a timebound of interval. If input channel is closed, coalescer will signal one last time if we have any pending unsignalled events and close the output channel.

func CreateGrpcConnection

func CreateGrpcConnection(ctx context.Context, c client.Client, pod *v1.Pod, port int) (*grpc.ClientConn, error)

CreateGrpcConnection create a grpc connection with given port

func EncodeClkIds

func EncodeClkIds(clkIds []string) (uint64, error)

EncodeClkIds will convert array of clk ids into a mask

func GenAnnotationKeyForImage

func GenAnnotationKeyForImage(pc *v1alpha1.PodChaos, containerName string) string

func GenAnnotationKeyForWebhook

func GenAnnotationKeyForWebhook(prefix string, podName string) string

func IgnoreNotFound

func IgnoreNotFound(err error) error

func InsertFinalizer

func InsertFinalizer(finalizers []string, finalizer string) []string

func IsAllowedNamespaces

func IsAllowedNamespaces(namespace string) bool

IsAllowedNamespaces returns whether namespace allows the execution of a chaos task

func IsCaredNetError

func IsCaredNetError(err error) bool

func MergeCommands

func MergeCommands(inject []string, origin []string, args []string) []string

MergeCommands merges injected commands and original commands for injecting commands to containers, eg: inject: []string{"bash", "-c", "/check.sh"}, origin: []string{"bash", "-c", "/run.sh"} merged commands: []string{"/bin/sh", "-ec", "/check.sh\n/run.sh"}

func MergeNetem

func MergeNetem(a, b *chaosdaemon.Netem) *chaosdaemon.Netem

MergeNetem merges two Netem protos into a new one. REMEMBER to assign the return value, i.e. merged = utils.MergeNetm(merged, em) For each field it takes the bigger value of the two. Its main use case is merging netem of different types, e.g. delay and loss. It returns nil if both inputs are nil. Otherwise it returns a new Netem with merged values.

func NextTime

func NextTime(spec v1alpha1.SchedulerSpec, now time.Time, firstTime bool) (*time.Time, error)

func RandomFixedIndexes

func RandomFixedIndexes(start, end, count uint) []uint

RandomFixedIndexes returns the `count` random indexes between `start` and `end`. [start, end)

func RemoveFromFinalizer

func RemoveFromFinalizer(finalizers []string, key string) []string

func SelectAndFilterPods

func SelectAndFilterPods(ctx context.Context, c client.Client, r client.Reader, spec SelectSpec) ([]v1.Pod, error)

SelectAndFilterPods returns the list of pods that filtered by selector and PodMode

func SelectPods

func SelectPods(ctx context.Context, c client.Client, r client.Reader, selector v1alpha1.SelectorSpec) ([]v1.Pod, error)

SelectPods returns the list of pods that are available for pod chaos action. It returns all pods that match the configured label, annotation and namespace selectors. If pods are specifically specified by `selector.Pods`, it just returns the selector.Pods.

func TimeoutClientInterceptor

func TimeoutClientInterceptor(ctx context.Context, method string, req, reply interface{},
	cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error

TimeoutClientInterceptor wraps the RPC with a timeout.

func TimeoutServerInterceptor

func TimeoutServerInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler) (interface{}, error)

TimeoutServerInterceptor ensures the context is intact before handling over the request to application.

Types

type ChaosDaemonClientInterface

type ChaosDaemonClientInterface interface {
	chaosdaemon.ChaosDaemonClient
	Close() error
}

ChaosDaemonClientInterface represents the ChaosDaemonClient, it's used to simply unit test

func NewChaosDaemonClient

func NewChaosDaemonClient(ctx context.Context, c client.Client, pod *v1.Pod, port int) (ChaosDaemonClientInterface, error)

NewChaosDaemonClient would create ChaosDaemonClient

type Edge

type Edge struct {
	Source uint32
	Target uint32
	Next   *Edge
}

Edge represents an edge in graph

type Graph

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

Graph represents a graph with link list

func NewGraph

func NewGraph() *Graph

NewGraph creates a Graph

func (*Graph) Flatten

func (g *Graph) Flatten(source uint32) []uint32

Flatten flattens the subtree from source (without checking whether it's a tree)

func (*Graph) Insert

func (g *Graph) Insert(source uint32, target uint32)

Insert inserts an Edge into a graph from source to target

func (*Graph) IterFrom

func (g *Graph) IterFrom(source uint32) *Edge

IterFrom starts iterating from source node

type GrpcChaosDaemonClient

type GrpcChaosDaemonClient struct {
	chaosdaemon.ChaosDaemonClient
	// contains filtered or unexported fields
}

GrpcChaosDaemonClient would act like chaosdaemon.ChaosDaemonClient with a Close method

func (*GrpcChaosDaemonClient) Close

func (c *GrpcChaosDaemonClient) Close() error

type SelectSpec

type SelectSpec interface {
	GetSelector() v1alpha1.SelectorSpec
	GetMode() v1alpha1.PodMode
	GetValue() string
}

Jump to

Keyboard shortcuts

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