Compare commits

...

6 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
Jonas Forsberg
f89dd485b8 Adds description of rhs 2025-03-13 09:12:06 +01:00
Jonas Forsberg
3ed5cd92a9 Adds kubectl-deprecated_api 2025-03-13 09:11:47 +01:00
4 changed files with 44 additions and 2 deletions

View File

@@ -12,9 +12,14 @@ 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 |
@@ -23,3 +28,10 @@ Usage:
| KUBECTL_RSH_IMAGE_TAG | latest | Image tag to use |
| KUBECTL_RSH_NAMESPACE | default | Namespace to create the rsh pod in |
| KUBECTL_RSH_POD_CREATE_TIMEOUT | 3 | Minutes to wait before failing to create pod |
## kubectl-deprecated_api
Lists APIs flagged as deprecated
```
Usage:
kubectl deprecated-api
```

7
kubectl-deprecated_api Executable file
View File

@@ -0,0 +1,7 @@
#!/usr/bin/env bash
if ! command -v prom2json > /dev/null; then
echo "You need prom2json to use this command"
exit 1
fi
kubectl get --raw /metrics | prom2json | jq -c '.[] | select(.name=="apiserver_requested_deprecated_apis").metrics[].labels' | column -t -s'{}[],"'

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