clusters

package
v0.47.2 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2024 License: Apache-2.0 Imports: 30 Imported by: 6

Documentation

Index

Constants

View Source
const DiagnosticOutDirectoryPrefix = "ktf-diag-"

DiagnosticOutDirectoryPrefix is the tmpdir prefix used for diagnostic dumps.

View Source
const (
	// TestResourceLabel is a label used on any resources to indicate that they
	// were created as part of a testing run and can be cleaned up in bulk based
	// on the value provided to the label.
	TestResourceLabel = "created-by-ktf"
)

Variables

This section is empty.

Functions

func ApplyManifestByURL added in v0.17.0

func ApplyManifestByURL(ctx context.Context, cluster Cluster, url string) error

ApplyManifestByURL applies a given manifest URL to the cluster provided

func ApplyManifestByYAML added in v0.17.0

func ApplyManifestByYAML(ctx context.Context, cluster Cluster, yaml string) error

ApplyManifestByYAML applies a given YAML manifest to the cluster provided

func CleanupGeneratedResources added in v0.9.0

func CleanupGeneratedResources(ctx context.Context, cluster Cluster, creatorID string) error

CleanupGeneratedResources cleans up all resources created by the given creator ID.

func CreateNamespace added in v0.6.3

func CreateNamespace(ctx context.Context, cluster Cluster, namespace string) error

CreateNamespace creates a new namespace in the given cluster provided a name.

func DeleteIngress added in v0.6.1

func DeleteIngress(ctx context.Context, c Cluster, namespace string, ingress runtime.Object) (err error)

DeleteIngress is a helper and function to delete an Ingress object to a cluster handling the version of the Ingress object for the caller so they don't have to. TODO: once we stop supporting old Kubernetes versions <1.19 we can remove this.

func DeleteManifestByURL added in v0.17.0

func DeleteManifestByURL(ctx context.Context, cluster Cluster, url string) error

DeleteManifestByURL deletes a given manifest URL on the cluster provided

func DeleteManifestByYAML added in v0.17.0

func DeleteManifestByYAML(ctx context.Context, cluster Cluster, yaml string) error

DeleteManifestByYAML deletes a given YAML manifest on the cluster provided

func DeployIngress added in v0.6.1

func DeployIngress(ctx context.Context, c Cluster, namespace string, ingress runtime.Object) (err error)

DeployIngress is a helper and function to deploy an Ingress object to a cluster handling the version of the Ingress object for the caller so they don't have to. TODO: once we stop supporting old Kubernetes versions <1.19 we can remove this.

func DumpAllDescribeAll added in v0.31.0

func DumpAllDescribeAll(ctx context.Context, c Cluster, outDir string) error

DumpAllDescribeAll gathers diagnostic information from the cluster. Specifically it runs "kubectl get all" and "kubectl describe all" for all resources and stores the output into two respective yaml files (kubectl_get_all.yaml and kubectl_describe_all.yaml).

func DumpDiagnostics added in v0.24.0

func DumpDiagnostics(ctx context.Context, c Cluster, meta string, outDir string) error

DumpDiagnostics gathers a wide range of generic, diagnostic information from the test cluster, to provide a snapshot of it at a given time for offline debugging. It uses the provided context and writes the meta string to meta.txt to identify the result set. It returns the name of the directory that contains all the produced diagnostics data.

func GenerateNamespace added in v0.9.0

func GenerateNamespace(ctx context.Context, cluster Cluster, creatorID string) (*corev1.Namespace, error)

GenerateNamespace creates a transient testing namespace given the cluster to create it on and a creator ID. The namespace will be given a UUID for a name, and the creatorID will be applied to the TestResourceLabel for automated cleanup.

func GetIngressLoadbalancerStatus added in v0.6.1

func GetIngressLoadbalancerStatus(ctx context.Context, c Cluster, namespace string, ingress runtime.Object) (*corev1.LoadBalancerStatus, error)

GetIngressLoadbalancerStatus is a partner to the above DeployIngress function which will given an Ingress object provided by the caller determine the version and pull a fresh copy of the current LoadBalancerStatus for that Ingress object without the caller needing to be aware of which version of Ingress they're using. TODO: once we stop supporting old Kubernetes versions <1.19 we can remove this.

func KustomizeDeleteForCluster added in v0.14.2

func KustomizeDeleteForCluster(ctx context.Context, cluster Cluster, kustomizeURL string, flags ...string) error

KustomizeDeleteForCluster deletes the provided kustomize manafests from the cluster

func KustomizeDeployForCluster added in v0.9.0

func KustomizeDeployForCluster(ctx context.Context, cluster Cluster, kustomizeURL string, flags ...string) error

KustomizeDeployForCluster applies a given kustomizeURL to the provided cluster

func TempKubeconfig added in v0.9.0

func TempKubeconfig(cluster Cluster) (*os.File, error)

TempKubeconfig produces a kubeconfig tempfile given a cluster. the caller is responsible for cleaning up the file if they want it removed.

func WaitForAddonDependencies added in v0.11.0

func WaitForAddonDependencies(ctx context.Context, cluster Cluster, addon Addon) error

