Operator for CronJob resources
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
Vladimir Smagin bdff58836e readme před 3 měsíci
build bootstrap operator před 1 rokem
cmd/manager bootstrap operator před 1 rokem
deploy bump helm version před 3 měsíci
pkg better annotations před 3 měsíci
vendor add vendor před 11 měsíci
version lables and annotations před 3 měsíci
.gitignore add vendor před 11 měsíci
Dockerfile bump go version před 3 měsíci
Jenkinsfile set build node před 3 měsíci
README.md readme před 3 měsíci
VERSION lables and annotations před 3 měsíci
go.mod add pipeline, use vendoring, no more latest tag před 11 měsíci
go.sum add pipeline, use vendoring, no more latest tag před 11 měsíci
logo.png add logo před 1 rokem
tools.go bootstrap operator před 1 rokem

README.md

Cron operator for Kubernetes

Manages multiple CronJobs with same image, but different commands and workdirs. Supports mounting of persistent volume to save results somewhere, ENV variables configmaps, concurrency and restart policy.

Build sources

Prebuilt images

You can find images here https://hub.docker.com/r/iam21h/cron-operator. Pin version number in operator.yaml if you do not want automaticaly get new features and bugs.

Deploy operator

Edit files and run:

kubectl -f deploy/crds/blindage_v1alpha1_cronop_crd.yaml
kubectl -f deploy/clusterrole.yaml
kubectl -f deploy/clusterrole_binding.yaml # edit service account namespace here
kubectl -n operators -f deploy/service_account.yaml
kubectl -n operators -f deploy/operator.yaml

or use Helm:

helm repo add 21h https://charts.blindage.org
helm repo update
helm install cron-operator 21h/cron-operator -n operators

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

Settings

In your CronOp resource you can set image, parameters and tasks. CronJobs is a result of reconciling tasks section, some parameters can be global and overrided in each task. Remember, CronJob, Pod and Job is a different things.

Look into pkg/apis/blindage/v1alpha1/cronop_types.go for your CustomResource syntax and comments.

This parameters can be set in global section or each task:

  • Set Configmap with ENV variables
    envConfigmap: default empty | string

  • Mount configmap as files
    mountConfigmap: default empty | string
    mountConfigmapPath: by default mounts to /configmap-local | string

  • Mount secret as files
    mountSecret: default empty | string
    mountSecretPath: by default mounts to /secret-local | string
    mountSecretPermissions: default permissions, use decimal notation, default 256 | integer

  • How to restart Pod
    restartPolicy: OnFailure | Never | Always

  • Limit Job restarts
    backoffLimit: 0 | integer

  • Allow Cronjob to run concurrent Jobs
    concurrencyPolicy: Allow | Forbid | Replace

  • Set standard kubernetes Pod security context podSecurityContext: default empty

Global history limits:

  • successfulJobsHistoryLimit: 3 | integer
  • failedJobsHistoryLimit: 3 | integer

Also you can save intermediate results in mounted persistent volume. You can set PVC name with PersistentVolumeName, mount point with PersistentVolumePath and PersistentVolumeSubPath. It’s easy.

Global affinity, node selection and tolerations, have standard kubernetes specs:

  • nodeSelector: default empty
  • affinity: default empty
  • tolerations: default empty

Global resource limiting also kubernetes standard, but separated:

  • podRequests: default empty
  • podLimits: default empty

Labels and annotations:

Operator automatically copies labels from CR meta to Cronjob, Job and Pod.

Also you cat set annotations in CR spec to set it for Pod and merge it with individual task annotations:

---
apiVersion: blindage.org/v1alpha1
kind: CronOp
metadata:
  name: mycron
  labels:
    my-application: python-app
spec:
  image: "python:3"
  annotations:
    co.elastic.logs.backup/multiline.match: after
    co.elastic.logs.backup/multiline.negate: "true"
    co.elastic.logs.backup/multiline.pattern: ^\[
  tasks:
  - name: print-test
    annotations:
      logger: do-not-log
    commands: ['python','-c', 'print("testtesttest")']
    schedule: "* * * * *"

Your first CronOp deployment

Good sample you can find in deploy/test-cron.yaml, see it in case of questions.

This resource can help you run your first tasks:

---
apiVersion: blindage.org/v1alpha1
kind: CronOp
metadata:
  name: mycron
  labels:
    app: python
    service: testing-cron
spec:
  image: "python:3"
  tasks:
  - name: print-test
    commands: ['python','-c', 'print("doing nothing")']
    schedule: "* * * * *"
  - name: hello
    commands: ['python','-c', 'print("hello world hourly")']
    schedule: "0 * * * *"

If you delete this resource operator will delete CronJobs and Jobs.


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