Skip to content

Commit a64933f

Browse files
authored
feat(actions): add pause action for KEDA ScaledObject and ScaledJob (argoproj#25301) (argoproj#25302)
Signed-off-by: Rick Brouwer <rickbrouwer@gmail.com>
1 parent 7669da6 commit a64933f

File tree

17 files changed

+333
-0
lines changed

17 files changed

+333
-0
lines changed

docs/operator-manual/resource_actions_builtin.md

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
discoveryTests:
2+
- inputPath: testdata/scaledjob.yaml
3+
result:
4+
- name: pause
5+
disabled: false
6+
iconClass: fa fa-fw fa-pause-circle
7+
- name: resume
8+
disabled: true
9+
iconClass: fa fa-fw fa-play-circle
10+
11+
- inputPath: testdata/scaledjob-pause.yaml
12+
result:
13+
- name: pause
14+
disabled: true
15+
iconClass: fa fa-fw fa-pause-circle
16+
- name: resume
17+
disabled: false
18+
iconClass: fa fa-fw fa-play-circle
19+
20+
- inputPath: testdata/scaledjob-resume.yaml
21+
result:
22+
- name: pause
23+
disabled: false
24+
iconClass: fa fa-fw fa-pause-circle
25+
- name: resume
26+
disabled: true
27+
iconClass: fa fa-fw fa-play-circle
28+
29+
actionTests:
30+
- action: pause
31+
inputPath: testdata/scaledjob.yaml
32+
expectedOutputPath: testdata/scaledjob-pause.yaml
33+
34+
- action: resume
35+
inputPath: testdata/scaledjob-pause.yaml
36+
expectedOutputPath: testdata/scaledjob-resume.yaml
37+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
local actions = {}
2+
local paused = false
3+
4+
if obj.metadata and obj.metadata.annotations then
5+
paused = obj.metadata.annotations["autoscaling.keda.sh/paused"] == "true"
6+
end
7+
8+
actions["pause"] = {
9+
["disabled"] = paused,
10+
["iconClass"] = "fa fa-fw fa-pause-circle"
11+
}
12+
13+
actions["resume"] = {
14+
["disabled"] = not paused,
15+
["iconClass"] = "fa fa-fw fa-play-circle"
16+
}
17+
18+
return actions
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
local obj = obj or {}
2+
if obj.metadata == nil then obj.metadata = {} end
3+
if obj.metadata.annotations == nil then obj.metadata.annotations = {} end
4+
5+
obj.metadata.annotations["autoscaling.keda.sh/paused"] = "true"
6+
7+
return obj
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
local obj = obj or {}
2+
if obj.metadata and obj.metadata.annotations then
3+
obj.metadata.annotations["autoscaling.keda.sh/paused"] = nil
4+
end
5+
6+
return obj
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: keda.sh/v1alpha1
2+
kind: ScaledJob
3+
metadata:
4+
name: test-scaledjob
5+
annotations:
6+
autoscaling.keda.sh/paused: "true"
7+
spec:
8+
jobTargetRef:
9+
template:
10+
spec:
11+
containers:
12+
- name: test
13+
image: test:latest
14+
triggers:
15+
- metadata:
16+
host: amqp://localhost:5672/vhost
17+
mode: QueueLength
18+
queueName: hello
19+
value: '1'
20+
type: rabbitmq
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: keda.sh/v1alpha1
2+
kind: ScaledJob
3+
metadata:
4+
name: test-scaledjob
5+
spec:
6+
jobTargetRef:
7+
template:
8+
spec:
9+
containers:
10+
- name: test
11+
image: test:latest
12+
triggers:
13+
- metadata:
14+
host: amqp://localhost:5672/vhost
15+
mode: QueueLength
16+
queueName: hello
17+
value: '1'
18+
type: rabbitmq
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: keda.sh/v1alpha1
2+
kind: ScaledJob
3+
metadata:
4+
name: test-scaledjob
5+
spec:
6+
jobTargetRef:
7+
template:
8+
spec:
9+
containers:
10+
- name: test
11+
image: test:latest
12+
triggers:
13+
- metadata:
14+
host: amqp://localhost:5672/vhost
15+
mode: QueueLength
16+
queueName: hello
17+
value: '1'
18+
type: rabbitmq
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
discoveryTests:
2+
- inputPath: testdata/scaledobject.yaml
3+
result:
4+
- name: pause
5+
disabled: false
6+
iconClass: fa fa-fw fa-pause-circle
7+
- name: paused-replicas
8+
disabled: false
9+
iconClass: fa fa-fw fa-pause-circle
10+
params:
11+
- name: replicas
12+
default: "0"
13+
- name: resume
14+
disabled: true
15+
iconClass: fa fa-fw fa-play-circle
16+
17+
- inputPath: testdata/scaledobject-pause.yaml
18+
result:
19+
- name: pause
20+
disabled: true
21+
iconClass: fa fa-fw fa-pause-circle
22+
- name: paused-replicas
23+
disabled: true
24+
iconClass: fa fa-fw fa-pause-circle
25+
params:
26+
- name: replicas
27+
default: "0"
28+
- name: resume
29+
disabled: false
30+
iconClass: fa fa-fw fa-play-circle
31+
32+
- inputPath: testdata/scaledobject-paused-replicas.yaml
33+
result:
34+
- name: pause
35+
disabled: true
36+
iconClass: fa fa-fw fa-pause-circle
37+
- name: paused-replicas
38+
disabled: false
39+
iconClass: fa fa-fw fa-pause-circle
40+
params:
41+
- name: replicas
42+
default: "0"
43+
- name: resume
44+
disabled: false
45+
iconClass: fa fa-fw fa-play-circle
46+
47+
- inputPath: testdata/scaledobject-resume.yaml
48+
result:
49+
- name: pause
50+
disabled: false
51+
iconClass: fa fa-fw fa-pause-circle
52+
- name: paused-replicas
53+
disabled: false
54+
iconClass: fa fa-fw fa-pause-circle
55+
params:
56+
- name: replicas
57+
default: "0"
58+
- name: resume
59+
disabled: true
60+
iconClass: fa fa-fw fa-play-circle
61+
62+
actionTests:
63+
- action: pause
64+
inputPath: testdata/scaledobject.yaml
65+
expectedOutputPath: testdata/scaledobject-pause.yaml
66+
67+
- action: resume
68+
inputPath: testdata/scaledobject-pause.yaml
69+
expectedOutputPath: testdata/scaledobject-resume.yaml
70+
71+
- action: paused-replicas
72+
inputPath: testdata/scaledobject.yaml
73+
expectedOutputPath: testdata/scaledobject-paused-replicas.yaml
74+
parameters:
75+
replicas: "6"
76+
77+
- action: paused-replicas
78+
inputPath: testdata/scaledobject.yaml
79+
expectedErrorMessage: "invalid number: not_a_number (must be >= 0)"
80+
parameters:
81+
replicas: "not_a_number"
82+
83+
- action: resume
84+
inputPath: testdata/scaledobject-paused-replicas.yaml
85+
expectedOutputPath: testdata/scaledobject-resume.yaml
86+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
local actions = {}
2+
local paused = false
3+
local hasPausedReplicas = false
4+
local currentPausedReplicas = nil
5+
6+
if obj.metadata and obj.metadata.annotations then
7+
paused = obj.metadata.annotations["autoscaling.keda.sh/paused"] == "true"
8+
currentPausedReplicas = obj.metadata.annotations["autoscaling.keda.sh/paused-replicas"]
9+
hasPausedReplicas = currentPausedReplicas ~= nil
10+
end
11+
12+
local isPaused = paused or hasPausedReplicas
13+
14+
actions["pause"] = {
15+
["disabled"] = isPaused,
16+
["iconClass"] = "fa fa-fw fa-pause-circle"
17+
}
18+
19+
actions["paused-replicas"] = {
20+
["disabled"] = paused,
21+
["iconClass"] = "fa fa-fw fa-pause-circle",
22+
["params"] = {
23+
{
24+
["name"] = "replicas",
25+
["default"] = currentPausedReplicas or "0"
26+
}
27+
},
28+
}
29+
30+
actions["resume"] = {
31+
["disabled"] = not isPaused,
32+
["iconClass"] = "fa fa-fw fa-play-circle"
33+
}
34+
35+
return actions

0 commit comments

Comments
 (0)