cluster

package
v0.0.0-...-ea9d87d Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2024 License: MIT Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const (
	K3sVersion1_26 = "v1.26.2-k3s1"
	K3sVersion1_28 = "v1.28.2-k3s1"
)

k3s versions warning: k3s versions are tagged with a `+` separator before `k3s1`, but k3s images use `-`.

View Source
const DefaultNamespace = "default"

Variables

View Source
var TestableRetryFunc = func(err error) bool {
	var testableRetrierError *TestableRetrierError
	ok := errors.As(err, &testableRetrierError)
	return ok
}

TestableRetryFunc returns true if the returned error is a TestableRetrierError and indicates that an action should be tried until the retrier hits its limit.

Functions

func NewCommandExecutor

func NewCommandExecutor(clientSet kubernetes.Interface, coreV1RestClient rest.Interface) *defaultCommandExecutor

NewCommandExecutor creates a new instance of NewCommandExecutor

Types

type K3dCluster

type K3dCluster struct {
	ClusterName         string
	AdminServiceAccount string
	// contains filtered or unexported fields
}

K3dCluster abstracts the cluster management during developer tests.

func CreateK3dCluster

func CreateK3dCluster(ctx context.Context, opts Opts) (cl *K3dCluster, err error)

CreateK3dCluster creates a completely new K8s cluster with an optional clusterNamePrefix.

func NewK3dCluster

func NewK3dCluster(t *testing.T) *K3dCluster

NewK3dCluster creates a completely new cluster within the provided container engine and default values. This method is the usual entry point of a test with testclusters-go.

func NewK3dClusterWithOpts

func NewK3dClusterWithOpts(t *testing.T, opts Opts) *K3dCluster

NewK3dClusterWithOpts creates like NewK3dCluster a new cluster but with more control over customization.

func (*K3dCluster) ClientSet

func (c *K3dCluster) ClientSet() (kubernetes.Interface, error)

ClientSet returns a K8s clientset which allows to interoperate with the cluster K8s API.

func (*K3dCluster) CtlKube

func (c *K3dCluster) CtlKube(fieldManager string) (*YamlApplier, error)

func (*K3dCluster) Lookout

func (c *K3dCluster) Lookout(t *testing.T) (*Lookout, error)

Lookout creates a new Lookout that interacts with the current cluster.

func (*K3dCluster) MustLookout

func (c *K3dCluster) MustLookout(t *testing.T) *Lookout

MustLookout creates a new Lookout that interacts with the current cluster. It does not return an error but panics with the found error instead.

func (*K3dCluster) Terminate

func (c *K3dCluster) Terminate(ctx context.Context) error

Terminate shuts down the configured k3d cluster.

func (*K3dCluster) WriteKubeConfig

func (c *K3dCluster) WriteKubeConfig(ctx context.Context, t *testing.T) string

WriteKubeConfig writes a Kube Config into the directory. This directory is the same where other Kube Configs may reside. This is useful when a testcluster should be debugged manually.

type Loglevel

type Loglevel int

Loglevel describes the verbosity of log messages being printed from testcluster-go

const (
	Error Loglevel = iota
	Warning
	Info
	Debug
)

type Lookout

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

Lookout provides convenience functionalities for cluster resources.

func (*Lookout) Pod

func (l *Lookout) Pod(namespace, name string) *PodSelector

Pod returns a single PodSelector to address a single pod.

func (*Lookout) Pods

func (l *Lookout) Pods(namespace string) *PodListSelector

Pods returns a PodListSelector to address multiple pods.

type NodeHealthCheckOpts

type NodeHealthCheckOpts struct {
	// SkipCheck controls whether a node check should be executed (which is usually a good idea). Defaults to false
	SkipCheck bool
}

NodeHealthCheckOpts customizes the way whether and how node health checks are executed.

type Opts

type Opts struct {
	// ClusterNamePrefix will be used to name the cluster so developers can discover
	// and address a cluster among others.
	// The cluster name prefix will be delimited by the default delimiter "-".
	// Defaults to the empty string which is allowed.
	ClusterNamePrefix string
	// LogLevel allows increases or decreases the testcluster-go's log verbosity.
	// Currently, k3d's log verbosity cannot be adjusted with this field.
	// Defaults to Warning.
	LogLevel Loglevel
	// NodeConditionEvictionHardArg allows tuning the kubelet's evictionHard argument.
	// Defaults to empty string.
	// See health.KubeletEvictionFsByPercentage for a helper function
	NodeConditionEvictionHardArg string
}

Opts allows customizing the K3d cluster's creation and operation.

type PodList

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

func (*PodList) Len

func (pl *PodList) Len(ctx context.Context, expected int) error

func (*PodList) Raw

func (pl *PodList) Raw(ctx context.Context) (*v1.PodList, error)

Raw queries the kubernetes API and returns the pod list as plain kubernetes API objects.

type PodListSelector

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

func (*PodListSelector) ByFieldSelector

func (pls *PodListSelector) ByFieldSelector(fieldSelector string) *PodListSelector

func (*PodListSelector) ByLabels

func (pls *PodListSelector) ByLabels(labels string) *PodListSelector

func (*PodListSelector) List

func (pls *PodListSelector) List() *PodList

type PodSelector

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

func (*PodSelector) Events

func (ps *PodSelector) Events(ctx context.Context, fieldSelectors ...string) (*corev1.EventList, error)

func (*PodSelector) Logs

func (ps *PodSelector) Logs(ctx context.Context) ([]byte, error)

func (*PodSelector) Raw

func (ps *PodSelector) Raw(ctx context.Context) (*corev1.Pod, error)

type ShellCommand

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

ShellCommand represents all necessary arguments to execute a command inside a container.

func NewShellCommand

func NewShellCommand(command string, args ...string) ShellCommand

NewShellCommand creates a new ShellCommand. While the command is mandatory, there can be zero to n command arguments.

func (*ShellCommand) CommandWithArgs

func (sc *ShellCommand) CommandWithArgs() []string

func (*ShellCommand) String

func (sc *ShellCommand) String() string

type TestableRetrierError

type TestableRetrierError struct {
	Err error
}

TestableRetrierError marks errors that indicate that a previously executed action should be retried with again. It must wrap an existing error.

func (*TestableRetrierError) Error

func (tre *TestableRetrierError) Error() string

Error returns the error's string representation.

type YamlApplier

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

YamlApplier provides a pod with kubectl access to the cluster.

func NewYamlApplier

func NewYamlApplier(restConfig *rest.Config, fieldManager, defaultNamespace string) (*YamlApplier, error)

func (*YamlApplier) ApplyWithFile

func (ya *YamlApplier) ApplyWithFile(ctx context.Context, yamlBytes []byte) error

ApplyWithFile copies the yaml bytes into a file and calls `kubectl apply -f`.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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