Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ binaries: clean \
_output/bin/apptainer.lima \
_output/bin/docker.lima \
_output/bin/podman.lima \
_output/bin/kubectl.lima \
_output/share/lima/lima-guestagent.Linux-x86_64 \
_output/share/lima/lima-guestagent.Linux-aarch64 \
_output/share/lima/lima-guestagent.Linux-riscv64
Expand Down Expand Up @@ -87,6 +88,10 @@ _output/bin/podman.lima: ./cmd/podman.lima
@mkdir -p _output/bin
cp -a $^ $@

_output/bin/kubectl.lima: ./cmd/kubectl.lima
@mkdir -p _output/bin
cp -a $^ $@

.PHONY: _output/bin/limactl$(exe)
_output/bin/limactl$(exe):
# The hostagent must be compiled with CGO_ENABLED=1 so that net.LookupIP() in the DNS server
Expand Down Expand Up @@ -132,6 +137,7 @@ uninstall:
"$(DEST)/bin/apptainer.lima" \
"$(DEST)/bin/docker.lima" \
"$(DEST)/bin/podman.lima" \
"$(DEST)/bin/kubectl.lima" \
"$(DEST)/share/lima" "$(DEST)/share/doc/lima"
if [ "$$(readlink "$(DEST)/bin/nerdctl")" = "nerdctl.lima" ]; then rm "$(DEST)/bin/nerdctl"; fi
if [ "$$(readlink "$(DEST)/bin/apptainer")" = "apptainer.lima" ]; then rm "$(DEST)/bin/apptainer"; fi
Expand Down
30 changes: 30 additions & 0 deletions cmd/kubectl.lima
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh
set -eu
: "${LIMA_INSTANCE:=}"
: "${KUBECTL:=kubectl}"

if [ -z "$LIMA_INSTANCE" ]; then
if [ "$(limactl ls -f '{{.Status}}' k3s 2>/dev/null)" = "Running" ]; then
LIMA_INSTANCE=k3s
elif [ "$(limactl ls -f '{{.Status}}' k8s 2>/dev/null)" = "Running" ]; then
LIMA_INSTANCE=k8s
else
echo "No k3s or k8s running instances found. Either start one with" >&2
echo "limactl start --name=k3s template://k3s" >&2
echo "limactl start --name=k8s template://k8s" >&2
echo "or set LIMA_INSTANCE to the name of your Kubernetes instance" >&2
exit 1
fi
elif [ "$(limactl ls -q "$LIMA_INSTANCE" 2>/dev/null)" != "$LIMA_INSTANCE" ]; then
echo "instance \"$LIMA_INSTANCE\" does not exist, run \`limactl start --name=$LIMA_INSTANCE\` to create a new instance" >&2
exit 1
fi
KUBECTL=$(command -v "$KUBECTL" || true)
if [ -n "$KUBECTL" ]; then
KUBECONFIG=$(limactl list "$LIMA_INSTANCE" --format '{{.Dir}}/copied-from-guest/kubeconfig.yaml')
export KUBECONFIG
exec "$KUBECTL" "$@"
else
export LIMA_INSTANCE
exec lima sudo kubectl "$@"
fi