forked from gianlucam76/k8s-cleaner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpause.yaml
74 lines (65 loc) · 1.81 KB
/
pause.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
73
74
# This cleaner:
# - runs at 8PM every day
# - finds all Deployments/StatefulSet/DaemonSet with
# annotation "pause-resume"
#
# For any such resource:
# - store current replicas in the annotation "previous-replicas"
# - set their replicas to zero (scale down and pause)
#
apiVersion: apps.projectsveltos.io/v1alpha1
kind: Cleaner
metadata:
name: scale-down-deployment-statefulset-daemonset
spec:
schedule: "* 20 * * *"
action: Transform
transform: |
-- Set replicas to 0
function transform()
hs = {}
if obj.metadata.annotations == nil then
obj.metadata.annotations = {}
end
-- store in the annotation current replicas value
obj.metadata.annotations["previous-replicas"] = tostring(obj.spec.replicas)
-- reset replicas to 0
obj.spec.replicas = 0
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
end
local resourceToPause = {}
for _, resource in ipairs(resources) do
if hasPauseAnnotation(resource) then
table.insert(resourceToPause, {resource = resource})
end
end
if #resourceToPause > 0 then
hs.resources = resourceToPause
end
return hs
end