Skip to content

Commit b5bb15a

Browse files
committed
[1732] chore: add cronjob/job labels and annotations to helm chart
Signed-off-by: Nikita B <[email protected]>
1 parent 94d1825 commit b5bb15a

File tree

4 files changed

+139
-0
lines changed

4 files changed

+139
-0
lines changed

charts/descheduler/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ The following table lists the configurable parameters of the _descheduler_ chart
7070
| `serviceAccount.create` | If `true`, create a service account for the cron job | `true` |
7171
| `serviceAccount.name` | The name of the service account to use, if not set and create is true a name is generated using the fullname template | `nil` |
7272
| `serviceAccount.annotations` | Specifies custom annotations for the serviceAccount | `{}` |
73+
| `cronJobAnnotations` | Annotations to add to the descheduler CronJob | `{}` |
74+
| `cronJobLabels` | Labels to add to the descheduler CronJob | `{}` |
75+
| `jobAnnotations` | Annotations to add to the descheduler Job resources (created by CronJob) | `{}` |
76+
| `jobLabels` | Labels to add to the descheduler Job resources (created by CronJob) | `{}` |
7377
| `podAnnotations` | Annotations to add to the descheduler Pods | `{}` |
7478
| `podLabels` | Labels to add to the descheduler Pods | `{}` |
7579
| `nodeSelector` | Node selectors to run the descheduler cronjob/deployment on specific nodes | `nil` |

charts/descheduler/templates/cronjob.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@ kind: CronJob
44
metadata:
55
name: {{ template "descheduler.fullname" . }}
66
namespace: {{ include "descheduler.namespace" . }}
7+
{{- if .Values.cronJobAnnotations }}
8+
annotations:
9+
{{- .Values.cronJobAnnotations | toYaml | nindent 4 }}
10+
{{- end }}
711
labels:
812
{{- include "descheduler.labels" . | nindent 4 }}
13+
{{- if .Values.cronJobLabels }}
14+
{{- .Values.cronJobLabels | toYaml | nindent 4 }}
15+
{{- end }}
916
spec:
1017
schedule: {{ .Values.schedule | quote }}
1118
{{- if .Values.suspend }}
@@ -25,6 +32,17 @@ spec:
2532
timeZone: {{ .Values.timeZone }}
2633
{{- end }}
2734
jobTemplate:
35+
{{- if or .Values.jobAnnotations .Values.jobLabels }}
36+
metadata:
37+
{{- if .Values.jobAnnotations }}
38+
annotations:
39+
{{- .Values.jobAnnotations | toYaml | nindent 8 }}
40+
{{- end }}
41+
{{- if .Values.jobLabels }}
42+
labels:
43+
{{- .Values.jobLabels | toYaml | nindent 8 }}
44+
{{- end }}
45+
{{- end }}
2846
spec:
2947
{{- if .Values.ttlSecondsAfterFinished }}
3048
ttlSecondsAfterFinished: {{ .Values.ttlSecondsAfterFinished }}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
suite: Test Descheduler CronJob and Job Annotations and Labels
2+
3+
templates:
4+
- "*.yaml"
5+
6+
release:
7+
name: descheduler
8+
9+
set:
10+
kind: CronJob
11+
12+
tests:
13+
- it: adds cronJob and job annotations and labels when set
14+
template: templates/cronjob.yaml
15+
set:
16+
cronJobAnnotations:
17+
monitoring.company.com/scrape: "true"
18+
description: "test cronjob"
19+
cronJobLabels:
20+
environment: "test"
21+
team: "platform"
22+
jobAnnotations:
23+
sidecar.istio.io/inject: "false"
24+
job.company.com/retry-limit: "3"
25+
jobLabels:
26+
job-type: "maintenance"
27+
priority: "high"
28+
asserts:
29+
- equal:
30+
path: metadata.annotations["monitoring.company.com/scrape"]
31+
value: "true"
32+
- equal:
33+
path: metadata.annotations.description
34+
value: "test cronjob"
35+
- equal:
36+
path: metadata.labels.environment
37+
value: "test"
38+
- equal:
39+
path: metadata.labels.team
40+
value: "platform"
41+
- equal:
42+
path: spec.jobTemplate.metadata.annotations["sidecar.istio.io/inject"]
43+
value: "false"
44+
- equal:
45+
path: spec.jobTemplate.metadata.annotations["job.company.com/retry-limit"]
46+
value: "3"
47+
- equal:
48+
path: spec.jobTemplate.metadata.labels.job-type
49+
value: "maintenance"
50+
- equal:
51+
path: spec.jobTemplate.metadata.labels.priority
52+
value: "high"
53+
54+
- it: does not add cronJob and job metadata when not set
55+
template: templates/cronjob.yaml
56+
asserts:
57+
- isNull:
58+
path: metadata.annotations
59+
- isNotNull:
60+
path: metadata.labels
61+
- equal:
62+
path: metadata.labels["app.kubernetes.io/name"]
63+
value: descheduler
64+
- isNull:
65+
path: spec.jobTemplate.metadata
66+
67+
- it: does not add job metadata when job annotations and labels are empty
68+
template: templates/cronjob.yaml
69+
set:
70+
jobAnnotations: {}
71+
jobLabels: {}
72+
asserts:
73+
- isNull:
74+
path: spec.jobTemplate.metadata
75+
76+
- it: works with all annotation and label types together
77+
template: templates/cronjob.yaml
78+
set:
79+
cronJobAnnotations:
80+
cron-annotation: "cron-value"
81+
cronJobLabels:
82+
cron-label: "cron-value"
83+
jobAnnotations:
84+
job-annotation: "job-value"
85+
jobLabels:
86+
job-label: "job-value"
87+
podAnnotations:
88+
pod-annotation: "pod-value"
89+
podLabels:
90+
pod-label: "pod-value"
91+
asserts:
92+
- equal:
93+
path: metadata.annotations.cron-annotation
94+
value: "cron-value"
95+
- equal:
96+
path: metadata.labels.cron-label
97+
value: "cron-value"
98+
- equal:
99+
path: spec.jobTemplate.metadata.annotations.job-annotation
100+
value: "job-value"
101+
- equal:
102+
path: spec.jobTemplate.metadata.labels.job-label
103+
value: "job-value"
104+
- equal:
105+
path: spec.jobTemplate.spec.template.metadata.annotations.pod-annotation
106+
value: "pod-value"
107+
- equal:
108+
path: spec.jobTemplate.spec.template.metadata.labels.pod-label
109+
value: "pod-value"

charts/descheduler/values.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,14 @@ serviceAccount:
204204
# Default is not set - but only implied by the ServiceAccount
205205
# automountServiceAccountToken: true
206206

207+
cronJobAnnotations: {}
208+
209+
cronJobLabels: {}
210+
211+
jobAnnotations: {}
212+
213+
jobLabels: {}
214+
207215
podAnnotations: {}
208216

209217
podLabels: {}

0 commit comments

Comments
 (0)