forked from gianlucam76/k8s-cleaner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresume.yaml
72 lines (66 loc) · 1.8 KB
/
resume.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# This cleaner:
# - runs at 8AM every day
# - finds all Deployments/StatefulSet/DaemonSet with
# annotation "pause-resume"
#
# For any such resource:
# - get old replicas in the annotation "previous-replicas"
# - set their replicas to such value (scale deployment/statefulset/daemonset up)
#
apiVersion: apps.projectsveltos.io/v1alpha1
kind: Cleaner
metadata:
name: scale-up-deployment-statefulset-daemonset
spec:
schedule: "* 8 * * *"
action: Transform
transform: |
-- Set replicas to 0
function transform()
hs = {}
if obj.metadata.annotations == nil then
return
end
if not obj.metadata.annotations["previous-replicas"] then
return
end
-- reset replicas
obj.spec.replicas = tonumber(obj.metadata.annotations["previous-replicas"])
hs.resource = obj
return hs
end
resourcePolicySet:
resourceSelectors:
- kind: Deployment
group: apps
version: v1
- kind: StatefulSet
group: "apps"
version: v1
- kind: DaemonSet
group: "apps"
version: v1
aggregatedSelection: |
function evaluate()
local hs = {}
-- returns true if object has annotaiton "pause-resume"
function hasPauseAnnotation(obj)
if obj.metadata.annotations ~= nil then
if obj.metadata.annotations["pause-resume"] then
return true
end
return false
end
return false
end
local resourceToUnPause = {}
for _, resource in ipairs(resources) do
if hasPauseAnnotation(resource) then
table.insert(resourceToUnPause, {resource = resource})
end
end
if #resourceToUnPause > 0 then
hs.resources = resourceToUnPause
end
return hs
end