util

package
v0.0.0-...-730bba4 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2018 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	IstioTop = os.Getenv("TOP")
	IstioSrc = os.Getenv("ISTIO_GO")
	IstioBin = os.Getenv("ISTIO_BIN")
	IstioOut = os.Getenv("ISTIO_OUT")

	// EnvoyOutWriter captures envoy output
	// Redirect out and err from envoy to buffer - coverage tests get confused if we write to out.
	// TODO: use files
	EnvoyOutWriter bytes.Buffer

	// EnvoyErrWriter captures envoy errors
	EnvoyErrWriter bytes.Buffer
)

Extracted from watcher_test, will run envoy

View Source
var (
	// MockTestServer is used for the unit tests. Will be started once, terminated at the
	// end of the suite.
	MockTestServer *bootstrap.Server

	// MockPilotURL is the URL for the pilot http endpoint
	MockPilotURL string

	// MockPilotGrpcAddr is the address to be used for grpc connections.
	MockPilotGrpcAddr string
)

Functions

func Backoff

func Backoff(baseDelay, maxDelay time.Duration, retries int) time.Duration

Backoff returns a random value in [0, maxDelay] that increases exponentially with retries, starting from baseDelay. It is the Go equivalent to C++'s //util/time/backoff.cc.

func CheckDeployment

func CheckDeployment(ctx context.Context, namespace, deployment string) error

CheckDeployment gets status of a deployment from a namespace

func CheckDeployments

func CheckDeployments(namespace string, timeout time.Duration) error

CheckDeployments checks whether all deployment in a given namespace

func CheckPodsRunning

func CheckPodsRunning(n string) (ready bool)

CheckPodsRunning return if all pods in a namespace are in "Running" status Also check container status to be running.

func Compare

func Compare(out, model []byte) error

Compare compares two byte slices. It returns an error with a contextual diff if they are not equal.

func CompareFiles

func CompareFiles(outFile, modelFile string) error

CompareFiles compares the content of two files

func CompareToFile

func CompareToFile(out []byte, modelFile string) error

CompareToFile compares a content with a file

func CopyFile

func CopyFile(src, dst string) error

CopyFile create a new file to src based on dst

func CreateNamespace

func CreateNamespace(n string) error

CreateNamespace create a kubernetes namespace

func CreateTempfile

func CreateTempfile(tmpDir, prefix, suffix string) (string, error)

CreateTempfile creates a tempfile string.

func DeleteNamespace

func DeleteNamespace(n string) error

DeleteNamespace delete a kubernetes namespace

func DownloadRelease

func DownloadRelease(version, tmpDir string) (string, error)

DownloadRelease gets the specified release from istio repo to tmpDir.

func EnsureTestServer

func EnsureTestServer() *bootstrap.Server

EnsureTestServer will ensure a pilot server is running in process and initializes the MockPilotUrl and MockPilotGrpcAddr to allow connections to the test pilot.

func ExtractTarGz

func ExtractTarGz(gzipStream io.Reader) error

ExtractTarGz extracts a .tar.gz file into current dir.

func FetchAndSaveClusterLogs

func FetchAndSaveClusterLogs(namespace string, tempDir string) error

FetchAndSaveClusterLogs will dump the logs for a cluster.

func Fill

func Fill(outFile, inFile string, values interface{}) error

Fill complete a template with given values and generate a new output file

func GetHeadCommitSHA

func GetHeadCommitSHA(org, repo, branch string) (string, error)

GetHeadCommitSHA finds the SHA of the commit to which the HEAD of branch points

func GetIngress

func GetIngress(n string) (string, error)

GetIngress get istio ingress ip

func GetIngressPod

func GetIngressPod(n string) (string, error)

GetIngressPod get istio ingress ip

func GetOsExt

func GetOsExt() (string, error)

GetOsExt returns the current OS tag.

func GetPodStatus

func GetPodStatus(n, pod string) string

GetPodStatus gets status of a pod from a namespace Note: It is not enough to check pod phase, which only implies there is at least one container running. Use kubectl CLI to get status so that we can ensure that all containers are running.

