k8s

package
v0.0.0-...-7754ea6 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MPL-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckStaticServerConnection

func CheckStaticServerConnection(t *testing.T, options *k8s.KubectlOptions, sourceApp string, expectSuccess bool, failureMessages []string, expectedSuccessOutput string, curlArgs ...string)

CheckStaticServerConnection execs into a pod of sourceApp and runs a curl command with the provided curlArgs. This function assumes that the connection is made to the static-server and expects the output to be "hello world" by default, or expectedSuccessOutput in a case of success. If expectSuccess is true, it will expect connection to succeed, otherwise it will expect failure due to intentions.

func CheckStaticServerConnectionFailing

func CheckStaticServerConnectionFailing(t *testing.T, options *k8s.KubectlOptions, sourceApp string, curlArgs ...string)

CheckStaticServerConnectionFailing is just like CheckStaticServerConnection but it always expects a failing connection with various errors.

func CheckStaticServerConnectionMultipleFailureMessages

func CheckStaticServerConnectionMultipleFailureMessages(t *testing.T, options *k8s.KubectlOptions, sourceApp string, expectSuccess bool, failureMessages []string, expectedSuccessOutput string, curlArgs ...string)

CheckStaticServerConnectionMultipleFailureMessages execs into a pod of sourceApp and runs a curl command with the provided curlArgs. This function assumes that the connection is made to the static-server and expects the output to be "hello world" by default, or expectedSuccessOutput in a case of success. If expectSuccess is true, it will expect connection to succeed, otherwise it will expect failure due to intentions. If multiple failureMessages are provided it will assert on the existence of any of them.

func CheckStaticServerConnectionSuccessful

func CheckStaticServerConnectionSuccessful(t *testing.T, options *k8s.KubectlOptions, sourceApp string, curlArgs ...string)

CheckStaticServerConnectionSuccessful is just like CheckStaticServerConnection but it always expects a successful connection.

func CheckStaticServerConnectionSuccessfulWithMessage

func CheckStaticServerConnectionSuccessfulWithMessage(t *testing.T, options *k8s.KubectlOptions, sourceApp string, message string, curlArgs ...string)

CheckStaticServerConnectionSuccessfulWithMessage is just like CheckStaticServerConnectionSuccessful but it asserts on a non-default expected message.

func CheckStaticServerHTTPConnectionFailing

func CheckStaticServerHTTPConnectionFailing(t *testing.T, options *k8s.KubectlOptions, sourceApp string, curlArgs ...string)

CheckStaticServerHTTPConnectionFailing is just like CheckStaticServerConnectionFailing except with HTTP-based intentions.

func CopySecret

func CopySecret(t *testing.T, sourceContext, destContext environment.TestContext, secretName string)

CopySecret copies a Kubernetes secret from one cluster to another.

func Deploy

func Deploy(t *testing.T, options *k8s.KubectlOptions, noCleanupOnFailure bool, noCleanup bool, debugDirectory string, filepath string)

Deploy creates a Kubernetes deployment by applying configuration stored at filepath, sets up a cleanup function and waits for the deployment to become available.

func DeployJob

func DeployJob(t *testing.T, options *k8s.KubectlOptions, noCleanupOnFailure bool, noCleanup bool, debugDirectory, kustomizeDir string)

func DeployKustomize

func DeployKustomize(t *testing.T, options *k8s.KubectlOptions, noCleanupOnFailure bool, noCleanup bool, debugDirectory string, kustomizeDir string)

DeployKustomize creates a Kubernetes deployment by applying the kustomize directory stored at kustomizeDir, sets up a cleanup function and waits for the deployment to become available.

func IsReady

func IsReady(pod corev1.Pod) bool

IsReady returns true if pod is ready.

func KubectlApply

func KubectlApply(t *testing.T, options *k8s.KubectlOptions, configPath string)

