From f139a5700d78c806eb7274bcd9155be44d0d5b62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20Kopeck=C3=BD?= Date: Mon, 14 Oct 2024 17:17:20 +0200 Subject: [PATCH] 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 * chore: Fix table formating Signed-off-by: SamoKopecky --------- Signed-off-by: SamoKopecky --- plugins/README.md | 28 ++++++++++++++++------------ plugins/keda-toggle.yaml | 26 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 plugins/keda-toggle.yaml diff --git a/plugins/README.md b/plugins/README.md index 8d487154..8b947f6d 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -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. -| Plugin-Name | Description | Available on Views | Shortcut | Kubectl plugin, external dependencies | -|--------------------|------------------------------------------------------------------|--------------------------|----------|---------------------------------------------------------------------------------------| -| debug-container.yml| Add [ephemeral debug container][1]
([nicolaka/netshoot][2]) | containers | Shift-d | | -| 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/) | -| 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/) | -| 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_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 | | -| 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) | +| Plugin-Name | Description | Available on Views | Shortcut | Kubectl plugin, external dependencies | +| ------------------------------ | ---------------------------------------------------------------------------- | ----------------------------------- | --------- | ------------------------------------------------------------------------------------- | +| debug-container.yml | Add [ephemeral debug container](1)
([nicolaka/netshoot](2)) | containers | Shift-d | | +| 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/) | +| 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/) | +| 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_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 | | +| 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 [2]: https://github.com/nicolaka/netshoot +[3]: https://keda.sh/ diff --git a/plugins/keda-toggle.yaml b/plugins/keda-toggle.yaml new file mode 100644 index 00000000..a4370c0f --- /dev/null +++ b/plugins/keda-toggle.yaml @@ -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 + +