Skip to content

Commit fa635f9

Browse files
feat(cf-common): add cronjob template (#31)
1 parent f159d57 commit fa635f9

37 files changed

+526
-227
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/quintush/helm-unittest/master/schema/helm-testsuite.json
2+
suite: cronjob metadata
3+
templates:
4+
- templates/controller.yaml
5+
tests:
6+
- it: Test cronjob default metadata
7+
values:
8+
- values.yaml
9+
asserts:
10+
- hasDocuments:
11+
count: 1
12+
- isKind:
13+
of: CronJob
14+
- isNull:
15+
path: metadata.annotations
16+
- equal:
17+
path: metadata.labels
18+
value:
19+
app.kubernetes.io/instance: RELEASE-NAME
20+
app.kubernetes.io/managed-by: Helm
21+
app.kubernetes.io/name: cf-common-test
22+
helm.sh/chart: cf-common-test-0.0.0
23+
- equal:
24+
path: metadata.name
25+
value: RELEASE-NAME-cf-common-test
26+
27+
- it: Test cronjob custom metadata
28+
values:
29+
- values.yaml
30+
set:
31+
controller:
32+
labels:
33+
alice: bob
34+
annotations:
35+
foo: bar
36+
asserts:
37+
- hasDocuments:
38+
count: 1
39+
- isKind:
40+
of: CronJob
41+
- equal:
42+
path: metadata.annotations
43+
value:
44+
foo: bar
45+
- equal:
46+
path: metadata.labels
47+
value:
48+
app.kubernetes.io/instance: RELEASE-NAME
49+
app.kubernetes.io/managed-by: Helm
50+
app.kubernetes.io/name: cf-common-test
51+
helm.sh/chart: cf-common-test-0.0.0
52+
alice: bob
53+
54+
- it: Test pod labels and annotations
55+
values:
56+
- values.yaml
57+
set:
58+
podLabels:
59+
alice: bob
60+
podAnnotations:
61+
foo: bar
62+
asserts:
63+
- equal:
64+
path: spec.jobTemplate.spec.template.metadata.labels.alice
65+
value: bob
66+
- equal:
67+
path: spec.jobTemplate.spec.template.metadata.annotations.foo
68+
value: bar
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/quintush/helm-unittest/master/schema/helm-testsuite.json
2+
suite: cronjob spec
3+
templates:
4+
- templates/controller.yaml
5+
values:
6+
- values.yaml
7+
tests:
8+
- it: Test cronjob concurrencyPolicy
9+
asserts:
10+
- equal:
11+
path: spec.concurrencyPolicy
12+
value: Forbid
13+
14+
- it: Test cronjob schedule
15+
asserts:
16+
- equal:
17+
path: spec.schedule
18+
value: "*/3 * * * *"
19+
20+
- it: Test cronjob startingDeadlineSeconds
21+
asserts:
22+
- equal:
23+
path: spec.startingDeadlineSeconds
24+
value: 30
25+
26+
- it: Test cronjob successfulJobsHistory
27+
asserts:
28+
- equal:
29+
path: spec.successfulJobsHistoryLimit
30+
value: 1
31+
32+
- it: Test cronjob failedJobsHistory
33+
asserts:
34+
- equal:
35+
path: spec.failedJobsHistoryLimit
36+
value: 1
37+
38+
- it: Test cronjob ttlSecondsAfterFinished
39+
asserts:
40+
- equal:
41+
path: spec.jobTemplate.spec.ttlSecondsAfterFinished
42+
value: 300
43+
44+
- it: Test cronjob suspend
45+
set:
46+
controller:
47+
cronjob:
48+
suspend: true
49+
asserts:
50+
- equal:
51+
path: spec.suspend
52+
value: true
53+
54+
- it: Test cronjob activeDeadlineSeconds
55+
asserts:
56+
- equal:
57+
path: spec.jobTemplate.spec.activeDeadlineSeconds
58+
value: 100
59+
60+
- it: Test cronjob backoffLimit
61+
asserts:
62+
- equal:
63+
path: spec.jobTemplate.spec.backoffLimit
64+
value: 5
65+
66+
- it: Test cronjob pod restartPolicy
67+
asserts:
68+
- equal:
69+
path: spec.jobTemplate.spec.template.spec.restartPolicy
70+
value: OnFailure
71+
72+
- it: Test cronjob parallelism
73+
asserts:
74+
- equal:
75+
path: spec.jobTemplate.spec.parallelism
76+
value: 3
77+
78+
- it: Test cronjob completions
79+
asserts:
80+
- equal:
81+
path: spec.jobTemplate.spec.completions
82+
value: 12
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# mock values for tests
2+
controller:
3+
enabled: true
4+
type: cronjob
5+
labels: {}
6+
annotations: {}
7+
cronjob:
8+
concurrencyPolicy: Forbid
9+
schedule: "*/3 * * * *"
10+
startingDeadlineSeconds: 30
11+
successfulJobsHistory: 1
12+
failedJobsHistory: 1
13+
ttlSecondsAfterFinished: 300
14+
15+
activeDeadlineSeconds: 100
16+
backoffLimit: 5
17+
completions: 12
18+
parallelism: 3
19+
20+
restartPolicy: OnFailure
21+
22+
container:
23+
image:
24+
registry: docker.io
25+
repository: bitnami/kubectl
26+
tag: latest
27+
pullPolicy: Always
28+
29+
command:
30+
- "/bin/sh"
31+
args:
32+
- "-c"
33+
- "sleep 10"
34+
35+
resources:
36+
limits:
37+
cpu: 100m
38+
memory: 128Mi
39+
requests:
40+
cpu: 100m
41+
memory: 128Mi

charts/cf-common-test/tests/job/metadata_test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ tests:
2424
path: metadata.name
2525
value: RELEASE-NAME-cf-common-test
2626

27-
- it: Test deployment custom metadata
27+
- it: Test job custom metadata
2828
values:
2929
- values.yaml
3030
set:

charts/cf-common/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v2
22
appVersion: v0.0.0
33
description: Codefresh library chart
44
name: cf-common
5-
version: 0.2.0
5+
version: 0.3.0
66
type: library
77
keywords:
88
- codefresh

charts/cf-common/README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Codefresh library chart
44

5-
![Version: 0.2.0](https://img.shields.io/badge/Version-0.2.0-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) ![AppVersion: v0.0.0](https://img.shields.io/badge/AppVersion-v0.0.0-informational?style=flat-square)
5+
![Version: 0.3.0](https://img.shields.io/badge/Version-0.3.0-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) ![AppVersion: v0.0.0](https://img.shields.io/badge/AppVersion-v0.0.0-informational?style=flat-square)
66

77
## Installing the Chart
88

@@ -18,7 +18,7 @@ Include this chart as a dependency in your `Chart.yaml` e.g.
1818
# Chart.yaml
1919
dependencies:
2020
- name: cf-common
21-
version: 0.2.0
21+
version: 0.3.0
2222
repository: https://chartmuseum.codefresh.io/cf-common
2323
```
2424
@@ -63,6 +63,13 @@ dependencies:
6363
| container.volumeMounts | object | `{}` | Set volume mounts for container |
6464
| controller | object | See below | Controller parameters |
6565
| controller.annotations | object | `{}` | Set annotations on controller |
66+
| controller.cronjob.concurrencyPolicy | string | `"Forbid"` | Specifies how to treat concurrent executions of a job that is created by this cron job, valid values are Allow, Forbid or Replace |
67+
| controller.cronjob.failedJobsHistory | int | `1` | The number of failed Jobs to keep |
68+
| controller.cronjob.schedule | string | `"*/20 * * * *"` | Sets the CronJob time when to execute your jobs |
69+
| controller.cronjob.startingDeadlineSeconds | int | `30` | The deadline in seconds for starting the job if it misses its scheduled time for any reason |
70+
| controller.cronjob.successfulJobsHistory | int | `1` | The number of succesful Jobs to keep |
71+
| controller.cronjob.suspend | string | `nil` | This flag tells the controller to suspend subsequent executions, it does not apply to already started executions. Defaults to false. |
72+
| controller.cronjob.ttlSecondsAfterFinished | string | `nil` | If this field is set, ttlSecondsAfterFinished after the Job finishes, it is eligible to be automatically deleted. |
6673
| controller.deployment.rollingUpdate.maxSurge | string | `nil` | Set RollingUpdate max surge (absolute number or percentage) |
6774
| controller.deployment.rollingUpdate.maxUnavailable | string | `nil` | Set RollingUpdate max unavailable (absolute number or percentage) |
6875
| controller.deployment.strategy | string | `nil` | Set deployment upgrade strategy (`RollingUpdate`/`Recreate`) |
@@ -87,7 +94,7 @@ dependencies:
8794
| controller.rollout.canary.steps[0] | object | `{"setWeight":null}` | Sets the ratio of canary ReplicaSet in percentage. |
8895
| controller.rollout.canary.steps[1] | object | `{"pause":{"duration":null}}` | Pauses the rollout for configured duration of time. Supported units: s, m, h. when setting `duration: {}` it will pauses indefinitely until manually resumed |
8996
| controller.rollout.strategy | string | `nil` | Rollout update strategy - can be Canary or BlueGreen. |
90-
| controller.type | string | `""` | Define the controller type (`deployment`/`rollout`/`job`) |
97+
| controller.type | string | `""` | Define the controller type (`deployment`/`rollout`/`job`/`cronjob`) |
9198
| extraResources | list | `[]` | Array of extra objects to deploy with the release |
9299
| global | object | `{"controller":{"deployment":{"rollingUpdate":{"maxSurge":null,"maxUnavailable":null},"strategy":null},"rollout":{"analysis":{"successfulRunHistoryLimit":null,"unsuccessfulRunHistoryLimit":null},"analysisTemplate":{"args":null,"enabled":null,"metrics":[{"failureCondition":null,"failureLimit":null,"name":null,"provider":{"newRelic":{"profile":null,"query":null}},"successCondition":null}]},"canary":{"maxSurge":null,"maxUnavailable":null,"steps":[{"setWeight":null},{"pause":{"duration":null}},{"setWeight":null},{"pause":{"duration":null}}]},"strategy":null},"type":""},"env":{},"imagePullSecrets":[],"imageRegistry":""}` | Global parameters |
93100
| global.controller.deployment.rollingUpdate.maxSurge | string | `nil` | Set RollingUpdate max surge (absolute number or percentage) |

charts/cf-common/templates/classic/_helpers.tpl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{{/*
22
Calculate RabbitMQ URI (for On-Prem)
3-
Usage
4-
{{ include "cf-common-0.2.0.classic.calculateRabbitMqUri" . }}
3+
Must me called from chart root context.
4+
Usage:
5+
{{ include "cf-common-0.3.0.classic.calculateRabbitMqUri" . }}
56
*/}}
67

7-
{{- define "cf-common-0.2.0.classic.calculateRabbitMqUri" }}
8+
{{- define "cf-common-0.3.0.classic.calculateRabbitMqUri" }}
89

910
{{- $rabbitmqProtocol := .Values.global.rabbitmqProtocol | default "amqp" -}}
1011
{{- $rabbitmqUsername := .Values.global.rabbitmqUsername -}}
@@ -22,9 +23,9 @@ coalesce here for backward compatibility
2223
{{/*
2324
Calculate Mongo Uri (for On-Prem)
2425
Usage:
25-
{{ include "cf.common-0.2.0.classic.calculateMongoUri" (dict "dbName" $.Values.global.pipelineManagerService "mongoURI" $.Values.global.mongoURI) }}
26+
{{ include "cf.common-0.3.0.classic.calculateMongoUri" (dict "dbName" $.Values.global.pipelineManagerService "mongoURI" $.Values.global.mongoURI) }}
2627
*/}}
27-
{{- define "cf-common-0.2.0.classic.calculateMongoUri" -}}
28+
{{- define "cf-common-0.3.0.classic.calculateMongoUri" -}}
2829
{{- if contains "?" .mongoURI -}}
2930
{{- $mongoURI := (splitList "?" .mongoURI) -}}
3031
{{- printf "%s%s?%s" (first $mongoURI) .dbName (last $mongoURI) }}

charts/cf-common/templates/common/_annotations.tpl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
{{/*
22
Render checksum annotation
3+
Must be called from chart root context.
34
Usage:
5+
annotations: {{ include "cf-common-0.3.0.annotations.podAnnotations" . | nindent }}
46
*/}}
5-
{{- define "cf-common-0.2.0.annotations.podAnnotations" -}}
7+
{{- define "cf-common-0.3.0.annotations.podAnnotations" -}}
68

79
{{- if .Values.podAnnotations -}}
8-
{{- include "cf-common-0.2.0.tplrender" (dict "Values" .Values.podAnnotations "context" $) | nindent 0 }}
10+
{{- include "cf-common-0.3.0.tplrender" (dict "Values" .Values.podAnnotations "context" $) | nindent 0 }}
911
{{- end -}}
1012

1113
{{- $configMapFound := dict -}}
1214
{{- range $configMapIndex, $configMapItem := .Values.configMaps -}}
1315

1416
{{- if $configMapItem.enabled -}}
15-
{{- $_ := set $configMapFound $configMapIndex ( include "cf-common-0.2.0.tplrender" (dict "Values" $configMapItem.data "context" $) | sha256sum) -}}
17+
{{- $_ := set $configMapFound $configMapIndex ( include "cf-common-0.3.0.tplrender" (dict "Values" $configMapItem.data "context" $) | sha256sum) -}}
1618
{{- end -}}
1719

1820
{{- if $configMapFound -}}
@@ -25,7 +27,7 @@ Usage:
2527
{{- range $secretIndex, $secretItem := .Values.secrets -}}
2628

2729
{{- if $secretItem.enabled -}}
28-
{{- $_ := set $secretFound $secretIndex ( include "cf-common-0.2.0.tplrender" (dict "Values" $secretItem.stringData "context" $) | sha256sum) -}}
30+
{{- $_ := set $secretFound $secretIndex ( include "cf-common-0.3.0.tplrender" (dict "Values" $secretItem.stringData "context" $) | sha256sum) -}}
2931
{{- end -}}
3032

3133
{{- if $secretFound -}}

charts/cf-common/templates/common/_labels.tpl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
{{/*
22
Kubernetes standard labels
33
*/}}
4-
{{- define "cf-common-0.2.0.labels.standard" -}}
5-
app.kubernetes.io/name: {{ include "cf-common-0.2.0.names.name" . }}
6-
helm.sh/chart: {{ include "cf-common-0.2.0.names.chart" . }}
4+
{{- define "cf-common-0.3.0.labels.standard" -}}
5+
app.kubernetes.io/name: {{ include "cf-common-0.3.0.names.name" . }}
6+
helm.sh/chart: {{ include "cf-common-0.3.0.names.chart" . }}
77
app.kubernetes.io/instance: {{ .Release.Name }}
88
app.kubernetes.io/managed-by: {{ .Release.Service }}
99
{{- end -}}
1010

1111
{{/*
1212
Labels to use on deploy.spec.selector.matchLabels and svc.spec.selector
1313
*/}}
14-
{{- define "cf-common-0.2.0.labels.matchLabels" -}}
15-
app.kubernetes.io/name: {{ include "cf-common-0.2.0.names.name" . }}
14+
{{- define "cf-common-0.3.0.labels.matchLabels" -}}
15+
app.kubernetes.io/name: {{ include "cf-common-0.3.0.names.name" . }}
1616
app.kubernetes.io/instance: {{ .Release.Name }}
1717
{{- end -}}
1818

1919

2020
{{/*
2121
Extra labels
2222
Usage:
23-
{{ include "cf-common-0.2.0.labels.extraLabels" ( dict "Values" .Values.path.to.the.labels "context" $) }}
23+
{{ include "cf-common-0.3.0.labels.extraLabels" ( dict "Values" .Values.path.to.the.labels "context" $) }}
2424
*/}}
25-
{{- define "cf-common-0.2.0.labels.extraLabels" -}}
25+
{{- define "cf-common-0.3.0.labels.extraLabels" -}}
2626
{{- if not (kindIs "map" .Values) -}}
2727
{{- fail "ERROR: labels block must be a map" -}}
2828
{{- end -}}
@@ -34,9 +34,9 @@ Usage:
3434
{{/*
3535
Annotations
3636
Usage:
37-
{{ include "cf-common-0.2.0.annotations" ( dict "Values" .Values.path.to.the.annotations "context" $) }}
37+
{{ include "cf-common-0.3.0.annotations" ( dict "Values" .Values.path.to.the.annotations "context" $) }}
3838
*/}}
39-
{{- define "cf-common-0.2.0.annotations" -}}
39+
{{- define "cf-common-0.3.0.annotations" -}}
4040
{{- if not (kindIs "map" .Values) -}}
4141
{{- fail "ERROR: annotations block must be a map" -}}
4242
{{- end -}}

charts/cf-common/templates/common/_names.tpl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{{/*
22
Expand the name of the chart.
33
*/}}
4-
{{- define "cf-common-0.2.0.names.name" -}}
4+
{{- define "cf-common-0.3.0.names.name" -}}
55
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
66
{{- end -}}
77

88
{{/*
99
Create chart name and version as used by the chart label.
1010
*/}}
11-
{{- define "cf-common-0.2.0.names.chart" -}}
11+
{{- define "cf-common-0.3.0.names.chart" -}}
1212
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
1313
{{- end -}}
1414

@@ -17,7 +17,7 @@ Create a default fully qualified app name.
1717
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
1818
If release name contains chart name it will be used as a full name.
1919
*/}}
20-
{{- define "cf-common-0.2.0.names.fullname" -}}
20+
{{- define "cf-common-0.3.0.names.fullname" -}}
2121
{{- if .Values.fullnameOverride -}}
2222
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
2323
{{- else -}}
@@ -33,10 +33,10 @@ If release name contains chart name it will be used as a full name.
3333
{{/*
3434
ServiceAccount Name
3535
*/}}
36-
{{- define "cf-common-0.2.0.names.serviceAccountName" -}}
36+
{{- define "cf-common-0.3.0.names.serviceAccountName" -}}
3737
{{- if .Values.serviceAccount -}}
3838
{{- if .Values.serviceAccount.enabled -}}
39-
{{- .Values.serviceAccount.nameOverride | default (include "cf-common-0.2.0.names.fullname" .) -}}
39+
{{- .Values.serviceAccount.nameOverride | default (include "cf-common-0.3.0.names.fullname" .) -}}
4040
{{- else -}}
4141
{{- print "default" -}}
4242
{{- end -}}

0 commit comments

Comments
 (0)