kubernetesk8s.io/kubernetes/test/utils/localupcluster Index | Files

package localupcluster

import "k8s.io/kubernetes/test/utils/localupcluster"

Package localupcluster contains wrapper code around invoking hack/local-up-cluster.sh and managing the resulting cluster.

Package localupcluster contains wrapper code around invoking hack/local-up-cluster.sh and managing the resulting cluster.

The basic mode of operation is:

Index

Constants

const (
	KubeAPIServer         = KubeComponentName("kube-apiserver")
	KubeControllerManager = KubeComponentName("kube-controller-manager")
	KubeScheduler         = KubeComponentName("kube-scheduler")
	Kubelet               = KubeComponentName("kubelet")
	KubeProxy             = KubeComponentName("kube-proxy")
	Kubectl               = KubeComponentName("kubectl")
	LocalUpCluster        = KubeComponentName("local-up-cluster")
)

Component names.

They match the names in the local-up-cluster.sh output, if the script runs those components.

Variables

var KubeClusterComponents = []KubeComponentName{KubeAPIServer, KubeControllerManager, KubeScheduler, Kubelet, KubeProxy}

Kubernetes components running in the cluster, in the order in which they need to be started and upgraded.

Types

type Cluster

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

Cluster represents one cluster.

hack/local-up-cluster.sh must be functional in the current environment. If necessary, env variables like CONTAINER_RUNTIME_ENDPOINT have to be set to adapt the script to the host system. The current user must have permission to use the container runtime. All Kubernetes components run as that user with files stored in a test temp directory.

local-up-cluster.sh does not support more than one cluster per host, so tests using this package have to run sequentially.

func New

func New(tCtx ktesting.TContext) *Cluster

func (*Cluster) GetSystemLogs

func (c *Cluster) GetSystemLogs(tCtx ktesting.TContext, component KubeComponentName) (string, bool)

GetSystemLogs returns the output of the given component, the empty string and false if not started.

func (*Cluster) LoadConfig

func (c *Cluster) LoadConfig(tCtx ktesting.TContext) *restclient.Config

LoadConfig returns the REST config for the running cluster.

func (*Cluster) Modify

func (c *Cluster) Modify(tCtx ktesting.TContext, options ModifyOptions) ModifyOptions

Modify changes the cluster as described in the options. It returns options that can be passed to Modify unchanged to restore the original state.

func (*Cluster) Start

func (c *Cluster) Start(tCtx ktesting.TContext, bindir string, localUpClusterEnv map[string]string)

Start brings up the cluster anew. If it was already running, it will be stopped first.

The cluster will be stopped automatically at the end of the test. If the ARTIFACTS env variable is set and the test failed, log files of the kind cluster get dumped into $ARTIFACTS/<test name>/kind/<cluster name> before stopping it.

The binary directory must contain kube-apiserver, kube-controller-manager, kube-scheduler, kube-proxy, and kubelet. Those binaries can be from a previous Kubernetes release. They will be invoked with parameters as defined in the *current* local-up-cluster.sh. This works as long as local-up-cluster.sh in its default configuration doesn't depend on something which was added only recently.

func (*Cluster) Stop

func (c *Cluster) Stop(tCtx ktesting.TContext)

Stop ensures that the cluster is not running anymore.

type Cmd

type Cmd struct {
	// Name is a short, descriptive name.
	Name string

	// CommandLine is the complete command line, including the command itself.
	CommandLine []string

	// AdditionalEnv gets added to the current environment.
	AdditionalEnv map[string]string

	// Log output as it gets printed.
	LogOutput bool

	// ProcessOutput, it non-nil, gets called for each line printed by the
	// command on stderr or stdout. The line does not include the trailing
	// newline.
	//
	// Called with EOF true when output processing stops. This implies
	// that the command has stopped or output processing failed. A non-empty
	// line in this case is the output processing error.
	ProcessOutput func(output Output)

	// Gather output in a string buffer. That collected output is returned by Wait and Stop.
	// If disabled, those methods return the empty string.
	GatherOutput bool

	// LogFile specifies a file to write the output to.
	// Can be combined with other options for output handling.
	// If it's the only one, then the command writes directly
	// into the file.
	LogFile string

	// KeepRunning ensures that the command is kept running beyond the end of its context,
	// i.e. context cancellation is ignored. Such commands have to be stopped explicitly.
	KeepRunning bool
	// contains filtered or unexported fields
}

func (*Cmd) Output

func (c *Cmd) Output(tCtx ktesting.TContext) string

func (*Cmd) Running

func (c *Cmd) Running() bool

func (*Cmd) Start

func (c *Cmd) Start(tCtx ktesting.TContext)

func (*Cmd) Stop

func (c *Cmd) Stop(tCtx ktesting.TContext, reason string) string

func (*Cmd) Wait

func (c *Cmd) Wait(tCtx ktesting.TContext) string

type KubeComponentName

type KubeComponentName string

type ModifyOptions

type ModifyOptions struct {
	// BinDir specifies where to find the replacement Kubernetes components.
	// If empty, then only components explicitly listed in FileByComponent
	// get modified.
	BinDir string

	// FileByComponent overrides BinDir for those components which are specified here.
	FileByComponent map[KubeComponentName]string

	// Upgrade determines whether the apiserver gets updated first (upgrade)
	// or last (downgrade).
	Upgrade bool
}

func (ModifyOptions) GetComponentFile

func (m ModifyOptions) GetComponentFile(component KubeComponentName) string

type Output

type Output struct {
	Line string
	EOF  bool
}

Source Files

cmd.go localupcluster.go

Version
v1.34.0-beta.0
Published
Jul 16, 2025
Platform
js/wasm
Imports
25 packages
Last checked
7 minutes ago

Tools for package owners.