Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #7 from hiddeco/release/0.1.1
Browse files Browse the repository at this point in the history
Release Cronjobber 0.1.1
  • Loading branch information
hiddeco authored Apr 6, 2019
2 parents 0b9011a + 49f1065 commit 0a00adf
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 7 deletions.
9 changes: 9 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,12 @@ jobs:
docker login -u "${DOCKER_REGISTRY_USER}" -p "${DOCKER_REGISTRY_PASSWORD}" quay.io
make push
fi
workflows:
version: 2
build-and-push:
jobs:
- build:
filters:
tags:
only: /[0-9]+(\.[0-9]+)*(-[a-z]+)?/
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
## 0.1.1 (2019-04-06)

### Fixes

- Use schedule location during earliestTime calculations
[hiddeco/cronjobber#6][#6]
- Use `timezone` in example and CRD
[hiddeco/cronjobber#6][#6]

### Improvements

- Mount timezone database from host in example `Deployment`
[hiddeco/cronjobber#6][#6]

### Thanks

Thanks to @Phuong-Trueanthem for submitting the patches.

[#6]: https://github.com/hiddeco/cronjobber/pull/6

## 0.1.0 (2019-03-06)

First semver release.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ test-codegen:
git diff --exit-code -- pkg/apis pkg/client

test: test-fmt test-codegen
go test $(TEST_FLAGS) ./...
go test $(TEST_FLAGS) ./...
68 changes: 68 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,75 @@
# Cronjobber

[![CircleCI](https://circleci.com/gh/hiddeco/cronjobber/tree/master.svg?style=shield)](https://circleci.com/gh/hiddeco/cronjobber/tree/master)
[![Go Report Card](https://goreportcard.com/badge/github.com/hiddeco/cronjobber)](https://goreportcard.com/report/github.com/hiddeco/cronjobber)
[![Docker Repository on Quay](https://quay.io/repository/hiddeco/cronjobber/status "Docker Repository on Quay")](https://quay.io/repository/hiddeco/cronjobber)
[![License](https://img.shields.io/github/license/hiddeco/cronjobber.svg)](https://github.com/hiddeco/cronjobber/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/hiddeco/cronjobber.svg)](https://github.com/hiddeco/cronjobber/releases)

Cronjobber is the cronjob controller from Kubernetes patched with time zone support.

## Installation

```sh
# Install CustomResourceDefinition
$ kubectl apply -f https://raw.githubusercontent.com/hiddeco/cronjobber/master/deploy/crd.yaml
# Setup service account and RBAC
$ kubectl apply -f https://raw.githubusercontent.com/hiddeco/cronjobber/master/deploy/rbac.yaml
# Deploy Cronjobber
$ kubectl apply -f https://raw.githubusercontent.com/hiddeco/cronjobber/master/deploy/deploy.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
```
## Reasoning
There has been a [long outstanding (and now closed) issue](https://github.com/kubernetes/kubernetes/issues/47202)
to add time zone support to the `CronJob` kind in Kubernetes, including
a [fully working PR](https://github.com/kubernetes/kubernetes/pull/47266)
which actually made it possible. SIG Apps and in SIG Architecture
decided however against adding it because of the downside of having
to manage and distribute time zone databases.

> People are now encouraged to innovate and solve these kinds of problems in the ecosystem rather than core.
>
> Instead of putting this in Kubernetes the ask is to:
> 1. Develop this in the ecosystem (e.g., a controller) that others can use. Distribute it, solve the problems there, and see what update looks like
> 2. If the solution is widely adopted and can be used by everyone (including small scale, multi-cluster, etc) then it could be considered for core Kubernetes
>
> -- <cite>[mattfarina (Matt Farina) on Jan 26, 2018](https://github.com/kubernetes/kubernetes/issues/47202#issuecomment-360820586)</cite>

Cronjobber is the most simple answer to this: it is the original PR
on top of a more recent version of the cronjob controller, with some
glue added to make it an independent controller.

## Credits

This application is derived from open source components. You can find
Expand Down
2 changes: 1 addition & 1 deletion deploy/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ spec:
- name: Time zone
type: string
description: The time zone the interval of a TZCronJob is calculated in
JSONPath: .spec.timeZone
JSONPath: .spec.timezone
- name: Last schedule
type: date
description: The last time a Job was scheduled by a TZCronJob
Expand Down
13 changes: 12 additions & 1 deletion deploy/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,23 @@ spec:
name: cronjobber
spec:
serviceAccountName: cronjobber
securityContext:
fsGroup: 65534 #nobody
volumes:
- name: timezonedb
hostPath:
path: /usr/share/zoneinfo
type: Directory
containers:
- name: cronjobber
image: hiddeco/cronjobber:latest
image: quay.io/hiddeco/cronjobber:0.1.1
resources:
requests:
cpu: 50m
memory: 64Mi
args:
- --log-level=info
volumeMounts:
- name: timezonedb
mountPath: /usr/share/zoneinfo
readOnly: true
4 changes: 2 additions & 2 deletions example/hello-tzc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ kind: TZCronJob
metadata:
name: hello
spec:
schedule: "*/1 * * * *"
timeZone: "Europe/Amsterdam"
schedule: "*/5 18 * * *"
timezone: "Europe/Amsterdam"
jobTemplate:
spec:
template:
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/cronjobber/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func getRecentUnmetScheduleTimes(sj cronjobberv1.TZCronJob, now time.Time) ([]ti

var earliestTime time.Time
if sj.Status.LastScheduleTime != nil {
earliestTime = sj.Status.LastScheduleTime.Time
earliestTime = sj.Status.LastScheduleTime.Time.In(now.Location())
} else {
// If none found, then this is either a recently created scheduledJob,
// or the active/completed info was somehow lost (contract for status
Expand All @@ -111,7 +111,7 @@ func getRecentUnmetScheduleTimes(sj cronjobberv1.TZCronJob, now time.Time) ([]ti
}
if sj.Spec.StartingDeadlineSeconds != nil {
// Controller is not going to schedule anything below this point
schedulingDeadline := now.Add(-time.Second * time.Duration(*sj.Spec.StartingDeadlineSeconds))
schedulingDeadline := now.Add(-time.Second * time.Duration(*sj.Spec.StartingDeadlineSeconds)).In(now.Location())

if schedulingDeadline.After(earliestTime) {
earliestTime = schedulingDeadline
Expand Down

0 comments on commit 0a00adf

Please sign in to comment.