istio: Index | Files

package util

import ""


Package Files

common_utils.go compare_utils.go echo.go helm_utils.go kube_utils.go pilot_server.go process_utils.go retry.go


const (

    // NodePortServiceType NodePort type of Kubernetes Service
    NodePortServiceType = "NodePort"

    // LoadBalancerServiceType LoadBalancer type of Kubernetes Service
    LoadBalancerServiceType = "LoadBalancer"


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

    // MockPilotSecureAddr is the address to be used for secure grpc connections.
    MockPilotSecureAddr string

    // MockPilotHTTPPort is the dynamic port for pilot http
    MockPilotHTTPPort int

    // MockPilotGrpcPort is the dynamic port for pilot grpc
    MockPilotGrpcPort int

func Backoff Uses

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/

func CheckAppDeployment Uses

func CheckAppDeployment(namespace, deployment string, timeout time.Duration, kubeconfig string) error

CheckAppDeployment checks whether or not an app in a namespace is ready

func CheckDeployment Uses

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

CheckDeployment gets status of a deployment from a namespace

func CheckDeploymentRemoved Uses

func CheckDeploymentRemoved(namespace, deployment string, kubeconfig string) error

CheckDeploymentRemoved waits until a deployment is removed or times out

func CheckDeployments Uses

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

CheckDeployments checks whether all deployments in a given namespace are ready

func CheckDeploymentsReady Uses

func CheckDeploymentsReady(ns string, kubeconfig string) (int, error)

CheckDeploymentsReady checks if deployment resources are ready. get podsReady() sometimes gets pods created by the "Job" resource which never reach the "Running" steady state.

func CheckPodRunning Uses

func CheckPodRunning(n, name string, kubeconfig string) error

CheckPodRunning return if a given pod with labeled name in a namespace are in "Running" status

func CheckPodsRunning Uses

func CheckPodsRunning(n string, kubeconfig string) (ready bool)

CheckPodsRunning returns readiness of all pods within a namespace. It will wait for upto 2 mins. use WithMaxDuration to specify a duration.

func CheckPodsRunningWithMaxDuration Uses

func CheckPodsRunningWithMaxDuration(n string, maxDuration time.Duration, kubeconfig string) (ready bool)

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

func Compare Uses

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 Uses

func CompareFiles(outFile, modelFile string) error

CompareFiles compares the content of two files

func CompareToFile Uses

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

CompareToFile compares a content with a file

func CopyFile Uses

func CopyFile(src, dst string) error

CopyFile create a new file to src based on dst

func CreateAndFill Uses

func CreateAndFill(outDir, templateFile string, values interface{}) (string, error)

CreateAndFill fills in the given yaml template with the values and generates a temp file for the completed yaml.

func CreateMultiClusterSecret Uses

func CreateMultiClusterSecret(namespace string, remoteKubeConfig string, localKubeConfig string) error

CreateMultiClusterSecret will create the secret associated with the remote cluster

func CreateNamespace Uses

func CreateNamespace(n string, kubeconfig string) error

CreateNamespace create a kubernetes namespace

func CreateTLSSecret Uses

func CreateTLSSecret(secretName, n, keyFile, certFile string, kubeconfig string) (string, error)

CreateTLSSecret creates a secret from the provided cert and key files

func CreateTempfile Uses

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

CreateTempfile creates a tempfile string.

func DeleteDeployment Uses

func DeleteDeployment(d string, n string, kubeconfig string) error

DeleteDeployment deletes deployment from the specified namespace

func DeleteMultiClusterSecret Uses

func DeleteMultiClusterSecret(namespace string, remoteKubeConfig string, localKubeConfig string) error

DeleteMultiClusterSecret delete the remote cluster secret

func DeleteNamespace Uses

func DeleteNamespace(n string, kubeconfig string) error

DeleteNamespace delete a kubernetes namespace

func DownloadRelease Uses

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

DownloadRelease gets the specified release from istio repo to tmpDir.

func FetchAndSaveClusterLogs Uses

func FetchAndSaveClusterLogs(namespace string, tempDir string, kubeconfig string) error

FetchAndSaveClusterLogs will dump the logs for a cluster.

func Fill Uses

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

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

func GetAppPods Uses

func GetAppPods(n string, kubeconfig string) (map[string][]string, error)

GetAppPods gets a map of app names to the pods for the app, for the given namespace

func GetAppPodsInfo Uses

func GetAppPodsInfo(n string, kubeconfig string, label string) ([]string, map[string][]string, error)

GetAppPodsInfo returns a map of a list of PodInfo

func GetClusterSubnet Uses

func GetClusterSubnet(kubeconfig string) (string, error)

GetClusterSubnet returns the subnet (in CIDR form, e.g. "24") for the nodes in the cluster.

func GetConfigs Uses

func GetConfigs(kubeconfig string, names ...string) (string, error)

GetConfigs retrieves the configurations for the list of resources.

func GetHeadCommitSHA Uses

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

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

func GetIngress Uses

func GetIngress(serviceName, podLabel, namespace, kubeconfig string, serviceType string, sanityCheck bool) (string, error)

GetIngress get istio ingress ip and port. Could relate to either Istio Ingress or to Istio Ingress Gateway, by serviceName and podLabel. Handles two cases: when the Ingress/Ingress Gateway Kubernetes Service is a LoadBalancer or NodePort (for tests within the cluster, including for minikube)

func GetIngressPodNames Uses

func GetIngressPodNames(n string, kubeconfig string) ([]string, error)

GetIngressPodNames get the pod names for the Istio ingress deployment.

func GetKubeConfig Uses

func GetKubeConfig(filename string) error

GetKubeConfig will create a kubeconfig file based on the active environment the test is run in

func GetKubeMasterIP Uses

func GetKubeMasterIP(kubeconfig string) (string, error)

GetKubeMasterIP returns the IP address of the kubernetes master service.

func GetOsExt Uses

func GetOsExt() (string, error)

GetOsExt returns the current OS tag.

func GetPodLabelValues Uses

func GetPodLabelValues(n, label string, kubeconfig string) (map[string]string, error)

GetPodLabelValues gets a map of pod name to label value for the given label and namespace

func GetPodLogs Uses

func GetPodLogs(n, pod, container string, tail, alsoShowPreviousPodLogs bool, kubeconfig string) string

GetPodLogs retrieves the logs for the given namespace, pod and container.

func GetPodLogsForLabel Uses

func GetPodLogsForLabel(n, labelSelector string, container string, tail, alsoShowPreviousPodLogs bool, kubeconfig string) string

GetPodLogsForLabel gets the logs for the given label selector and container

func GetPodName Uses

func GetPodName(n, labelSelector string, kubeconfig string) (pod string, err error)

GetPodName gets the pod name for the given namespace and label selector

func GetPodNames Uses

func GetPodNames(n string) (pods []string, kubeconfig string)

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

func GetPodStatus Uses

func GetPodStatus(n, pod string, kubeconfig 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 GetResourcePath Uses

func GetResourcePath(p string) string

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

func GitRootDir Uses

func GitRootDir() (string, error)

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

func HelmClientInit Uses

func HelmClientInit() error

HelmClientInit initializes the Helm client only

func HelmDelete Uses

func HelmDelete(chartName string) error

HelmDelete helm del --purge a chart

func HelmFetch Uses

func HelmFetch(chartRepo, chartDir string) error

HelmFetch will fetch the charts from the provided repo. It is assumed the repo itself has already been added.

func HelmInit Uses

func HelmInit(serviceAccount string) error

HelmInit init helm with a service account

func HelmInstall Uses

func HelmInstall(chartDir, chartName, valueFile, namespace, setValue string) error

HelmInstall helm install from a chart for a given namespace

--set stringArray        set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)

func HelmInstallDryRun Uses

func HelmInstallDryRun(chartDir, chartName, valueFile, namespace, setValue string) error

HelmInstallDryRun helm install dry run from a chart for a given namespace

func HelmParams Uses

func HelmParams(chartDir, chartName, valueFile, namespace, setValue string) string

HelmParams provides a way to construct helm params

func HelmTemplate Uses

func HelmTemplate(chartDir, chartName, namespace, setValue, outfile string) error

HelmTemplate helm template from a chart for a given namespace

--set stringArray        set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)

