kubeclient

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: AGPL-3.0 Imports: 27 Imported by: 0

Documentation

Overview

The kubeclient package provides a simple wrapper around Kubernetes interactions commonly used in the e2e tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Kubeclient

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

A Kubeclient offers a communication interface to a Kubernetes cluster.

func New

func New(config *rest.Config, log *slog.Logger) (*Kubeclient, error)

New creates a new Kubeclient from a given Kubeconfig.

func NewForTest

func NewForTest(t *testing.T) *Kubeclient

NewForTest creates a Kubeclient with parameters suitable for e2e testing.

func NewFromConfigFile

func NewFromConfigFile(configPath string, log *slog.Logger) (*Kubeclient, error)

NewFromConfigFile creates a new Kubeclient for a given Kubeconfig file.

func (*Kubeclient) Apply

func (c *Kubeclient) Apply(ctx context.Context, objects ...*unstructured.Unstructured) error

Apply a set of namespaced manifests to a namespace.

func (*Kubeclient) Delete

func (c *Kubeclient) Delete(ctx context.Context, objects ...*unstructured.Unstructured) error

Delete a set of manifests.

func (*Kubeclient) Exec

func (c *Kubeclient) Exec(ctx context.Context, namespace, pod string, argv []string) (
	stdout string, stderr string, err error,
)

Exec executes a process in a pod and returns the stdout and stderr.

func (*Kubeclient) ExecDeployment added in v0.7.0

func (c *Kubeclient) ExecDeployment(ctx context.Context, namespace, deployment string, argv []string) (stdout string, stderr string, err error)

ExecDeployment executes a process in one of the deployment's pods.

func (*Kubeclient) PodsFromDeployment

func (c *Kubeclient) PodsFromDeployment(ctx context.Context, namespace, deployment string) ([]v1.Pod, error)

PodsFromDeployment returns the pods from a deployment in a namespace.

A pod is considered to belong to a deployment if it is owned by a ReplicaSet which is in turn owned by the Deployment in question.

func (*Kubeclient) PodsFromOwner added in v0.7.0

func (c *Kubeclient) PodsFromOwner(ctx context.Context, namespace, kind, name string) ([]v1.Pod, error)

PodsFromOwner returns the pods owned by an object in the namespace of the given kind.

func (*Kubeclient) PortForwardPod

func (k *Kubeclient) PortForwardPod(ctx context.Context, namespace, podName, remotePort string) (string, func(), error)

PortForwardPod starts a port forward to the selected pod.

On success, the function returns a TCP address that clients can connect to and a function to cancel the port forwarding.

func (*Kubeclient) RestartDeployment added in v0.7.0

func (c *Kubeclient) RestartDeployment(ctx context.Context, namespace, name string) error

RestartDeployment restarts a deployment by deleting all of its pods.

func (*Kubeclient) WaitForDaemonset

func (c *Kubeclient) WaitForDaemonset(ctx context.Context, namespace, name string) error

WaitForDaemonset watches the given daemonset and blocks until the desired number of pods are ready or the context expires (is cancelled or times out).

func (*Kubeclient) WaitForDeployment

func (c *Kubeclient) WaitForDeployment(ctx context.Context, namespace, name string) error

WaitForDeployment watches the given deployment and blocks until it meets the condition Available=True or the context expires (is cancelled or times out).

func (*Kubeclient) WaitForLoadBalancer

func (c *Kubeclient) WaitForLoadBalancer(ctx context.Context, namespace, name string) (string, error)

WaitForLoadBalancer waits until the given service is configured with an external IP and returns it.

func (*Kubeclient) WaitForPod

func (c *Kubeclient) WaitForPod(ctx context.Context, namespace, name string) error

WaitForPod watches the given pod and blocks until it meets the condition Ready=True or the context expires (is cancelled or times out).

func (*Kubeclient) WaitForStatefulSet added in v0.7.0

func (c *Kubeclient) WaitForStatefulSet(ctx context.Context, namespace, name string) error

WaitForStatefulSet watches the given StatefulSet and blocks until the desired number of pods are ready or the context expires (is cancelled or times out).

Jump to

Keyboard shortcuts

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