KubectlApply takes a path to a Kubernetes YAML file and applies it to the cluster by running 'kubectl apply -f'. If there's an error applying the file, fail the test.

func KubectlApplyK

func KubectlApplyK(t *testing.T, options *k8s.KubectlOptions, kustomizeDir string)

KubectlApplyK takes a path to a kustomize directory and applies it to the cluster by running 'kubectl apply -k'. If there's an error applying the file, fail the test.

func KubectlDelete

func KubectlDelete(t *testing.T, options *k8s.KubectlOptions, configPath string)

KubectlDelete takes a path to a Kubernetes YAML file and deletes it from the cluster by running 'kubectl delete -f'. If there's an error deleting the file, fail the test.

func KubectlDeleteK

func KubectlDeleteK(t *testing.T, options *k8s.KubectlOptions, kustomizeDir string)

KubectlDeleteK takes a path to a kustomize directory and deletes it from the cluster by running 'kubectl delete -k'. If there's an error deleting the file, fail the test.

func KubectlLabel

func KubectlLabel(t *testing.T, options *k8s.KubectlOptions, objectType string, objectId string, key string, value string)

KubectlLabel takes an object and applies the given label to it. Example: `KubectlLabel(t, options, "node", nodeId, corev1.LabelTopologyRegion, "us-east-1")`.

func KubectlScale

func KubectlScale(t *testing.T, options *k8s.KubectlOptions, deployment string, replicas int)

KubectlScale takes a deployment and scales it to the provided number of replicas.

func KubernetesAPIServerHost

func KubernetesAPIServerHost(t *testing.T, cfg *config.TestConfig, ctx environment.TestContext) string

KubernetesAPIServerHost returns the Kubernetes API server URL depending on test configuration.

func KubernetesAPIServerHostFromOptions

func KubernetesAPIServerHostFromOptions(t *testing.T, options *terratestk8s.KubectlOptions) string

KubernetesAPIServerHostFromOptions returns the Kubernetes API server host from options.

func RunKubectl

func RunKubectl(t *testing.T, options *k8s.KubectlOptions, args ...string)

RunKubectl runs an arbitrary kubectl command provided via args and ignores the output. If there's an error running the command, fail the test.

func RunKubectlAndGetOutputE

func RunKubectlAndGetOutputE(t testutil.TestingTB, options *k8s.KubectlOptions, args ...string) (string, error)

RunKubectlAndGetOutputE runs an arbitrary kubectl command provided via args and returns its output and error.

func RunKubectlAndGetOutputWithLoggerE

func RunKubectlAndGetOutputWithLoggerE(t testutil.TestingTB, options *k8s.KubectlOptions, logger *terratestLogger.Logger, args ...string) (string, error)

RunKubectlAndGetOutputWithLoggerE is the same as RunKubectlAndGetOutputE but it also allows you to provide a custom logger. This is useful if the command output contains sensitive information, for example, when you can pass logger.Discard.

func ServiceHost

func ServiceHost(t *testing.T, cfg *config.TestConfig, ctx environment.TestContext, serviceName string) string

ServiceHost returns a host for a Kubernetes service depending on test configuration.

func WaitForAllPodsToBeReady

func WaitForAllPodsToBeReady(t *testing.T, client kubernetes.Interface, namespace, podLabelSelector string)

WaitForAllPodsToBeReady waits until all pods with the provided podLabelSelector are in the ready status. It checks every 2 second for 20 minutes. If there is at least one container in a pod that isn't ready after that, it fails the test.

func WritePodsDebugInfoIfFailed

func WritePodsDebugInfoIfFailed(t *testing.T, kubectlOptions *k8s.KubectlOptions, debugDirectory, labelSelector string)

WritePodsDebugInfoIfFailed calls kubectl describe and kubectl logs --all-containers on pods filtered by the labelSelector and writes it to the debugDirectory.

Types

This section is empty.

Jump to

Keyboard shortcuts

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