ebiiim / gitbackup

A Kubernetes Operator for scheduled backup of Git repositories.
MIT License
1 stars 0 forks source link

Proposal: insert random delay instead of incrementing cron #4

Open ebiiim opened 1 year ago

ebiiim commented 1 year ago

Problem

Collection currently increments cron, but actually it's difficult to define "increment" for cron.

$ kubectl get cronjobs
NAME                        SCHEDULE    SUSPEND   ACTIVE   LAST SCHEDULE   AGE
gitbackup-coll1-bar         2 6 * * *   False     0        <none>          5s
gitbackup-coll1-foo         1 6 * * *   False     0        <none>          5s
gitbackup-coll1-gitbackup   0 6 * * *   False     0        <none>          5s

Proposal

Inserting a random delay like rand(0, repo_num*10) is a good alternative.

To allow Collection to set the delay to the controlled Repository, add spec.maxRandomDelay field to Repository.

apiVersion: gitbackup.ebiiim.com/v1beta1
kind: Repository
spec:
  # max random delay in seconds
  maxRandomDelay: 60
  ...

Random delay can be implemented in shell script like sleep $(shuf -i0-123 -n1) or sleep $(( RANDOM % 123 )).

Note: $RANDOM returns a number in the range 0 - 32767