feat(actions): add pause action for KEDA ScaledObject and ScaledJob (#25301) (#25302)

Signed-off-by: Rick Brouwer <rickbrouwer@gmail.com>
This commit is contained in:
Rick Brouwer
2025-11-30 10:21:35 +01:00
committed by GitHub
parent 7669da6c3e
commit a64933f11d
17 changed files with 333 additions and 0 deletions

View File

@@ -32,6 +32,11 @@
- [image.toolkit.fluxcd.io/ImageUpdateAutomation/reconcile](https://github.com/argoproj/argo-cd/blob/master/resource_customizations/image.toolkit.fluxcd.io/ImageUpdateAutomation/actions/reconcile/action.lua)
- [image.toolkit.fluxcd.io/ImageUpdateAutomation/resume](https://github.com/argoproj/argo-cd/blob/master/resource_customizations/image.toolkit.fluxcd.io/ImageUpdateAutomation/actions/resume/action.lua)
- [image.toolkit.fluxcd.io/ImageUpdateAutomation/suspend](https://github.com/argoproj/argo-cd/blob/master/resource_customizations/image.toolkit.fluxcd.io/ImageUpdateAutomation/actions/suspend/action.lua)
- [keda.sh/ScaledJob/pause](https://github.com/argoproj/argo-cd/blob/master/resource_customizations/keda.sh/ScaledJob/actions/pause/action.lua)
- [keda.sh/ScaledJob/resume](https://github.com/argoproj/argo-cd/blob/master/resource_customizations/keda.sh/ScaledJob/actions/resume/action.lua)
- [keda.sh/ScaledObject/pause](https://github.com/argoproj/argo-cd/blob/master/resource_customizations/keda.sh/ScaledObject/actions/pause/action.lua)
- [keda.sh/ScaledObject/paused-replicas](https://github.com/argoproj/argo-cd/blob/master/resource_customizations/keda.sh/ScaledObject/actions/paused-replicas/action.lua)
- [keda.sh/ScaledObject/resume](https://github.com/argoproj/argo-cd/blob/master/resource_customizations/keda.sh/ScaledObject/actions/resume/action.lua)
- [kustomize.toolkit.fluxcd.io/Kustomization/reconcile](https://github.com/argoproj/argo-cd/blob/master/resource_customizations/kustomize.toolkit.fluxcd.io/Kustomization/actions/reconcile/action.lua)
- [kustomize.toolkit.fluxcd.io/Kustomization/resume](https://github.com/argoproj/argo-cd/blob/master/resource_customizations/kustomize.toolkit.fluxcd.io/Kustomization/actions/resume/action.lua)
- [kustomize.toolkit.fluxcd.io/Kustomization/suspend](https://github.com/argoproj/argo-cd/blob/master/resource_customizations/kustomize.toolkit.fluxcd.io/Kustomization/actions/suspend/action.lua)

View File

@@ -0,0 +1,37 @@
discoveryTests:
- inputPath: testdata/scaledjob.yaml
result:
- name: pause
disabled: false
iconClass: fa fa-fw fa-pause-circle
- name: resume
disabled: true
iconClass: fa fa-fw fa-play-circle
- inputPath: testdata/scaledjob-pause.yaml
result:
- name: pause
disabled: true
iconClass: fa fa-fw fa-pause-circle
- name: resume
disabled: false
iconClass: fa fa-fw fa-play-circle
- inputPath: testdata/scaledjob-resume.yaml
result:
- name: pause
disabled: false
iconClass: fa fa-fw fa-pause-circle
- name: resume
disabled: true
iconClass: fa fa-fw fa-play-circle
actionTests:
- action: pause
inputPath: testdata/scaledjob.yaml
expectedOutputPath: testdata/scaledjob-pause.yaml
- action: resume
inputPath: testdata/scaledjob-pause.yaml
expectedOutputPath: testdata/scaledjob-resume.yaml

View File

@@ -0,0 +1,18 @@
local actions = {}
local paused = false
if obj.metadata and obj.metadata.annotations then
paused = obj.metadata.annotations["autoscaling.keda.sh/paused"] == "true"
end
actions["pause"] = {
["disabled"] = paused,
["iconClass"] = "fa fa-fw fa-pause-circle"
}
actions["resume"] = {
["disabled"] = not paused,
["iconClass"] = "fa fa-fw fa-play-circle"
}
return actions

View File

@@ -0,0 +1,7 @@
local obj = obj or {}
if obj.metadata == nil then obj.metadata = {} end
if obj.metadata.annotations == nil then obj.metadata.annotations = {} end
obj.metadata.annotations["autoscaling.keda.sh/paused"] = "true"
return obj

View File

@@ -0,0 +1,6 @@
local obj = obj or {}
if obj.metadata and obj.metadata.annotations then
obj.metadata.annotations["autoscaling.keda.sh/paused"] = nil
end
return obj

View File

@@ -0,0 +1,20 @@
apiVersion: keda.sh/v1alpha1
kind: ScaledJob
metadata:
name: test-scaledjob
annotations:
autoscaling.keda.sh/paused: "true"
spec:
jobTargetRef:
template:
spec:
containers:
- name: test
image: test:latest
triggers:
- metadata:
host: amqp://localhost:5672/vhost
mode: QueueLength
queueName: hello
value: '1'
type: rabbitmq

View File

@@ -0,0 +1,18 @@
apiVersion: keda.sh/v1alpha1
kind: ScaledJob
metadata:
name: test-scaledjob
spec:
jobTargetRef:
template:
spec:
containers:
- name: test
image: test:latest
triggers:
- metadata:
host: amqp://localhost:5672/vhost
mode: QueueLength
queueName: hello
value: '1'
type: rabbitmq

View File

@@ -0,0 +1,18 @@
apiVersion: keda.sh/v1alpha1
kind: ScaledJob
metadata:
name: test-scaledjob
spec:
jobTargetRef:
template:
spec:
containers:
- name: test
image: test:latest
triggers:
- metadata:
host: amqp://localhost:5672/vhost
mode: QueueLength
queueName: hello
value: '1'
type: rabbitmq

View File

@@ -0,0 +1,86 @@
discoveryTests:
- inputPath: testdata/scaledobject.yaml
result:
- name: pause
disabled: false
iconClass: fa fa-fw fa-pause-circle
- name: paused-replicas
disabled: false
iconClass: fa fa-fw fa-pause-circle
params:
- name: replicas
default: "0"
- name: resume
disabled: true
iconClass: fa fa-fw fa-play-circle
- inputPath: testdata/scaledobject-pause.yaml
result:
- name: pause
disabled: true
iconClass: fa fa-fw fa-pause-circle
- name: paused-replicas
disabled: true
iconClass: fa fa-fw fa-pause-circle
params:
- name: replicas
default: "0"
- name: resume
disabled: false
iconClass: fa fa-fw fa-play-circle
- inputPath: testdata/scaledobject-paused-replicas.yaml
result:
- name: pause
disabled: true
iconClass: fa fa-fw fa-pause-circle
- name: paused-replicas
disabled: false
iconClass: fa fa-fw fa-pause-circle
params:
- name: replicas
default: "0"
- name: resume
disabled: false
iconClass: fa fa-fw fa-play-circle
- inputPath: testdata/scaledobject-resume.yaml
result:
- name: pause
disabled: false
iconClass: fa fa-fw fa-pause-circle
- name: paused-replicas
disabled: false
iconClass: fa fa-fw fa-pause-circle
params:
- name: replicas
default: "0"
- name: resume
disabled: true
iconClass: fa fa-fw fa-play-circle
actionTests:
- action: pause
inputPath: testdata/scaledobject.yaml
expectedOutputPath: testdata/scaledobject-pause.yaml
- action: resume
inputPath: testdata/scaledobject-pause.yaml
expectedOutputPath: testdata/scaledobject-resume.yaml
- action: paused-replicas
inputPath: testdata/scaledobject.yaml
expectedOutputPath: testdata/scaledobject-paused-replicas.yaml
parameters:
replicas: "6"
- action: paused-replicas
inputPath: testdata/scaledobject.yaml
expectedErrorMessage: "invalid number: not_a_number (must be >= 0)"
parameters:
replicas: "not_a_number"
- action: resume
inputPath: testdata/scaledobject-paused-replicas.yaml
expectedOutputPath: testdata/scaledobject-resume.yaml

View File

@@ -0,0 +1,35 @@
local actions = {}
local paused = false
local hasPausedReplicas = false
local currentPausedReplicas = nil
if obj.metadata and obj.metadata.annotations then
paused = obj.metadata.annotations["autoscaling.keda.sh/paused"] == "true"
currentPausedReplicas = obj.metadata.annotations["autoscaling.keda.sh/paused-replicas"]
hasPausedReplicas = currentPausedReplicas ~= nil
end
local isPaused = paused or hasPausedReplicas
actions["pause"] = {
["disabled"] = isPaused,
["iconClass"] = "fa fa-fw fa-pause-circle"
}
actions["paused-replicas"] = {
["disabled"] = paused,
["iconClass"] = "fa fa-fw fa-pause-circle",
["params"] = {
{
["name"] = "replicas",
["default"] = currentPausedReplicas or "0"
}
},
}
actions["resume"] = {
["disabled"] = not isPaused,
["iconClass"] = "fa fa-fw fa-play-circle"
}
return actions

View File

@@ -0,0 +1,7 @@
local obj = obj or {}
if obj.metadata == nil then obj.metadata = {} end
if obj.metadata.annotations == nil then obj.metadata.annotations = {} end
obj.metadata.annotations["autoscaling.keda.sh/paused"] = "true"
return obj

View File

@@ -0,0 +1,17 @@
local obj = obj or {}
if obj.metadata == nil then obj.metadata = {} end
if obj.metadata.annotations == nil then obj.metadata.annotations = {} end
local replicas = actionParams["replicas"]
if not replicas then
error("replicas parameter is required", 0)
end
local replicasNum = tonumber(replicas)
if not replicasNum or replicasNum < 0 then
error("invalid number: " .. replicas .. " (must be >= 0)", 0)
end
obj.metadata.annotations["autoscaling.keda.sh/paused-replicas"] = tostring(replicasNum)
return obj

View File

@@ -0,0 +1,7 @@
local obj = obj or {}
if obj.metadata and obj.metadata.annotations then
obj.metadata.annotations["autoscaling.keda.sh/paused"] = nil
obj.metadata.annotations["autoscaling.keda.sh/paused-replicas"] = nil
end
return obj

View File

@@ -0,0 +1,14 @@
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: test-scaledobject
annotations:
autoscaling.keda.sh/paused: "true"
spec:
scaleTargetRef:
name: test-deployment
triggers:
- type: cpu
metadata:
type: Utilization
value: "50"

View File

@@ -0,0 +1,14 @@
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: test-scaledobject
annotations:
autoscaling.keda.sh/paused-replicas: "6"
spec:
scaleTargetRef:
name: test-deployment
triggers:
- type: cpu
metadata:
type: Utilization
value: "50"

View File

@@ -0,0 +1,12 @@
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: test-scaledobject
spec:
scaleTargetRef:
name: test-deployment
triggers:
- type: cpu
metadata:
type: Utilization
value: "50"

View File

@@ -0,0 +1,12 @@
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: test-scaledobject
spec:
scaleTargetRef:
name: test-deployment
triggers:
- type: cpu
metadata:
type: Utilization
value: "50"