Documentation
¶
Overview ¶
package client provides a client for tests.
This Client can operate on any k8s resource struct type, core or custom, via the runtime.Object interface. As well as the usual Create, Get, Update, Delete it supports Watch and provides some convenience methods for tests.
Most tests should use the singleton client returned by Get(). Avoiding creation of multiple clients saves significant time in a test suite.
Index ¶
- Constants
- Variables
- func Deleted(e watch.Event) (bool, error)
- func IgnoreAlreadyExists(err error) error
- func IgnoreNotFound(err error) error
- func IsDaemonSetReady(e watch.Event) (bool, error)
- func PodFailed(e watch.Event) (bool, error)
- func PodRunning(e watch.Event) (bool, error)
- func PodSucceeded(e watch.Event) (bool, error)
- func RouteReady(e watch.Event) (bool, error)
- type Client
- func (c *Client) Cfg() *rest.Config
- func (c *Client) ContainerLogStream(namespace, podName, containerName string, follow bool) (io.ReadCloser, error)
- func (c *Client) ContainerLogs(namespace, podName, containerName string) string
- func (c *Client) ControllerRuntimeClient() crclient.Client
- func (c *Client) Create(o crclient.Object) (err error)
- func (c *Client) Delete(o crclient.Object) (err error)
- func (c *Client) Get(o crclient.Object) (err error)
- func (c *Client) GroupVersionResource(o crclient.Object) (schema.GroupVersionResource, error)
- func (c *Client) Host() string
- func (c *Client) List(list crclient.ObjectList, opts ...ListOption) (err error)
- func (c *Client) Recreate(o crclient.Object) (err error)
- func (c *Client) Remove(o crclient.Object) (err error)
- func (c *Client) RemoveSync(o crclient.Object) (err error)
- func (c *Client) Timeout() time.Duration
- func (c *Client) Update(o crclient.Object) (err error)
- func (c *Client) WaitFor(o client.Object, condition Condition) (err error)
- func (c *Client) WaitForType(o client.Object, condition Condition, opts ...ListOption) (err error)
- func (c *Client) Watch(gvr schema.GroupVersionResource, opts ...ListOption) (w watch.Interface, err error)
- func (c *Client) WatchObject(o client.Object) (w watch.Interface, err error)
- func (c *Client) WatchTypeOf(o client.Object, opts ...ListOption) (w watch.Interface, err error)
- func (c *Client) WithLabels(labels map[string]string) *Client
- func (c *Client) WithTimeout(timeout time.Duration) *Client
- type Condition
- type Continue
- type HasLabels
- type InNamespace
- type Limit
- type ListOption
- type ListOptions
- type MatchingFields
- type MatchingFieldsSelector
- type MatchingLabels
- type MatchingLabelsSelector
- type NamespaceClient
- type Test
- type TestOption
- type TestOptions
Constants ¶
const ( // LabelKey is the create label key for the Get() client. LabelKey = "test-client" // LabelValue is the create label value for the Get() client. LabelValue = "true" )
Variables ¶
var ( ErrWatchClosed = errors.New("watch closed") ErrTimeout = errors.New("timeout") )
Functions ¶
func IgnoreAlreadyExists ¶
IgnoreAlreadyExists returns nil on AlreadyExists errors, other values returned unmodified.
func IgnoreNotFound ¶
IgnoreNotFound returns nil on NotFound errors, other values returned unmodified.
func IsDaemonSetReady ¶
DaemonSetIsReady returns (true, nil) when the pods of the set are ready on all nodes in the cluster and (false, nil) otherwise.
func PodFailed ¶
PodFailed returns (true,nil) when e.Object is a Pod with phase PodFailed. Returns an error if pod reaches any other long-lasting state [failed, succeeded ,running]
func PodRunning ¶
PodRunning returns (true,nil) when e.Object is a Pod with phase PodRunning. Returns an error if pod reaches any other long-lasting state [failed, succeeded ,running]
func PodSucceeded ¶
PodSucceeded returns (true,nil) when e.Object is a Pod with phase PodSucceeded. Returns an error if pod reaches any other long-lasting state [failed, succeeded ,running]
Types ¶
type Client ¶
Client operates on any runtime.Object (core or custom) and has Watch to wait efficiently.
func Get ¶
func Get() *Client
Get returns a process-wide singleton client, created on demand. Uses defaults: DefaultTimeout, LabelKey, LabelValue.
func New ¶
New client.
Operations will fail if they take longer than timeout. The Labels will be applied to each object created by the client.
func (*Client) ContainerLogStream ¶
func (c *Client) ContainerLogStream(namespace, podName, containerName string, follow bool) (io.ReadCloser, error)
ContainerLogStream returns the log stream for a container. Empty containerName means default container.
func (*Client) ContainerLogs ¶
ContainerLogs returns the pod logs, or an error string if there is a problem reading them. Empty containerName means default container.
func (*Client) ControllerRuntimeClient ¶
ControllerRuntimeClient returns the underlying controller runtime Client
func (*Client) Get ¶
Get the resource with the name, namespace and type of o, copy it's state into o.
func (*Client) GroupVersionResource ¶
GroupVersionResource uses the Client's RESTMapping to find the resource name for o.
func (*Client) List ¶
func (c *Client) List(list crclient.ObjectList, opts ...ListOption) (err error)
List resources, return results in o, which must be an xxxList struct.
func (*Client) Recreate ¶
Recreate creates o after removing any existing object of the same name and type.
func (*Client) RemoveSync ¶
RemoveSync is like Delete but ignores NotFound errors and deletes in the foreground
func (*Client) Update ¶
Update the state of resource with name, namespace and type of o using the state in o.
func (*Client) WaitFor ¶
WaitFor watches o until condition() returns true or error, or c.Timeout expires. It is not an error if o does not exist, it will be waited for. o is updated from the last object seen by the watch.
func (*Client) WaitForType ¶
WaitForType watches for events involving objects of the same type as o, until condition() returns true or error, or c.Timeout expires. o is updated from the last object seen by the watch.
func (*Client) Watch ¶
func (c *Client) Watch(gvr schema.GroupVersionResource, opts ...ListOption) (w watch.Interface, err error)
Watch for changes in namespace to objects with the given GroupVersionResource, apply the given list options to the watch.
func (*Client) WatchObject ¶
WatchObject returns a watch for changes to a single named object. Note: it is not an error if no such object exists, the watcher will wait for creation.
func (*Client) WatchTypeOf ¶
WatchTypeOf returns a watch using the GroupVersionResource of object o.
func (*Client) WithLabels ¶
WithLabels returns a client that uses c but has a different set of Create Labels.
type Condition ¶
Condition returns true if an event meets the condition, error if something goes wrong.
type InNamespace ¶
type InNamespace = crclient.InNamespace
type ListOptions ¶
type ListOptions = crclient.ListOptions
type MatchingFields ¶
type MatchingFields = crclient.MatchingFields
type MatchingFieldsSelector ¶
type MatchingFieldsSelector = crclient.MatchingFieldsSelector
type MatchingLabels ¶
type MatchingLabels = crclient.MatchingLabels
type MatchingLabelsSelector ¶
type MatchingLabelsSelector = crclient.MatchingLabelsSelector
type NamespaceClient ¶
type NamespaceClient struct {
Test
}
NamespaceClient wraps the singleton test client for use with hack testing
func NewNamespaceClient ¶
func NewNamespaceClient() *NamespaceClient
func (*NamespaceClient) Close ¶
func (t *NamespaceClient) Close()
type Test ¶
Test wraps the singleton test client with setup/teardown and convenience methods for testing.
func ForTest ¶
ForTest returns a Test for a testing.T. The client.Test is closed when the test ends.
func NewTest ¶
func NewTest(testOptions ...TestOption) *Test
NewTest creates a new Test, which includes creating a new test namespace.
type TestOption ¶
type TestOption string
TestOption is an option to alter a test in some way
const ( //UseInfraNamespaceTestOption is the option to hint the test should be run in an infrastructure namespace UseInfraNamespaceTestOption TestOption = "useInfraNamespace" //DryRunTestOption is a hint to use in testing to not actually create resources against cluster (e.g. unit tests) DryRunTestOption TestOption = "dryRun" )
type TestOptions ¶
type TestOptions []TestOption
func (TestOptions) Include ¶
func (options TestOptions) Include(option TestOption) bool