-
Notifications
You must be signed in to change notification settings - Fork 2
/
hitman.yaml
71 lines (51 loc) · 2.05 KB
/
hitman.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
version: v1alpha1
kind: Hitman
metadata:
name: killing-sample
spec:
synchronization:
time: 1m
resources:
- target:
group: ""
version: v1
resource: pods
# Select the resources by their name
# Choose one of the following options
name:
matchRegex: ^(coredns-)
#matchExact: "coredns-xxxxxxxxxx-yyyyy"
# Select the namespace where the resources are located
# Choose one of the following options
namespace:
matchRegex: ^(kube-system)
#matchExact: kube-system
# (Optional) Define a preStep to TODO
preStep: |
{{ $retrievedTargets := .targets }}
{{/* Define a variable to store the processed targets */}}
{{ $processedTargets := slice }}
{{/* Loop through the retrieved targets */}}
{{ range $i, $target := $retrievedTargets }}
{{/* Do something with the target */}}
{{ $processedTarget := $target }}
{{/* Save the processed target */}}
{{ $processedTargets = append $processedTargets $processedTarget }}
{{ end }}
{{/* Save the processed targets in a variable for later usage */}}
{{ setVar "example" $processedTargets }}
conditions:
# Delete the resources when they are older than 10 minutes
- key: |-
{{/* Retrieve a previously defined variable if needed */}}
{{ $processedTargets := .vars.example }}
{{ $object := .object }}
{{/* Define some variables */}}
{{- $maxAgeMinutes := 10 -}}
{{- $nowTimestamp := (now | unixEpoch) -}}
{{- $podStartTime := (toDate "2006-01-02T15:04:05Z07:00" .object.status.startTime) | unixEpoch -}}
{{/* Calculate the age of the resource in minutes */}}
{{- $minutedFromNow := int (round (div (sub $nowTimestamp $podStartTime) 60) 0) -}}
{{/* Print true ONLY if the resource is older than 5 minutes */}}
{{- printf "%v" (ge $minutedFromNow $maxAgeMinutes) -}}
value: true