WaitForAddonDependencies is a convenience method to wait for all dependencies of a given addon to be ready on the cluster according to a given context.

func WaitForCondition added in v0.10.0

func WaitForCondition(ctx context.Context, cluster Cluster, namespace, objectType, object, condition string, seconds int) error

WaitForCondition waits for a condition to be true for an object on the cluster given that objects namespace, type and name.

Types

type Addon

type Addon interface {
	// Name indicates the unique name of the Addon
	Name() AddonName

	// Dependencies indicates any addons this addon is dependent on in order
	// for operations to succeed.
	Dependencies(ctx context.Context, cluster Cluster) []AddonName

	// Deploy deploys the addon component to a provided cluster.
	// Addon implementations are responsible for waiting for their
	// own dependencies to deploy as needed.
	Deploy(ctx context.Context, cluster Cluster) error

	// Delete removes the addon component from the given cluster.
	Delete(ctx context.Context, cluster Cluster) error

	// DumpDiagnostics gathers and returns diagnostic information for an addon. Its return map is a map of string
	// filenames to file content byte slices.
	DumpDiagnostics(ctx context.Context, cluster Cluster) (map[string][]byte, error)

	// Ready is a non-blocking call which checks the status of the addon on the
	// cluster and reports any runtime.Objects which are still unresolved.
	// If all components are ready, this method will return [], true, nil.
	// If the addon has failed unrecoverably, it will provide an error.
	Ready(ctx context.Context, cluster Cluster) (waitingForObjects []runtime.Object, ready bool, err error)
}

Addon is a loadable component to extend the functionality of a Cluster.

type AddonName

type AddonName string

AddonName indicates a unique name for Addons which can be deployed to Clusters.

type Addons

type Addons map[AddonName]Addon

Addons is a map type for collecting a list of unique Addons.

type Builder added in v0.23.0

type Builder interface {
	Build(ctx context.Context) (Cluster, error)
}

type Cleaner added in v0.14.1

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

Cleaner holds namespaces and objects for later cleanup. This is generally used during integration tests to clean up test resources.

func NewCleaner added in v0.14.1

func NewCleaner(cluster Cluster) *Cleaner

NewCleaner provides a new initialized *Cleaner object.

func (*Cleaner) Add added in v0.14.1

func (c *Cleaner) Add(obj client.Object)

func (*Cleaner) AddManifest added in v0.18.0

func (c *Cleaner) AddManifest(manifest string)

func (*Cleaner) AddNamespace added in v0.14.1

func (c *Cleaner) AddNamespace(namespace *corev1.Namespace)

func (*Cleaner) Cleanup added in v0.14.1

func (c *Cleaner) Cleanup(ctx context.Context) error

func (*Cleaner) DumpDiagnostics deprecated added in v0.17.0

func (c *Cleaner) DumpDiagnostics(ctx context.Context, meta string) (string, error)

DumpDiagnostics dumps diagnostics from the underlying cluster.

Deprecated: Users should use Cluster.DumpDiagnostics().

type Cluster

type Cluster interface {
	// Name indicates the unique name of the running cluster.
	Name() string

	// Type indicates the type of Kubernetes Cluster (e.g. Kind, GKE, e.t.c.)
	Type() Type

	// Version indicates the Kubernetes server version of the cluster.
	Version() (semver.Version, error)

	// Client is the configured *kubernetes.Clientset which can be used to access the Cluster's API
	Client() *kubernetes.Clientset

	// Config provides the *rest.Config for the cluster which is convenient for initiating custom kubernetes.Clientsets.
	Config() *rest.Config

	// Cleanup performance any cleanup and teardown needed to destroy the cluster.
	Cleanup(ctx context.Context) error

	// GetAddon retrieves and Addon object from the cluster if that addon was previously loaded.
	GetAddon(name AddonName) (Addon, error)

	// ListAddons lists the addon components currently loaded into the cluster.
	ListAddons() []Addon

	// DeployAddon deploys a new addon component to the cluster.
	DeployAddon(ctx context.Context, addon Addon) error

	// DeleteAddon removes an existing cluster Addon.
	DeleteAddon(ctx context.Context, addon Addon) error

	// DumpDiagnostics dumps the diagnostic data to temporary directory and return the name
	// of said directory and an error.
	// It uses the provided meta string allow for diagnostics identification.
	DumpDiagnostics(ctx context.Context, meta string) (string, error)

	// IPFamily returns the cluster's IP networking capabilities.
	IPFamily() IPFamily
}

Cluster objects represent a running Kubernetes cluster.

type IPFamily added in v0.40.0

type IPFamily string
const (
	// IPv4 indicates a Cluster that supports only IPv4 networking.
	IPv4 IPFamily = "ipv4"
	// IPv6 indicates a Cluster that supports only IPv6 networking.
	IPv6 IPFamily = "ipv6"
	// Dual indicates a Cluster that supports both IPv4 and IPv6 networking.
	Dual IPFamily = "dual"
)

type Type

type Type string

Type indicates the type of Kubernetes cluster (e.g. Kind, GKE, e.t.c.)

Directories

Path Synopsis
addons
types
gke

Jump to

Keyboard shortcuts

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