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 0ac5c8fbf7 add workdir and persistence 9 months ago
build bootstrap operator 9 months ago
cmd/manager bootstrap operator 9 months ago
deploy add workdir and persistence 9 months ago
pkg add workdir and persistence 9 months ago
version add workdir and persistence 9 months ago
.gitignore create cronjobs 9 months ago
Dockerfile bootstrap operator 9 months ago
Makefile create cronjobs 9 months ago
README.md add workdir and persistence 9 months ago
VERSION add workdir and persistence 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

README.md

Cron operator for Kubernetes

Control multiple cronjobs with same image, but different commands.

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 command
  • Or just run docker build -t cron-operator . to make image locally

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
metadata:
  name: mycron
spec:
  image: "python:3"
  persistentVolumeName: app-cache
  persistentVolumePath: /persistent
  tasks:
  - name: print-test
    commands:
    - python
    - -c
    - print("test")
    schedule: "* * * * *"
  - name: print-test2
    commands:
    - python
    - -c
    - print("test task 2")
    schedule: "* * * * *"

---
apiVersion: batch/v1
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: app-cache
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  storageClassName: my-efs

If you delete this resource operator will delete only CronJobs, not created Jobs and Pods.

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