testkubeclient

package
v1.16.1-rc.1 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const FieldManager = configsync.GroupName + "/nomostest"

FieldManager is the field manager to use when creating, updating, and patching kubernetes objects with kubectl and client-go. This is used to uniquely identify the nomostest client, to enable field pruning and merging. This must be different from the field manager used by config sync, in order to allow both clients to manage different fields on the same objects.

View Source
const TestLabel = "nomos-test"

TestLabel is the label added to all test objects, ensuring we can clean up non-ephemeral clusters when tests are complete.

View Source
const TestLabelValue = "enabled"

TestLabelValue is the value assigned to the above label.

Variables

AddTestLabel is automatically added to objects created or declared with the NT methods, or declared with Repository.Add.

This isn't perfect - objects added via other means (such as kubectl) will bypass this.

Functions

This section is empty.

Types

type KubeClient

type KubeClient struct {
	// Context to use, if not specified by the method.
	Context context.Context
	// Client to use to manage Kubernetes objects.
	Client client.Client
	// Logger for methods to use.
	Logger *testlogger.TestLogger
}

KubeClient wraps client.KubeClient to handle logging, default test-scoped context, and type checking in the schema before API calls.

Includes some advanced helper functions, like Apply, MergePatch, and GetDeploymentPod.

func (*KubeClient) Apply

func (tc *KubeClient) Apply(obj client.Object, opts ...client.PatchOption) error

Apply wraps Patch to perform a server-side apply. All non-nil fields will be adopted by the nomostest field manager.

func (*KubeClient) Create

func (tc *KubeClient) Create(obj client.Object, opts ...client.CreateOption) error

Create is identical to Create defined for clietc.Client, but without requiring Context.

func (*KubeClient) Delete

func (tc *KubeClient) Delete(obj client.Object, opts ...client.DeleteOption) error

Delete is identical to Delete defined for clietc.Client, but without requiring Context.

func (*KubeClient) DeleteAllOf

func (tc *KubeClient) DeleteAllOf(obj client.Object, opts ...client.DeleteAllOfOption) error

DeleteAllOf is identical to DeleteAllOf defined for clietc.Client, but without requiring Context.

func (*KubeClient) Get

func (tc *KubeClient) Get(name, namespace string, obj client.Object) error

Get is identical to Get defined for clietc.Client, except:

1) Context implicitly uses the one created for the test case. 2) name and namespace are strings instead of requiring client.ObjectKey.

Leave namespace as empty string for cluster-scoped resources.

func (*KubeClient) GetDeploymentPod

func (tc *KubeClient) GetDeploymentPod(deploymentName, namespace string, retrytTimeout time.Duration) (*corev1.Pod, error)

GetDeploymentPod is a convenience method to look up the pod for a deployment. It requires that exactly one pod exists, is running, and that the deployment uses label selectors to uniquely identify its pods. This is primarily useful for finding the current pod for a reconciler or other single-replica controller deployments.

func (*KubeClient) List

func (tc *KubeClient) List(obj client.ObjectList, opts ...client.ListOption) error

List is identical to List defined for clietc.Client, but without requiring Context.

func (*KubeClient) MergePatch

func (tc *KubeClient) MergePatch(obj client.Object, patch string, opts ...client.PatchOption) error

MergePatch uses the object to construct a merge patch for the fields provided. All specified fields will be adopted by the nomostest field manager.

func (*KubeClient) ObjectTypeMustExist

func (tc *KubeClient) ObjectTypeMustExist(o client.Object) error

ObjectTypeMustExist returns an error if the passed type is not declared in the client's scheme.

func (*KubeClient) Update

func (tc *KubeClient) Update(obj client.Object, opts ...client.UpdateOption) error

Update is identical to Update defined for clietc.Client, but without requiring Context. All fields will be adopted by the nomostest field manager.

Jump to

Keyboard shortcuts

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