func HelmTest Uses

func HelmTest(releaseName string) error

HelmTest helm test a chart release

func HelmTillerRunning Uses

func HelmTillerRunning() error

HelmTillerRunning will block for up to 120 seconds waiting for Tiller readiness

func IsJobSucceeded Uses

func IsJobSucceeded(n, name string, kubeconfig string) (bool, error)

IsJobSucceeded checks whether a job for the given namespace succeeded

func IsProcessRunning Uses

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

IsProcessRunning check if a os.Process is running

func IsProcessRunningInt Uses

func IsProcessRunningInt(pid int) (bool, error)

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

func IsProcessRunningString Uses

func IsProcessRunningString(pidS string) (bool, error)

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

func KillProcess Uses

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

KillProcess kill a os.Process

func KubeApply Uses

func KubeApply(namespace, yamlFileName string, kubeconfig string) error

KubeApply kubectl apply from file

func KubeApplyContentSilent Uses

func KubeApplyContentSilent(namespace, yamlContents string, kubeconfig string) error

KubeApplyContentSilent kubectl apply from contents silently

func KubeApplyContents Uses

func KubeApplyContents(namespace, yamlContents string, kubeconfig string) error

KubeApplyContents kubectl apply from contents

func KubeApplySilent Uses

func KubeApplySilent(namespace, yamlFileName string, kubeconfig string) error

