machine

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2021 License: Apache-2.0 Imports: 20 Imported by: 4

Documentation

Overview

Package machine builds k8s resources for use in integration tests

Index

Constants

View Source
const (
	// DefaultTimeout used to wait for resources
	DefaultTimeout = 300 * time.Second
	// DefaultInterval for polling
	DefaultInterval = 500 * time.Millisecond
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ChanResult

type ChanResult struct {
	Error error
}

ChanResult holds different fields that can be sent through a channel

type Machine

type Machine struct {
	PollTimeout  time.Duration
	PollInterval time.Duration

	Clientset *kubernetes.Clientset
}

Machine produces and destroys resources for tests

func NewMachine

func NewMachine() Machine

NewMachine returns a new machine which creates k8s resources

func (*Machine) CollectJobs

func (m *Machine) CollectJobs(namespace string, labels string, n int) ([]batchv1.Job, error)

CollectJobs waits for n jobs with specified labels. It fails after the timeout.

func (*Machine) CollectSecret

func (m *Machine) CollectSecret(namespace string, name string) (*corev1.Secret, error)

CollectSecret polls until the specified secret can be fetched

func (*Machine) ConfigMapExists

func (m *Machine) ConfigMapExists(namespace string, name string) (bool, error)

ConfigMapExists returns true if the secret by that name exist

func (*Machine) ContainExpectedEvent

func (m *Machine) ContainExpectedEvent(events []corev1.Event, reason string, message string) bool

ContainExpectedEvent return true if events contain target resource event

func (*Machine) ContainJob

func (m *Machine) ContainJob(jobs []batchv1.Job, name string) bool

ContainJob searches job array for a job matching `name`

func (*Machine) CreateConfigMap

func (m *Machine) CreateConfigMap(namespace string, configMap corev1.ConfigMap) (TearDownFunc, error)

CreateConfigMap creates a ConfigMap and returns a function to delete it

func (*Machine) CreateEndpoints

func (m *Machine) CreateEndpoints(namespace string, ep corev1.Endpoints) (TearDownFunc, error)

CreateEndpoints creates an Endpoint in the given namespace

func (*Machine) CreateLabeledNamespace

func (m *Machine) CreateLabeledNamespace(namespace string, labels map[string]string) (TearDownFunc, error)

CreateLabeledNamespace creates a namespace, it doesn't return an error if the namespace exists

func (*Machine) CreateNamespace

func (m *Machine) CreateNamespace(namespace string) (TearDownFunc, error)

CreateNamespace creates a namespace, it doesn't return an error if the namespace exists

func (*Machine) CreatePod

func (m *Machine) CreatePod(namespace string, pod corev1.Pod) (TearDownFunc, error)

CreatePod creates a default pod and returns a function to delete it

func (*Machine) CreateSecret

func (m *Machine) CreateSecret(namespace string, secret corev1.Secret) (TearDownFunc, error)

CreateSecret creates a secret and returns a function to delete it

func (*Machine) CreateService

func (m *Machine) CreateService(namespace string, service corev1.Service) (TearDownFunc, error)

CreateService creates a Service in the given namespace

func (*Machine) DeleteJobs

func (m *Machine) DeleteJobs(namespace string, labels string) (bool, error)

DeleteJobs deletes all the jobs

func (*Machine) DeleteNamespace

func (m *Machine) DeleteNamespace(namespace string) error

DeleteNamespace deletes a namespace, it returns an error if it fails

func (*Machine) DeleteSecrets

func (m *Machine) DeleteSecrets(namespace string) (bool, error)

DeleteSecrets deletes all the secrets

func (*Machine) GetConfigMap

func (m *Machine) GetConfigMap(namespace string, name string) (*corev1.ConfigMap, error)

GetConfigMap gets a ConfigMap by name

func (*Machine) GetEndpoints

func (m *Machine) GetEndpoints(namespace string, name string) (*corev1.Endpoints, error)

GetEndpoints gets target Endpoints

func (*Machine) GetNodes

func (m *Machine) GetNodes() ([]corev1.Node, error)

GetNodes gets nodes

func (*Machine) GetPod

func (m *Machine) GetPod(namespace string, name string) (*corev1.Pod, error)

GetPod returns pod by name

func (*Machine) GetPodContainerLogs

func (m *Machine) GetPodContainerLogs(namespace, podName, containerName string) (string, error)

GetPodContainerLogs gets logs for a specific container in a pd

func (*Machine) GetPodLogs

func (m *Machine) GetPodLogs(namespace, podName string) (string, error)

GetPodLogs gets pod logs

func (*Machine) GetPods

func (m *Machine) GetPods(namespace string, labels string) (*corev1.PodList, error)

GetPods returns all the pods selected by labels

func (*Machine) GetSecret

func (m *Machine) GetSecret(namespace string, name string) (*corev1.Secret, error)

GetSecret fetches the specified secret

func (*Machine) GetService

func (m *Machine) GetService(namespace string, name string) (*corev1.Service, error)

GetService gets target Service

func (*Machine) InitContainerRunning

func (m *Machine) InitContainerRunning(namespace, podName, containerName string) (bool, error)

InitContainerRunning returns true if the pod by that name has a specific init container that is in state running

func (*Machine) JobExists

func (m *Machine) JobExists(namespace string, name string) (bool, error)

JobExists returns true if job with that name exists

func (*Machine) PodContainsLogMsg

func (m *Machine) PodContainsLogMsg(namespace, podName, containerName, msg string) error

PodContainsLogMsg searches pod test logs for at least one occurrence of msg, but it will have a shorter timeout(10secs). This is for tests where one does not expect to see a log.

func (*Machine) PodCount

func (m *Machine) PodCount(namespace string, labels string, match func(corev1.Pod) bool) (int, error)

PodCount returns the number of matching pods

func (*Machine) PodLabeled

func (m *Machine) PodLabeled(namespace string, name string, desiredLabel, desiredValue string) (bool, error)

PodLabeled returns true if the pod is labeled correctly

func (*Machine) PodReady

func (m *Machine) PodReady(namespace string, name string) (bool, error)

PodReady returns true if the pod by that name is ready.

func (*Machine) PodRunning

func (m *Machine) PodRunning(namespace string, name string) (bool, error)

PodRunning returns true if the pod by that name is in state running

func (*Machine) PodsDeleted

func (m *Machine) PodsDeleted(namespace string) (bool, error)

PodsDeleted returns true if the all pods are deleted

func (*Machine) PodsFailing

func (m *Machine) PodsFailing(namespace string, labels string) (bool, error)

PodsFailing returns true if the pod by that name exist and is in a failed state

func (*Machine) PodsRunning

func (m *Machine) PodsRunning(namespace string, labels string) (bool, error)

PodsRunning returns true if all the pods selected by labels are in state running Note that only the first page of pods is considered - don't use this if you have a long pod list that you care about

func (*Machine) SecretExists

func (m *Machine) SecretExists(namespace string, name string) (bool, error)

SecretExists returns true if the secret by that name exist

func (*Machine) SubsetsExist

func (m *Machine) SubsetsExist(namespace string, endpointsName string) (bool, error)

SubsetsExist checks if the subsets of the endpoints exist

func (*Machine) TearDownAll

func (m *Machine) TearDownAll(funcs []TearDownFunc) error

TearDownAll calls all passed in tear down functions in order

func (*Machine) UpdateConfigMap

func (m *Machine) UpdateConfigMap(namespace string, configMap corev1.ConfigMap) (*corev1.ConfigMap, TearDownFunc, error)

UpdateConfigMap updates a ConfigMap and returns a function to delete it

func (*Machine) UpdateEndpoints

func (m *Machine) UpdateEndpoints(namespace string, ep corev1.Endpoints) (*corev1.Endpoints, TearDownFunc, error)

UpdateEndpoints updates an endpoint and returns a function to delete it

func (*Machine) UpdatePod

func (m *Machine) UpdatePod(namespace string, pod corev1.Pod) (*corev1.Pod, TearDownFunc, error)

UpdatePod updates a pod and returns a function to delete it

func (*Machine) UpdateSecret

func (m *Machine) UpdateSecret(namespace string, secret corev1.Secret) (*corev1.Secret, TearDownFunc, error)

UpdateSecret updates a secret and returns a function to delete it

func (*Machine) UpdateService

func (m *Machine) UpdateService(namespace string, svc corev1.Service) (*corev1.Service, TearDownFunc, error)

UpdateService updates a service and returns a function to delete it

func (*Machine) WaitForConfigMap

func (m *Machine) WaitForConfigMap(namespace string, name string) error

WaitForConfigMap blocks until the config map is available. It fails after the timeout.

func (*Machine) WaitForInitContainerRunning

func (m *Machine) WaitForInitContainerRunning(namespace, podName, containerName string) error

WaitForInitContainerRunning blocks until a pod's init container is running. It fails after the timeout.

func (*Machine) WaitForJobDeletion

func (m *Machine) WaitForJobDeletion(namespace string, name string) error

WaitForJobDeletion blocks until the batchv1.Job is deleted

func (*Machine) WaitForJobExists

func (m *Machine) WaitForJobExists(namespace string, labels string) (bool, error)

WaitForJobExists polls until a short timeout is reached or a job is found It returns true only if a job is found

func (*Machine) WaitForJobsDeleted

func (m *Machine) WaitForJobsDeleted(namespace string, labels string) error

WaitForJobsDeleted waits until the jobs no longer exists

func (*Machine) WaitForLogMsg

func (m *Machine) WaitForLogMsg(logs *observer.ObservedLogs, msg string) error

WaitForLogMsg searches zap test logs for at least one occurrence of msg. When using this, tests should use FlushLog() to remove log messages from other tests.

func (*Machine) WaitForPod

func (m *Machine) WaitForPod(namespace string, name string) error

WaitForPod blocks until the pod is running. It fails after the timeout.

func (*Machine) WaitForPodContainerLogMatchRegexp

func (m *Machine) WaitForPodContainerLogMatchRegexp(namespace string, podName string, containerName string, regExp string) error

WaitForPodContainerLogMatchRegexp searches a pod's container test logs for at least one occurrence of Regexp.

func (*Machine) WaitForPodContainerLogMsg

func (m *Machine) WaitForPodContainerLogMsg(namespace, podName, containerName, msg string) error

WaitForPodContainerLogMsg searches pod test logs for at least one occurrence of msg.

func (*Machine) WaitForPodCount added in v0.0.2

func (m *Machine) WaitForPodCount(namespace string, labels string, count int) error

WaitForPodCount blocks until the specified number of pods is running

func (*Machine) WaitForPodFailures

func (m *Machine) WaitForPodFailures(namespace string, labels string) error

WaitForPodFailures blocks until all selected pods are failing. It fails after the timeout.

func (*Machine) WaitForPodLogMatchRegexp

func (m *Machine) WaitForPodLogMatchRegexp(namespace string, podName string, regExp string) error

WaitForPodLogMatchRegexp searches pod test logs for at least one occurrence of Regexp.

func (*Machine) WaitForPodLogMsg

func (m *Machine) WaitForPodLogMsg(namespace string, podName string, msg string) error

WaitForPodLogMsg searches pod test logs for at least one occurrence of msg.

func (*Machine) WaitForPodReady

func (m *Machine) WaitForPodReady(namespace string, name string) error

WaitForPodReady blocks until the pod is ready. It fails after the timeout.

func (*Machine) WaitForPods

func (m *Machine) WaitForPods(namespace string, labels string) error

WaitForPods blocks until all selected pods are running. It fails after the timeout.

func (*Machine) WaitForPodsDelete

func (m *Machine) WaitForPodsDelete(namespace string) error

WaitForPodsDelete blocks until the pod is deleted. It fails after the timeout.

func (*Machine) WaitForPortReachable

func (m *Machine) WaitForPortReachable(protocol, uri string) error

WaitForPortReachable blocks until the endpoint is reachable

func (*Machine) WaitForSecret

func (m *Machine) WaitForSecret(namespace string, name string) error

WaitForSecret blocks until the secret is available. It fails after the timeout.

func (*Machine) WaitForSecretChange

func (m *Machine) WaitForSecretChange(namespace string, name string, changed SecretChangedFunc) error

WaitForSecretChange blocks until the secret fulfills the change func

func (*Machine) WaitForSecretDeletion

func (m *Machine) WaitForSecretDeletion(namespace string, name string) error

WaitForSecretDeletion blocks until the resource is deleted

func (*Machine) WaitForServiceAccount added in v0.0.2

func (m *Machine) WaitForServiceAccount(namespace string, name string) error

WaitForServiceAccount blocks until the service account exists

func (*Machine) WaitForSubsetsExist

func (m *Machine) WaitForSubsetsExist(namespace string, endpointsName string) error

WaitForSubsetsExist blocks until the specified endpoints' subsets exist

type SecretChangedFunc

type SecretChangedFunc func(corev1.Secret) bool

SecretChangedFunc returns true if something changed in the secret

type TearDownFunc

type TearDownFunc func() error

TearDownFunc tears down the resource

Jump to

Keyboard shortcuts

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