NAME

Kubernetes::REST::CLI::Minikube - Bring up a minikube test cluster and run a command against it

VERSION

version 1.108

SYNOPSIS

use Kubernetes::REST::CLI::Minikube;

my ($options, $command) = Kubernetes::REST::CLI::Minikube->split_argv(@ARGV);
@ARGV = @$options;
my $runner = Kubernetes::REST::CLI::Minikube->new_with_options;
exit $runner->run(@$command);

DESCRIPTION

MooX::Options-based class that powers the kube_test_minikube CLI tool. It makes sure a minikube binary is available (downloading a verified one into a cache directory when there is none), brings up a minikube profile whose kubeconfig lives in an isolated file, exports the live-test gate variables of the Kubernetes::REST family of distributions and runs the command it was given with that environment.

This class does not talk to the Kubernetes API and does not consume Kubernetes::REST::CLI::Role::Connection: it only orchestrates the minikube binary. Every process interaction goes through "_run", "_capture" and "_download", so tests can replace them without a real minikube.

The KUBECONFIG environment variable is set to the isolated file for every minikube invocation, so the user's ~/.kube/config is never read or written.

profile

The minikube profile to bring up, passed as -p to every minikube invocation. Default: kube-rest-test. The profile also names the kubeconfig context minikube writes.

Short option: -p

driver

The minikube driver, passed as --driver= to minikube start. Default: docker.

Short option: -d

kubernetes_version

Kubernetes version for the cluster, passed as --kubernetes-version= to minikube start when set. Omit to let minikube pick its default.

Short option: -k

minikube_version

Pin the minikube release, as tagged upstream (v1.38.1). When set, the binary in "install_dir" is used if it reports exactly this version and downloaded from the release directory of that version otherwise; a minikube found on PATH is ignored. Without a pin a minikube on PATH is used as-is, then one already in "install_dir", and only when neither exists the latest release is downloaded.

cpus

Number of CPUs for the cluster, passed as --cpus= to minikube start when set.

Short option: -c

memory

Memory for the cluster in minikube's notation (4g, 4096mb, or a plain number of megabytes), passed as --memory= to minikube start when set.

Short option: -m

container_runtime

Container runtime for the cluster, passed as --container-runtime= to minikube start when set. On a Podman backend the rootless driver needs --driver podman --container-runtime containerd --rootless.

rootless

Pass --rootless to minikube start. Required by the rootless podman driver, which additionally needs --container-runtime containerd (see "container_runtime").

install_dir

Directory a downloaded minikube binary is installed into, and where the default "kubeconfig" lives. Default: $XDG_CACHE_HOME/kube_test_minikube, or ~/.cache/kube_test_minikube when XDG_CACHE_HOME is not set.

kubeconfig

Path of the isolated kubeconfig file. Default: <install_dir>/<profile>.kubeconfig. Every minikube invocation runs with KUBECONFIG set to this file, and it is the value all exported variables receive. Removed again by "delete".

env

Name of an additional environment variable to set to the kubeconfig path, for distributions with a live-test gate of their own. Repeatable.

Short option: -e

context

When set, TEST_KUBERNETES_REST_CONTEXT is exported with this value as well. Without it that variable is left alone.

stop

Run minikube stop after the command has finished. Without a command, stop the profile and exit without starting anything.

Short option: -s

delete

Run minikube delete after the command has finished and remove the kubeconfig file. Without a command, delete the profile and exit without starting anything. Takes precedence over "stop".

Short option: -D

restart

Run minikube start even when the profile already reports a running host and API server. start is idempotent on minikube's side; this makes it re-check the node.

Short option: -r

verbose

Print each minikube command line to STDERR before it runs.

Short option: -v

minikube_bin

Path of the minikube binary in use. Resolved lazily as described under "minikube_version", downloading and verifying a release when nothing usable exists; pass it to the constructor to use a specific binary and skip the lookup.

split_argv

my ($options, $command) = Kubernetes::REST::CLI::Minikube->split_argv(@ARGV);

Class method. Splits a command line into the tool's own options and the command to run: the command starts at the first argument that is not an option or the value of an option that takes one, or after a --. Returns two array references. MooX::Options rewrites @ARGV before parsing it (a bundled -lr becomes -l r), so the command has to be taken out before new_with_options ever sees it - this is what bin/kube_test_minikube does. Unique prefixes of long option names are recognised the way Getopt::Long recognises them.

run

my $exit_code = $runner->run(@command);

Entry point called by bin/kube_test_minikube. Makes sure the profile is running ("_ensure_running"), then runs @command with the environment from "_env_for_child" and returns the command's exit status: its exit code, or 128 plus the signal number when it died from a signal, or 127 when it could not be started at all. "stop" and "delete" tear the profile down after the command and never mask that status.

Without a command it prints one export NAME='value' line per exported variable to STDOUT, for eval "$(kube_test_minikube)", and returns 0 - unless "stop" or "delete" is set, in which case it only tears down and returns minikube's exit status.

Dies when minikube start fails, naming the profile and driver; the process exit code is then minikube's.

_ensure_running

Runs minikube start unless "_running" reports the profile up and the kubeconfig file exists, or always with "restart". Dies naming the profile and driver when start fails.

_running

Returns true when minikube status -o json reports both the host and the API server of the profile as Running. A failing status (unknown or stopped profile) counts as not running. On a multi-node profile the control-plane entry is the one consulted.

_teardown

Runs minikube delete (and removes the kubeconfig file) when "delete" is set, otherwise minikube stop when "stop" is set, otherwise nothing. Returns the raw $? of the minikube command, 0 when nothing ran.

_env_for_child

Returns a hash reference of the environment variables exported to the command: KUBECONFIG, TEST_KUBERNETES_REST_KUBECONFIG, TEST_IO_K8S_KUBECONFIG and every "env" name, all set to the absolute kubeconfig path; TEST_KUBERNETES_REST_CONTEXT only when "context" is given; and PATH with "install_dir" prepended when the binary in use lives there, so minikube is reachable from inside the command.

_run

my $status = $runner->_run(@cmd);

Runs @cmd without a shell, with STDIN, STDOUT and STDERR passed through, and returns the raw $? (-1 when it could not be started). The seam every pass-through process interaction goes through; override it in tests.

_capture

my $stdout = $runner->_capture(@cmd);

Runs @cmd without a shell and returns its STDOUT as a string (STDERR is passed through). Dies when the command cannot be started or exits non-zero. The seam every parsed process interaction goes through; override it in tests.

_download

$runner->_download($url, $file);

Fetches $url straight into $file (streamed to disk, never held in memory) and dies on any HTTP failure. The seam for every HTTP interaction; override it in tests.

SEE ALSO

SUPPORT

Issues

Please report bugs and feature requests on GitHub at https://github.com/pplu/kubernetes-rest/issues.

IRC

Join #kubernetes on irc.perl.org or message Getty directly.

CONTRIBUTING

Contributions are welcome! Please fork the repository and submit a pull request.

AUTHORS

  • Torsten Raudssus <getty@cpan.org>

  • Jose Luis Martinez Torres <jlmartin@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2019-2026 by Jose Luis Martinez Torres <jlmartin@cpan.org>.

This is free software, licensed under:

The Apache License, Version 2.0, January 2004