Compare commits

...

4 Commits

Author SHA1 Message Date
Jonas Forsberg
460cfe6254 Adds completion for rsh 2025-03-13 11:32:35 +01:00
Jonas Forsberg
d226951ba8 fixes double brackets 2025-03-13 11:08:19 +01:00
Jonas Forsberg
6694e1dde9 Fixes missing double quotes 2025-03-13 09:17:41 +01:00
Jonas Forsberg
c7af9dc1ee Fixes formating 2025-03-13 09:13:16 +01:00
3 changed files with 30 additions and 3 deletions

View File

@@ -13,10 +13,13 @@ kubectl plugin list
## kubectl-rsh
Creates a pod on the node and executes a shell on that node.
You need cluster admin rights and privileged pod execution rights
```
Usage:
kubectl rsh [nodeName]
```
### Variables
| Name | Default | Desciption |
@@ -28,6 +31,7 @@ Usage:
## kubectl-deprecated_api
Lists APIs flagged as deprecated
```
Usage:
kubectl deprecated-api
```

View File

@@ -23,7 +23,7 @@ if [[ "$1" == "version" ]];then
exit 0
fi
if [ "$1" == "--help" ]; then
if [[ "$1" == "--help" ]]; then
print_help
exit 0
fi
@@ -75,6 +75,6 @@ function remove_pod(){
trap remove_pod EXIT
echo "Waiting for pod to be ready..."
kubectl wait -n "$KUBECTL_RSH_NAMESPACE" --for=condition=Ready --timeout ${KUBECTL_RSH_POD_CREATE_TIMEOUT}m "$POD" >/dev/null
kubectl wait -n "$KUBECTL_RSH_NAMESPACE" --for=condition=Ready --timeout "${KUBECTL_RSH_POD_CREATE_TIMEOUT}m" "$POD" >/dev/null
kubectl attach -n "$KUBECTL_RSH_NAMESPACE" -it "$POD"

23
kubectl_complete-rsh Executable file
View File

@@ -0,0 +1,23 @@
#!/usr/bin/env bash
# If we are completing a flag, use Cobra's builtin completion system.
# To know if we are completing a flag we need the last argument starts with a `-` and does not contain an `=`
args=("$@")
lastArg=${args[((${#args[@]}-1))]}
if [[ "$lastArg" == -* ]]; then
if [[ "$lastArg" != *=* ]]; then
kubectl ns __complete "$@"
fi
else
# TODO Make sure we are not completing the value of a flag.
# TODO Only complete a single argument.
# Both are pretty hard to do in a shell script. The better way to do this would be to let
# Cobra do all the completions by using `cobra.ValidArgsFunction` in the program.
# But the below, although imperfect, is a nice example for plugins that don't use Cobra.
kubectl get nodes --no-headers -o custom-columns=":metadata.name"
# Turn off file completion. See the ShellCompDirective documentation within
# https://github.com/spf13/cobra/blob/main/shell_completions.md#completion-of-nouns
echo :4
fi