dynakube

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

README

dynakube

Kubernetes Test client with dynamic behavior

This client simplifies testing controllers with dynamic behaviour.

How to use

// initial state of the store.
d := &appsv1.Deployment{
    ObjectMeta: metav1.ObjectMeta{
        Namespace: "test",
        Name:      "foo",
    },
}
client := dynakube.NewDynamicClient(clientScheme, d)

// register custom reactors if you want to customize the behavior. 
client.PrependReactor("update", "deployments", func(action t.Action) (bool, runtime.Object, error) {
    return true, nil, &errors.StatusError{ErrStatus: metav1.Status{Code: 500}}
})

// run your reconciler.
r := NewReconciler(client)
name := types.NamespacedName{Namespace: "test", Name: "foo"}
_, err := r.Reconcile(context.Background(), controllers.Request{NamespacedName: name})
Expect(err).ToNot(BeNil())

Notes

This project reuses code from k8s.io/client-go package.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a fake client which implements controller runtime client.

func NewClient

func NewClient(scheme *runtime.Scheme, objects ...runtime.Object) *Client

func NewDynamicClient

func NewDynamicClient(scheme *runtime.Scheme, objects ...runtime.Object) *Client

DEPRECATED. Use NewClient

func (*Client) AddObjects added in v0.0.2

func (c *Client) AddObjects(objs ...runtime.Object) error

func (*Client) Create

func (c *Client) Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error

Create saves the object obj.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error

Delete deletes the given obj.

func (*Client) DeleteAllOf

func (c *Client) DeleteAllOf(ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption) error

DeleteAllOf ...

func (*Client) Get

func (c *Client) Get(ctx context.Context, key client.ObjectKey, obj client.Object) error

Get retrieves an obj for the given object key from the Kubernetes Cluster.

func (*Client) List

func (c *Client) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error

List retrieves list of objects for a given namespace and list options.

func (*Client) Patch

func (c *Client) Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error

Patch ...

func (*Client) PrependReactor

func (c *Client) PrependReactor(verb string, resource string, action func(action testing.Action) (handled bool, ret runtime.Object, err error))

func (*Client) RESTMapper

func (c *Client) RESTMapper() meta.RESTMapper

RESTMapper ...

func (*Client) Scheme

func (c *Client) Scheme() *runtime.Scheme

Scheme ...

func (*Client) Status

func (c *Client) Status() client.StatusWriter

Status returns fake status writer.

func (*Client) Update

func (c *Client) Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error

Update updates the given obj.

Jump to

Keyboard shortcuts

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