cloudnative-pg / cloudnative-pg

CloudNativePG is a comprehensive platform designed to seamlessly manage PostgreSQL databases within Kubernetes environments, covering the entire operational lifecycle from initial deployment to ongoing maintenance
https://cloudnative-pg.io
Apache License 2.0
4.23k stars 286 forks source link

[Bug]: Incorrect calculation of cronjobs in scheduled backups #4202

Open DeskPlant opened 5 months ago

DeskPlant commented 5 months ago

Is there an existing issue already for this bug?

I have read the troubleshooting guide

I am running a supported version of CloudNativePG

Contact Details

patrik.zotj@gmail.com

Version

1.22.2

What version of Kubernetes are you using?

1.29

What is your Kubernetes environment?

Cloud: Amazon EKS

How did you install the operator?

YAML manifest

What happened?

After creating a cluster, i tried attaching a scheduled backup resource to it using the yaml below.

apiVersion: postgresql.cnpg.io/v1
kind: ScheduledBackup
metadata:
  name: backup-test
spec:
  schedule: "0 1 * * *"
  backupOwnerReference: self
  immediate: true
  cluster:
    name: test-db

The backups created by it are fine, the issue is the frequency of the backups does not match the given cron in the yaml file. For examle if i give it a cronjob to backup every day at 1 am, even though it says the schedule is correct when i use kubectl describe, the backups are instead done every 1 hour.

image image

I have tried this with other formats for example every 8 hours and that makes the backups occur every 8 minutes instead.

Cluster resource

No response

Relevant log output

No response

Code of Conduct

mv-yurchenko commented 5 months ago

Got same problem with cron error

shusaan commented 5 months ago

I am facing same problem

shusaan commented 4 months ago

@gbartolini is that targeting in next release ?

mv-yurchenko commented 4 months ago

May be this will help: https://pkg.go.dev/github.com/robfig/cron I used this doc to configure

shusaan commented 4 months ago

May be this will help: https://pkg.go.dev/github.com/robfig/cron I used this doc to configure

thank you, will check and share update

ccrvlh commented 1 month ago

The issue seems to be that CNPG uses a 6 string cron as defined on the link on the docs (https://pkg.go.dev/github.com/robfig/cron). However, the docs mention:

This field is a cron schedule specification, which follows the same format used in Kubernetes CronJobs

And when looking at k8s CronJob docs here It says that is a 5 digit string cron.

The .spec.schedule field is required. The value of that field follows the Cron syntax:

So the issue doesn't seem to be that is calculating it wrong, but rather that the docs/links/logic are inconsistent.