Operator for CronJob resources
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Vladimir Smagin 102696d873 unpin version 9 months ago
build bootstrap operator 9 months ago
cmd/manager bootstrap operator 9 months ago
deploy unpin version 9 months ago
pkg bugfix: reconcile concurrency and restart policy 9 months ago
version bugfix: reconcile concurrency and restart policy 9 months ago
.gitignore create cronjobs 9 months ago
Dockerfile bootstrap operator 9 months ago
Makefile create cronjobs 9 months ago
README.md Изменить 'README.md' 9 months ago
VERSION bugfix: reconcile concurrency and restart policy 9 months ago
go.mod add workdir and persistence 9 months ago
go.sum sync tasks and cronjobs 9 months ago
logo.png add logo 9 months ago
tools.go bootstrap operator 9 months ago


Cron operator for Kubernetes

Manages multiple CronJobs with same image, but different commands and workdirs. Supports mounting of persistent volume to save results somewhere.

Build sources

  • You definitly need a Golang installed
  • Clone repository https://git.blindage.org/21h/cron-operator.git to your computer
  • Open Makefile and change images registry to yours, then run make && make push
  • Or run docker build -t cron-operator . to make image and push to your repo later

Prebuilt images

You can find images here https://hub.docker.com/r/iam21h/cron-operator

Deploy operator

Cluster scoped installation:

kubectl -f deploy/crds/blindage_v1alpha1_cronop_crd.yaml
kubectl -f deploy/service_account.yaml
kubectl -f deploy/clusterrole.yaml
kubectl -f deploy/clusterrole_binding.yaml
kubectl -f deploy/operator.yaml

Change operator.yaml if you want operator watch only specified namespace. Check deploy directory, may be you want to use Role instead of ClusterRole.

Your first CronOp deployment

This resource can help you run your first tasks:

apiVersion: blindage.org/v1alpha1
kind: CronOp
  name: mycron
  image: "python:3"
  persistentVolumeName: app-cache
  persistentVolumePath: /persistent
  - name: print-test-in-pvc-dir
    workdir: /persistent
    commands: ['python','-c', 'print("doing nothing")']
    schedule: "* * * * *"
  - name: print-another-test
    commands: ['python','-c', 'print("koalas loves trees")']
    schedule: "* * * * *"

apiVersion: batch/v1
kind: PersistentVolumeClaim
apiVersion: v1
  name: app-cache
    - ReadWriteOnce
      storage: 10Gi
  storageClassName: my-efs

If you delete this resource operator will delete CronJobs.

Full Spec

type CronOpSpec struct {
  // default busybox, override it with our image
  Image string     `json:"image,omitempty"`
  // if you need some persistence set here to your PersistentVolumeClaim name
  PersistentVolumeName string     `json:"persistentVolumeName,omitempty"`
  // mount path
  PersistentVolumePath string     `json:"persistentVolumePath,omitempty"`

  // default is empty, but empty is useless ;)
  Tasks []CronTask `json:"tasks,omitempty"`

type CronTask struct {
  // use naming same as containers name, its required
  Name              string                          `json:"name"`

  // default "0 * * * *", hourly
  Schedule          string                          `json:"schedule,omitempty"`

  // command, can't be empty
  Commands          []string                        `json:"commands"`

  // set command working directory, default empty
  Workdir           string                          `json:"workdir,omitempty"`

  // default OnFailure
  RestartPolicy     *corev1.RestartPolicy           `json:"restartPolicy,omitempty"`

  // default Allow
  ConcurrencyPolicy *batchv1beta1.ConcurrencyPolicy `json:"concurrencyPolicy,omitempty"`

Copyright by Vladimir Smagin (21h) 2019
http://blindage.org email: 21h@blindage.org
Project page: https://git.blindage.org/21h/cron-operator