utils

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExitSuccess = iota
	ExitError
	ExitBadConnection
	ExitInterrupted
	ExitIO
	ExitBadArgs = 128
)

http://tldp.org/LDP/abs/html/exitcodes.html

View Source
const DefaultRPCTimeout = 60 * time.Second

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

Variables

View Source
var PrintFxLog bool
View Source
var RPCTimeout = DefaultRPCTimeout

RPCTimeout specifies timeout of RPC between controller and chaos-operator

Functions

func CheckIPProtocols

func CheckIPProtocols(p string) bool

func CheckIPs

func CheckIPs(i string) bool

func CheckPercent

func CheckPercent(p string) bool

func CheckPorts

func CheckPorts(p string) bool

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 CreateTempFile added in v1.0.0

func CreateTempFile(path string) (string, error)

CreateTempFile will create a temp file in current directory.

func EncodeClkIds

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

EncodeClkIds will convert array of clk ids into a mask

func ExecuteCmd added in v1.2.0

func ExecuteCmd(cmdStr string) (string, error)

func ExitWithError added in v1.0.0

func ExitWithError(code int, err error)

ExitWithError exits with error

func ExitWithMsg added in v1.0.0

func ExitWithMsg(code int, msg string)

ExitWithMsg exits with error message

func FxNewAppWithoutLog added in v1.0.0

func FxNewAppWithoutLog(opts ...fx.Option) *fx.App

FxNewAppWithoutLog returns fx App without log

func GetDiskTotalSize added in v1.0.0

func GetDiskTotalSize(path string) (total uint64, err error)

GetDiskTotalSize returns the total bytes in disk

func GetProgramPath

func GetProgramPath() string

GetProgramPath returns the path of the program

func GetRootDevice added in v1.0.0

func GetRootDevice() (string, error)

GetRootDevice returns the device which "/" mount on.

func IPToCidr

func IPToCidr(ip string) string

IPToCidr converts from an ip to a full mask cidr

func NormalExit added in v1.0.0

func NormalExit(msg string)

NormalExit exits normally

func ParseUnit added in v1.0.0

func ParseUnit(s string) (uint64, error)

ParseUnit parse a digit with unit such as "K" , "KiB", "KB", "c", "MiB", "MB", "M". If input string is a digit without unit , it will be regarded as a digit with unit M(1024*1024 bytes).

func RandomStringWithCharset added in v1.0.0

func RandomStringWithCharset(length int) string

func RemoveDuplicateElement

func RemoveDuplicateElement(languages []string) []string

func ResolveCidr

func ResolveCidr(name string) ([]string, error)

ResolveCidr converts cidr/ip/domain into cidr

func ResolveCidrs

func ResolveCidrs(names []string) ([]string, error)

ResolveCidrs converts multiple cidrs/ips/domains into cidr

func SetRuntimeEnv added in v1.0.0

func SetRuntimeEnv() error

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 Command added in v1.0.2

type Command struct {
	Name string
}

func (Command) GetCmdArgs added in v1.4.0

func (c Command) GetCmdArgs(val interface{}) (string, []string)

func (Command) Unmarshal added in v1.0.2

func (c Command) Unmarshal(val interface{}) *exec.Cmd

func (Command) UnmarshalWithCtx added in v1.4.0

func (c Command) UnmarshalWithCtx(ctx context.Context, val interface{}) *exec.Cmd

type CommandPools added in v1.4.0

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

CommandPools is a group of commands runner

func NewCommandPools added in v1.4.0

func NewCommandPools(ctx context.Context, deadline *time.Time, size int) *CommandPools

NewCommandPools returns a new CommandPools

func (*CommandPools) Close added in v1.4.0

func (p *CommandPools) Close()

func (*CommandPools) Process added in v1.4.0

func (p *CommandPools) Process(name string, args []string) ([]byte, error)

func (*CommandPools) Start added in v1.4.0

func (p *CommandPools) Start(runner *CommandRunner)

Start command async.

func (*CommandPools) Wait added in v1.4.0

func (p *CommandPools) Wait()

type CommandRunner added in v1.4.0

type CommandRunner struct {
	Name string
	Args []string
	// contains filtered or unexported fields
}

func NewCommandRunner added in v1.4.0

func NewCommandRunner(name string, args []string) *CommandRunner

func (*CommandRunner) WithOutputHandler added in v1.4.0

func (r *CommandRunner) WithOutputHandler(
	handler func([]byte, error, chan interface{}),
	outputChanel chan interface{},
) *CommandRunner

type DdArgBlock added in v1.0.0

type DdArgBlock struct {
	BlockSize string
	Count     string
}

DdArgBlock is command arg for dd. BlockSize is bs.Count is count.

func SplitBytesByProcessNum added in v1.0.0

func SplitBytesByProcessNum(bytes uint64, processNum uint8) ([]DdArgBlock, error)

This func split bytes in to processNum + 1 dd arg blocks. Every ddArgBlock can generate one dd command. If bytes is bigger than processNum M , bytes will be split into processNum dd commands with bs = 1M ,count = bytes/ processNum M. If bytes is not bigger than processNum M , bytes will be split into processNum dd commands with bs = bytes / uint64(processNum) ,count = 1. And one ddArgBlock stand by the rest bytes will also add to the end of slice, even if rest bytes = 0.

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

Jump to

Keyboard shortcuts

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