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:
- local-up-cluster.sh contains all the logic of how to configure and invoke components.
- local-up-cluster.sh is run in dry-run mode, which prints all commands and their parameters without actually running them, except for etcd: etcd's lifecycle is managed as before by the caller or local-up-cluster.sh.
- local-up-cluster.sh is kept running as long as the cluster runs to keep etcd running and generated configuration files around.
- This package takes care of running the commands, including output redirection.
- It can stop commands and run them again using different binaries to similar upgrades or downgrades.
Index ¶
- Constants
- Variables
- type Cluster
- func New(tCtx ktesting.TContext) *Cluster
- func (c *Cluster) GetSystemLogs(tCtx ktesting.TContext, component KubeComponentName) (string, bool)
- func (c *Cluster) LoadConfig(tCtx ktesting.TContext) *restclient.Config
- func (c *Cluster) Modify(tCtx ktesting.TContext, options ModifyOptions) ModifyOptions
- func (c *Cluster) Start(tCtx ktesting.TContext, bindir string, localUpClusterEnv map[string]string)
- func (c *Cluster) Stop(tCtx ktesting.TContext)
- type Cmd
- func (c *Cmd) Output(tCtx ktesting.TContext) string
- func (c *Cmd) Running() bool
- func (c *Cmd) Start(tCtx ktesting.TContext)
- func (c *Cmd) Stop(tCtx ktesting.TContext, reason string) string
- func (c *Cmd) Wait(tCtx ktesting.TContext) string
- type KubeComponentName
- type ModifyOptions
- type Output
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 (*Cluster) GetSystemLogs ¶
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 ¶
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 ¶
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 (*Cmd) Running ¶
func (*Cmd) Start ¶
func (*Cmd) Stop ¶
func (*Cmd) Wait ¶
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 ¶
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.