Generate Kubernetes Job/CronJob specs without the boilerplate.
- Expose an opinionated set of "the most useful" Job/CronJob properties as top level properties.
- Write the same specs for your Jobs and CronJobs by specifying a
schedule
in Cron format or as the string 'once'. - Include a collection of embedded
jobs
that inherit the top level properties.
For a complete list of the available properties and commentary about their uses see schema.json.
pip install kronjob
$ kronjob --help
usage: kronjob [-h] [--version] [abstract_job_spec] [k8s_job_spec]
Generate Kubernetes Job/CronJob specs without the boilerplate.
positional arguments:
abstract_job_spec File containing an abstract definition of Kubernetes
Job/CronJob specs. Defaults to stdin.
k8s_job_spec File kubernetes Job/CronJob specs will be written to.
Defaults to stdout.
optional arguments:
-h, --help show this help message and exit
--version
Input:
image: example.com/base
name: example
namespace: test
schedule: 'once' # in order to output a Job and not a CronJob `schedule` must be 'once'
Output:
apiVersion: batch/v2alpha1
kind: CronJob
metadata:
labels:
kronjob/job: example
name: example
namespace: test
spec:
concurrencyPolicy: Forbid
failedJobsHistoryLimit: 10
jobTemplate:
spec:
template:
metadata:
labels:
kronjob/job: example-example
spec:
containers:
- image: example.com/base
name: job
restartPolicy: Never
schedule: '* * * * *'
successfulJobsHistoryLimit: 1
Input:
image: example.com/base
name: example
namespace: test
schedule: '* * * * *'
Output:
apiVersion: batch/v2alpha1
kind: CronJob
metadata:
labels:
kronjob/job: example
name: example
namespace: test
spec:
concurrencyPolicy: Forbid
failedJobsHistoryLimit: 10
jobTemplate:
spec:
template:
metadata:
labels:
kronjob/job: example
spec:
containers:
- image: example.com/base
name: job
restartPolicy: Never
schedule: '* * * * *'
successfulJobsHistoryLimit: 1
Input:
image: example.com/base
name: example
namespace: test
jobs:
- schedule: '* * * * *'
- schedule: once
Output:
apiVersion: batch/v2alpha1
kind: CronJob
metadata:
labels:
kronjob/job: example
name: example
namespace: test
spec:
concurrencyPolicy: Forbid
failedJobsHistoryLimit: 10
jobTemplate:
spec:
template:
metadata:
labels:
kronjob/job: example
spec:
containers:
- image: example.com/base
name: job
restartPolicy: Never
schedule: '* * * * *'
successfulJobsHistoryLimit: 1
---
apiVersion: batch/v1
kind: Job
metadata:
labels:
kronjob/job: example
name: example
namespace: test
spec:
template:
metadata:
labels:
kronjob/job: example
spec:
containers:
- image: example.com/base
name: job
restartPolicy: Never
In general, to allow kronjob
to take more parameters, the following must be done:
- Add the parameter to
schema.json
so that it is consumed from thekronjob.yml
- Find its appropriate mapping in the kubernetes models. This generally involves going through the
github.com/kubernetes-client/python
documentation and trying to find the appropriate model, depending on where the parameter is supposed to be surfaced - Add the mapping inside the
build_k8s_object
function. - Update tests to reflect that the kronjob can handle a new parameter, and that it maps appropriately. Note that
kronjob
abstracts both a CronJob and a Job