func GetPodsName

func GetPodsName(n string) (pods []string)

GetPodsName gets names of all pods in specific namespace and return in a slice

func GetResourcePath

func GetResourcePath(p string) string

GetResourcePath give "path from WORKSPACE", return absolute path at runtime

func GitRootDir

func GitRootDir() (string, error)

GitRootDir returns the absolute path to the root directory of the git repo where this function is called

func HTTPDownload

func HTTPDownload(dst string, src string) error

HTTPDownload download from src(url) and store into dst(local file)

func IsProcessRunning

func IsProcessRunning(p *os.Process) (bool, error)

IsProcessRunning check if a os.Process is running

func IsProcessRunningInt

func IsProcessRunningInt(pid int) (bool, error)

IsProcessRunningInt check if a process of the given pid(int) is running

func IsProcessRunningString

func IsProcessRunningString(pidS string) (bool, error)

IsProcessRunningString check if a process of the given pid(string) is running

func KillProcess

func KillProcess(p *os.Process) (err error)

KillProcess kill a os.Process

func KubeApply

func KubeApply(namespace, yamlFileName string) error

KubeApply kubectl apply from file

func KubeApplyContents

func KubeApplyContents(namespace, yamlContents string) error

KubeApplyContents kubectl apply from contents

func KubeDelete

func KubeDelete(namespace, yamlFileName string) error

KubeDelete kubectl delete from file

func KubeDeleteContents

func KubeDeleteContents(namespace, yamlContents string) error

KubeDeleteContents kubectl apply from contents

func NamespaceDeleted

func NamespaceDeleted(n string) (bool, error)

NamespaceDeleted check if a kubernete namespace is deleted

func Poll

func Poll(interval time.Duration, numTrials int, do func() (bool, error)) error

Poll executes do() after time interval for a max of numTrials times. The bool returned by do() indicates if polling succeeds in that trial

func Record

func Record(command, record string) error

Record run command and record output into a file

func RunBackground

func RunBackground(format string, args ...interface{}) (*os.Process, error)

RunBackground starts a background process and return the Process if succeed

func RunEnvoy

func RunEnvoy(base string, template string) error

RunEnvoy runs an envoy process. Base is the basename for the generate envoy.json, template is the template to be used to run envoy.

func Shell

func Shell(format string, args ...interface{}) (string, error)

Shell run command on shell and get back output and error if get one

func ShellContext

func ShellContext(ctx context.Context, format string, args ...interface{}) (string, error)

ShellContext run command on shell and get back output and error if get one

func ShellMuteOutput

func ShellMuteOutput(format string, args ...interface{}) (string, error)

ShellMuteOutput run command on shell and get back output and error if get one without logging the output

func ShellSilent

func ShellSilent(format string, args ...interface{}) (string, error)

ShellSilent runs command on shell and get back output and error if get one without logging the command or output.

func Teardown

func Teardown()

Teardown will cleanup the temp dir and remove the test data.

func WriteTempfile

func WriteTempfile(tmpDir, prefix, suffix, contents string) (string, error)

WriteTempfile creates a tempfile with the specified contents.

func WriteTextFile

func WriteTextFile(filePath, content string) error

WriteTextFile overwrites the file on the given path with content

Types

type Break

type Break struct {
	Err error
}

Break the retry loop if the error returned is of this type.

func (Break) Error

func (e Break) Error() string

type Retrier

type Retrier struct {
	// BaseDelay is the minimum delay between retry attempts.
	BaseDelay time.Duration
	// MaxDelay is the maximum delay allowed between retry attempts.
	MaxDelay time.Duration
	// MaxDuration is the maximum cumulative duration allowed for all retries
	MaxDuration time.Duration
	// Retries defines number of retry attempts
	Retries int
}

Retrier contains the retry configuration parameters.

func (Retrier) Retry

func (r Retrier) Retry(ctx context.Context, fn func(ctx context.Context, retryIndex int) error) (int, error)

Retry calls the given function a number of times, unless it returns a nil or a Break

Jump to

Keyboard shortcuts

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