-
Notifications
You must be signed in to change notification settings - Fork 589
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add kubectl kubernetes client wrapper
Will connect to a running "k3s" or "k8s" instance. Similar to other wrappers, but uses conf not sock. Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
- Loading branch information
1 parent
e4ede4f
commit d16e4b2
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/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 running instance found, run \`limactl start\` to start an 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}}/conf/kubeconfig.yaml') | ||
export KUBECONFIG | ||
exec "$KUBECTL" "$@" | ||
else | ||
export LIMA_INSTANCE | ||
exec lima sudo kubectl "$@" | ||
fi |