KubeApplySilent kubectl apply from file silently

func KubeCommand Uses

func KubeCommand(command, namespace, yamlFileName string, kubeconfig string) error

KubeCommand executes the given kubectl command with the given yaml file

func KubeDelete Uses

func KubeDelete(namespace, yamlFileName string, kubeconfig string) error

KubeDelete kubectl delete from file

func KubeDeleteContents Uses

func KubeDeleteContents(namespace, yamlContents string, kubeconfig string) error

KubeDeleteContents kubectl apply from contents

func KubeGetYaml Uses

func KubeGetYaml(namespace, resource, name string, kubeconfig string) (string, error)

KubeGetYaml kubectl get yaml content for given resource.

func KubeScale Uses

func KubeScale(namespace, typeName string, replicaCount int, kubeconfig string) error

KubeScale kubectl scale a pod specified using typeName

func LabelNamespace Uses

func LabelNamespace(n, label, kubeconfig string) error

LabelNamespace will add a label to the kubernetes namespace

func NamespaceDeleted Uses

func NamespaceDeleted(n string, kubeconfig string) (bool, error)

NamespaceDeleted check if a kubernete namespace is deleted

func PodExec Uses

func PodExec(n, pod, container, command string, muteOutput bool, kubeconfig string) (string, error)

PodExec runs the specified command on the container for the specified namespace and pod

func Poll Uses

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 RandomString Uses

func RandomString(n int) string

RandomString returns a random string of size n (letters only)

func Record Uses

func Record(command, record string) error

Record run command and record output into a file

func ReplaceInConfigMap Uses

func ReplaceInConfigMap(namespace string, configmapName string, sedExpression string, kubeconfig string) error

ReplaceInConfigMap will modify an existing configmap with the provided sed expression

func RunBackground Uses

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

RunBackground starts a background process and return the Process if succeed

func RunGRPC Uses

func RunGRPC(port int, version, crt, key string)

RunGRPC runs the GRPC service, with optional TLS

func RunHTTP Uses

func RunHTTP(port int, version string)

RunHTTP runs the http echo service.

func Shell Uses

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

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

func ShellContext Uses

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 Uses

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 ShellMuteOutputError Uses

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

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

func ShellSilent Uses

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 ValidatingWebhookConfigurationExists Uses

func ValidatingWebhookConfigurationExists(name string, kubeconfig string) bool

ValidatingWebhookConfigurationExists check if a kubernetes ValidatingWebhookConfiguration is deleted

func WaitForDeploymentsReady Uses

func WaitForDeploymentsReady(ns string, timeout time.Duration, kubeconfig string) error

WaitForDeploymentsReady wait up to 'timeout' duration return an error if deployments are not ready

func WriteTempfile Uses

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

WriteTempfile creates a tempfile with the specified contents.

func WriteTextFile Uses

func WriteTextFile(filePath, content string) error

WriteTextFile overwrites the file on the given path with content

type Break Uses

type Break struct {
    Err error

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

func (Break) Error Uses

func (e Break) Error() string

type EchoClient Uses

type EchoClient struct {
    // contains filtered or unexported fields

EchoClient controls the client

type PodInfo Uses

type PodInfo struct {
    // Name is the pod's name
    Name string
    // IPAddr is the pod's IP
    IPAddr string

PodInfo contains pod's information such as name and IP address

type Retrier Uses

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 Uses

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

type TearDownFunc Uses

type TearDownFunc func()

TearDownFunc is to be called to tear down a test server.

func EnsureTestServer Uses

func EnsureTestServer(args ...func(*bootstrap.PilotArgs)) (*bootstrap.Server, TearDownFunc)

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

Package util imports 45 packages (graph) and is imported by 3 packages. Updated 2019-10-17. Refresh now. Tools for package owners.