Skip to content

Commit

Permalink
Add cronjobber chart (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
plumdog authored Sep 21, 2021
1 parent 2dd1dbd commit e32cb88
Show file tree
Hide file tree
Showing 9 changed files with 268 additions and 0 deletions.
8 changes: 8 additions & 0 deletions charts/cronjobber/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
name: cronjobber
home: https://github.com/hiddeco/cronjobber
version: 0.1.1
appVersion: 0.3.0
description: Cronjobber is the cronjob controller from Kubernetes patched with time zone support.
maintainers:
- name: CyberHippo
75 changes: 75 additions & 0 deletions charts/cronjobber/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Cronjobber Helm Chart

## Chart Details
This chart will do the following:

* Installing `Cronjobber` which is the cronjob controller from Kubernetes patched with time zone support.

## Installing the Chart

To install the chart with the release name `my-release`:

```bash
$ helm install my-release chart/
```

## Configuration

The following table lists the configurable parameters of the cronjobber chart and their default values.

| Parameter | Description | Default |
| ----------------------- | ---------------------------------- | ---------------------------------------------------------- |
| `name` | Name of the resources | `cronjobber` |
| `namespace` | Namespace to deploy the resources | `default` |
| `image.repository` | Container image name | `quay.io/hiddeco/cronjobber` |
| `image.tag` | Container image tag | `0.3.0` |
| `replicas` | Number of replicas | `1` |
| `resources.requests.cpu`| CPU request for the main container | `50m` |
| `resources.requests.memory`| Memory request for the main container | `64Mi` |
| `sidecar.enabled` | Sidecar to keep the timezone database up-to-date | `False` |
| `sidecar.name` | Init container name | `init-updatetz` |
| `sidecar.image.repository`| Sidecar and init container image name | `quay.io/hiddeco/cronjobber-updatetz` |
| `sidecar.image.tag` | Sidecar and init container image tag | `0.1.1` |
| `sidecar.resources.requests.cpu`| Sidecar and init container cpu request | `100m` |
| `sidecar.resources.requests.memory`| Sidecar and init container memory request | `64Mi` |


Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`.

Alternatively, a YAML file that specifies the values for the parameters can be provided while installing the chart. For example,

```bash
$ helm install --name my-release -f values.yaml chart
```

> **Tip**: You can use the default [values.yaml](values.yaml)
## Usage

Instead of creating a [`CronJob`](https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/)
like you normally would, you create a `TZCronJob`, which works exactly
the same but supports an additional field: `.spec.timezone`. Set this
to the time zone you wish to schedule your jobs in and Cronjobber will
take care of the rest.

```yaml
apiVersion: cronjobber.hidde.co/v1alpha1
kind: TZCronJob
metadata:
name: hello
spec:
schedule: "*/1 * * * *"
timezone: "Europe/Amsterdam"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox
args:
- /bin/sh
- -c
- date; echo "Hello, World!"
restartPolicy: OnFailure
```
17 changes: 17 additions & 0 deletions charts/cronjobber/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
name: {{ .Values.name }}
labels:
name: {{ .Values.name }}
rules:
- apiGroups: ['cronjobber.hidde.co']
resources: ['*']
verbs: ['*']
- apiGroups: ['batch']
resources: ['jobs']
verbs: ['*']
- apiGroups: ['']
resources: ['events']
verbs: ['create', 'patch', 'update']
15 changes: 15 additions & 0 deletions charts/cronjobber/templates/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: {{ .Values.name }}
labels:
name: {{ .Values.name }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ .Values.name }}
subjects:
- kind: ServiceAccount
name: {{ .Values.name }}
namespace: {{ .Values.namespace }}
34 changes: 34 additions & 0 deletions charts/cronjobber/templates/customresourcedefinition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: tzcronjobs.cronjobber.hidde.co
spec:
group: cronjobber.hidde.co
version: v1alpha1
names:
plural: tzcronjobs
singular: tzcronjob
kind: TZCronJob
listKind: TZCronJobList
shortNames:
- tzc
scope: Namespaced
subresources:
status: {}
additionalPrinterColumns:
- name: Schedule
type: string
description: The schedule defining the interval a TZCronJob is run
JSONPath: .spec.schedule
- name: Time zone
type: string
description: The time zone the interval of a TZCronJob is calculated in
JSONPath: .spec.timezone
- name: Last schedule
type: date
description: The last time a Job was scheduled by a TZCronJob
JSONPath: .status.lastScheduleTime
- name: Age
type: date
JSONPath: .metadata.creationTimestamp
81 changes: 81 additions & 0 deletions charts/cronjobber/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Values.name }}
namespace: {{ .Values.namespace }}
spec:
replicas: {{ .Values.replicas }}
selector:
matchLabels:
name: {{ .Values.name }}
strategy:
type: Recreate
template:
metadata:
labels:
name: {{ .Values.name }}
spec:
serviceAccountName: {{ .Values.name }}
securityContext:
fsGroup: 2 #daemon
{{- if .Values.sidecar.enabled }}
volumes:
- name: timezonedb
emptyDir: {}
{{- end }}
{{- if .Values.sidecar.enabled }}
initContainers:
- name: init-updatetz
image: {{ printf "%s:%s" .Values.sidecar.image.repository .Values.sidecar.image.tag | quote }}
securityContext:
{{ toYaml .Values.sidecar.securityContext | indent 12 }}
resources:
limits:
cpu: {{ .Values.sidecar.resources.requests.cpu }}
memory: {{ .Values.sidecar.resources.requests.memory }}
volumeMounts:
- name: timezonedb
mountPath: /tmp/zoneinfo
readOnly: false
env:
- name: INIT_CONTAINER
value: "true"
- name: REFRESH_INTERVAL
value: "3s"
{{- end }}
containers:
- name: {{ .Values.name }}
image: {{ printf "%s:%s" .Values.image.repository .Values.image.tag | quote }}
resources:
requests:
cpu: {{ .Values.resources.requests.cpu }}
memory: {{ .Values.resources.requests.memory }}
args:
- --log-level=info
{{- if .Values.sidecar.enabled }}
volumeMounts:
- name: timezonedb
mountPath: /usr/share/zoneinfo
readOnly: true
{{- end }}
{{- if .Values.sidecar.enabled }}
- name: updatetz
image: {{ printf "%s:%s" .Values.sidecar.image.repository .Values.sidecar.image.tag | quote }}
# NB: the security context configuration below may not work
# out of the box on OpenShift
securityContext:
{{ toYaml .Values.sidecar.securityContext | indent 12 }}
resources:
limits:
cpu: {{ .Values.sidecar.resources.requests.cpu }}
memory: {{ .Values.sidecar.resources.requests.memory }}
volumeMounts:
- name: timezonedb
mountPath: /tmp/zoneinfo
readOnly: false
{{- end }}
{{- if .Values.nodeSelector }}
nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
{{- end }}
8 changes: 8 additions & 0 deletions charts/cronjobber/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ .Values.name }}
namespace: {{ .Values.namespace }}
labels:
name: {{ .Values.name }}
28 changes: 28 additions & 0 deletions charts/cronjobber/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: cronjobber
namespace: default
image:
repository: quay.io/hiddeco/cronjobber
tag: 0.3.0
replicas: 1
resources:
requests:
cpu: 50m
memory: 64Mi
sidecar:
enabled: false
name: init-updatetz
image:
repository: quay.io/hiddeco/cronjobber-updatetz
tag: 0.1.1
resources:
requests:
cpu: 100m
memory: 64Mi
# NB: the security context configuration below may not work
# out of the box on OpenShift
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
nodeSelector: {}
2 changes: 2 additions & 0 deletions ct.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
target-branch: main
excluded-charts:
- cronjobber

0 comments on commit e32cb88

Please sign in to comment.