feat(2896): Add toggle keda plugin (#2897)

* feat(2896): Add toggle keda plugin

Also update formating of plugins readme table and fix links

Signed-off-by: SamoKopecky <sano.kopecky@gmail.com>

* chore: Fix table formating

Signed-off-by: SamoKopecky <sano.kopecky@gmail.com>

---------

Signed-off-by: SamoKopecky <sano.kopecky@gmail.com>
mine
Samuel Kopecký 2024-10-14 17:17:20 +02:00 committed by GitHub
parent 42bc8fcaac
commit f139a5700d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 42 additions and 12 deletions

View File

@ -4,17 +4,21 @@ K9s plugins extend the tool to provide additional functionality via actions to f
Following is an example of some of plugin files in this directory. Other files are not listed in this table. Following is an example of some of plugin files in this directory. Other files are not listed in this table.
| Plugin-Name | Description | Available on Views | Shortcut | Kubectl plugin, external dependencies | | Plugin-Name | Description | Available on Views | Shortcut | Kubectl plugin, external dependencies |
|--------------------|------------------------------------------------------------------|--------------------------|----------|---------------------------------------------------------------------------------------| | ------------------------------ | ---------------------------------------------------------------------------- | ----------------------------------- | --------- | ------------------------------------------------------------------------------------- |
| debug-container.yml| Add [ephemeral debug container][1]<br>([nicolaka/netshoot][2]) | containers | Shift-d | | | debug-container.yml | Add [ephemeral debug container](1)<br>([nicolaka/netshoot](2)) | containers | Shift-d | |
| dive.yml | Dive image layers | containers | d | [Dive](https://github.com/wagoodman/dive) | | dive.yml | Dive image layers | containers | d | [Dive](https://github.com/wagoodman/dive) |
| get-all.yml | get all resources in a namespace | all | g | [Krew](https://krew.sigs.k8s.io/), [ketall](https://github.com/corneliusweig/ketall/) | | get-all.yml | get all resources in a namespace | all | g | [Krew](https://krew.sigs.k8s.io/), [ketall](https://github.com/corneliusweig/ketall/) |
| job_suspend.yml | Suspends a running cronjob | cronjobs | Ctrl-s | | | job_suspend.yml | Suspends a running cronjob | cronjobs | Ctrl-s | |
| k3d_root_shell.yml | Root shell to k3d container | containers | Shift-s | [jq](https://stedolan.github.io/jq/) | | k3d_root_shell.yml | Root shell to k3d container | containers | Shift-s | [jq](https://stedolan.github.io/jq/) |
| resource-recommendations.yml | View recommendations for CPU/Memory requests based on historical data | deployments/daemonsets/statefulsets | Shift-k | [Robusta KRR](https://github.com/robusta-dev/krr) | | resource-recommendations.yml | View recommendations for CPU/Memory requests based on historical data | deployments/daemonsets/statefulsets | Shift-k | [Robusta KRR](https://github.com/robusta-dev/krr) |
| log_stern.yml | View resource logs using stern | pods | Ctrl-l | | | log_stern.yml | View resource logs using stern | pods | Ctrl-l | |
| log_jq.yml | View resource logs using jq | pods | Ctrl-j | kubectl-plugins/kubectl-jq | | log_jq.yml | View resource logs using jq | pods | Ctrl-j | kubectl-plugins/kubectl-jq |
| log_full.yml | get full logs from pod/container | pods/containers | Ctrl-l | | | log_full.yml | get full logs from pod/container | pods/containers | Ctrl-l | |
| ai-incident-investigation.yaml | Run AI investigation on application issues to find the root cause in seconds | all | Shift-h/o | [HolmesGPT](https://github.com/robusta-dev/holmesgpt) | | ai-incident-investigation.yaml | Run AI investigation on application issues to find the root cause in seconds | all | Shift-h/o | [HolmesGPT](https://github.com/robusta-dev/holmesgpt) |
| toggle-keda | Enable/disable [keda](3) ScaledObject autoscaler | scaledobjects | Ctrl-N | |
[1]: https://kubernetes.io/docs/tasks/debug/debug-application/debug-running-pod/#ephemeral-container [1]: https://kubernetes.io/docs/tasks/debug/debug-application/debug-running-pod/#ephemeral-container
[2]: https://github.com/nicolaka/netshoot [2]: https://github.com/nicolaka/netshoot
[3]: https://keda.sh/

26
plugins/keda-toggle.yaml Normal file
View File

@ -0,0 +1,26 @@
plugins:
toggle-keda:
shortCut: Ctrl-N
override: false
overwriteOutput: true
confirm: false
dangerous: true
description: Toggle autoscaling on keda scaledobject
scopes:
- scaledobjects
command: bash
background: true
args:
- -c
- |
ANNOTATION="autoscaling.keda.sh/paused-replicas"
if kubectl get scaledobject $NAME -n $NAMESPACE -o yaml | grep -q "$ANNOTATION: \"0\""; then
# If annotation found, remove it
kubectl annotate scaledobject $NAME "$ANNOTATION"- -n $NAMESPACE --context $CONTEXT >/dev/null && echo "Keda autoscaling for $NAME enabled"
else
# If annotation not found, add it
kubectl annotate scaledobject $NAME "$ANNOTATION"=0 -n $NAMESPACE --context $CONTEXT >/dev/null && echo "Keda autoscaling for $NAME disabled"
fi