fix cronjob updates
DELETE
e2e-tests/scheduled-backup/compare/cronjob_f875c-each-min-aws-s3-oc.yml
-apiVersion: batch/v1beta1
-kind: CronJob
-metadata:
- annotations:
- testName: scheduled-backup
- labels:
- backupWorker: "True"
- cluster: scheduled-backup
- schedule: N_N_N_N_N
- type: cron
- name: f875c-each-min-aws-s3
- ownerReferences:
- - controller: true
- kind: PerconaXtraDBCluster
- name: scheduled-backup
-spec:
- concurrencyPolicy: Allow
- failedJobsHistoryLimit: 1
- jobTemplate:
- metadata:
- ownerReferences:
- - apiVersion: batch/v1beta1
- kind: CronJob
- name: f875c-each-min-aws-s3
- spec:
- template:
- metadata:
- annotations:
- testName: scheduled-backup
- labels:
- backupWorker: "True"
- cluster: scheduled-backup
- schedule: N_N_N_N_N
- type: cron
- spec:
- affinity:
- nodeAffinity:
- requiredDuringSchedulingIgnoredDuringExecution:
- nodeSelectorTerms:
- - matchExpressions:
- - key: backupWorker
- operator: In
- values:
- - "True"
- containers:
- - args:
- - sh
- - -c
- - "\n\t\t\t\t\t\t\tcat <<-EOF | kubectl apply -f -\n\t\t\t\t\t\t\t\t\tapiVersion: pxc.percona.com/v1\n\t\t\t\t\t\t\t\t\tkind: PerconaXtraDBClusterBackup\n\t\t\t\t\t\t\t\t\tmetadata:\n\t\t\t\t\t\t\t\t\t finalizers: [delete-s3-backup ]\n\t\t\t\t\t\t\t\t\t name: \"cron-${pxcCluster:0:16}-aws-s3-$(date -u \"+%Y%m%d%H%M%S\")-${suffix}\"\n\t\t\t\t\t\t\t\t\t labels:\n\t\t\t\t\t\t\t\t\t ancestor: \"f875c-each-min-aws-s3\"\n\t\t\t\t\t\t\t\t\t cluster: \"${pxcCluster}\"\n\t\t\t\t\t\t\t\t\t type: \"cron\"\n\t\t\t\t\t\t\t\t\tspec:\n\t\t\t\t\t\t\t\t\t pxcCluster: \"${pxcCluster}\"\n\t\t\t\t\t\t\t\t\t storageName: \"aws-s3\"\n\t\t\t\t\t\t\tEOF\n\t\t\t\t\t\t\t"
- env:
- - name: pxcCluster
- value: scheduled-backup
- imagePullPolicy: Always
- name: run-backup
- resources:
- requests:
- cpu: 600m
- memory: 1G
- terminationMessagePath: /dev/termination-log
- terminationMessagePolicy: File
- dnsPolicy: ClusterFirst
- nodeSelector:
- backupWorker: "True"
- priorityClassName: high-priority
- restartPolicy: Never
- schedulerName: default-scheduler
- securityContext:
- supplementalGroups:
- - 1001
- serviceAccount: percona-xtradb-cluster-operator
- serviceAccountName: percona-xtradb-cluster-operator
- terminationGracePeriodSeconds: 30
- tolerations:
- - effect: NoSchedule
- key: backupWorker
- operator: Equal
- value: "True"
- schedule: '* * * * *'
- successfulJobsHistoryLimit: 1
- suspend: false

DELETE
e2e-tests/scheduled-backup/compare/cronjob_f875c-each-min-aws-s3.yml
-apiVersion: batch/v1beta1
-kind: CronJob
-metadata:
- annotations:
- testName: scheduled-backup
- labels:
- backupWorker: "True"
- cluster: scheduled-backup
- schedule: N_N_N_N_N
- type: cron
- name: f875c-each-min-aws-s3
- ownerReferences:
- - controller: true
- kind: PerconaXtraDBCluster
- name: scheduled-backup
-spec:
- concurrencyPolicy: Allow
- failedJobsHistoryLimit: 1
- jobTemplate:
- metadata:
- ownerReferences:
- - apiVersion: batch/v1beta1
- kind: CronJob
- name: f875c-each-min-aws-s3
- spec:
- template:
- metadata:
- annotations:
- testName: scheduled-backup
- labels:
- backupWorker: "True"
- cluster: scheduled-backup
- schedule: N_N_N_N_N
- type: cron
- spec:
- affinity:
- nodeAffinity:
- requiredDuringSchedulingIgnoredDuringExecution:
- nodeSelectorTerms:
- - matchExpressions:
- - key: backupWorker
- operator: In
- values:
- - "True"
- containers:
- - args:
- - sh
- - -c
- - "\n\t\t\t\t\t\t\tcat <<-EOF | kubectl apply -f -\n\t\t\t\t\t\t\t\t\tapiVersion: pxc.percona.com/v1\n\t\t\t\t\t\t\t\t\tkind: PerconaXtraDBClusterBackup\n\t\t\t\t\t\t\t\t\tmetadata:\n\t\t\t\t\t\t\t\t\t finalizers: [delete-s3-backup ]\n\t\t\t\t\t\t\t\t\t name: \"cron-${pxcCluster:0:16}-aws-s3-$(date -u \"+%Y%m%d%H%M%S\")-${suffix}\"\n\t\t\t\t\t\t\t\t\t labels:\n\t\t\t\t\t\t\t\t\t ancestor: \"f875c-each-min-aws-s3\"\n\t\t\t\t\t\t\t\t\t cluster: \"${pxcCluster}\"\n\t\t\t\t\t\t\t\t\t type: \"cron\"\n\t\t\t\t\t\t\t\t\tspec:\n\t\t\t\t\t\t\t\t\t pxcCluster: \"${pxcCluster}\"\n\t\t\t\t\t\t\t\t\t storageName: \"aws-s3\"\n\t\t\t\t\t\t\tEOF\n\t\t\t\t\t\t\t"
- env:
- - name: pxcCluster
- value: scheduled-backup
- imagePullPolicy: Always
- name: run-backup
- resources:
- requests:
- cpu: 600m
- memory: 1G
- terminationMessagePath: /dev/termination-log
- terminationMessagePolicy: File
- dnsPolicy: ClusterFirst
- nodeSelector:
- backupWorker: "True"
- priorityClassName: high-priority
- restartPolicy: Never
- schedulerName: default-scheduler
- securityContext:
- fsGroup: 1001
- supplementalGroups:
- - 1001
- serviceAccount: percona-xtradb-cluster-operator
- serviceAccountName: percona-xtradb-cluster-operator
- terminationGracePeriodSeconds: 30
- tolerations:
- - effect: NoSchedule
- key: backupWorker
- operator: Equal
- value: "True"
- schedule: '* * * * *'
- successfulJobsHistoryLimit: 1
- suspend: false

DELETE
e2e-tests/scheduled-backup/compare/cronjob_f875c-each-min-gcp-cs-oc.yml
-apiVersion: batch/v1beta1
-kind: CronJob
-metadata:
- annotations:
- testName: scheduled-backup
- labels:
- backupWorker: "True"
- cluster: scheduled-backup
- schedule: N_N_N_N_N
- type: cron
- name: f875c-each-min-gcp-cs
- ownerReferences:
- - controller: true
- kind: PerconaXtraDBCluster
- name: scheduled-backup
-spec:
- concurrencyPolicy: Allow
- failedJobsHistoryLimit: 1
- jobTemplate:
- metadata:
- ownerReferences:
- - apiVersion: batch/v1beta1
- kind: CronJob
- name: f875c-each-min-gcp-cs
- spec:
- template:
- metadata:
- annotations:
- testName: scheduled-backup
- labels:
- backupWorker: "True"
- cluster: scheduled-backup
- schedule: N_N_N_N_N
- type: cron
- spec:
- affinity:
- nodeAffinity:
- requiredDuringSchedulingIgnoredDuringExecution:
- nodeSelectorTerms:
- - matchExpressions:
- - key: backupWorker
- operator: In
- values:
- - "True"
- containers:
- - args:
- - sh
- - -c
- - "\n\t\t\t\t\t\t\tcat <<-EOF | kubectl apply -f -\n\t\t\t\t\t\t\t\t\tapiVersion: pxc.percona.com/v1\n\t\t\t\t\t\t\t\t\tkind: PerconaXtraDBClusterBackup\n\t\t\t\t\t\t\t\t\tmetadata:\n\t\t\t\t\t\t\t\t\t finalizers: [delete-s3-backup ]\n\t\t\t\t\t\t\t\t\t name: \"cron-${pxcCluster:0:16}-gcp-cs-$(date -u \"+%Y%m%d%H%M%S\")-${suffix}\"\n\t\t\t\t\t\t\t\t\t labels:\n\t\t\t\t\t\t\t\t\t ancestor: \"f875c-each-min-gcp-cs\"\n\t\t\t\t\t\t\t\t\t cluster: \"${pxcCluster}\"\n\t\t\t\t\t\t\t\t\t type: \"cron\"\n\t\t\t\t\t\t\t\t\tspec:\n\t\t\t\t\t\t\t\t\t pxcCluster: \"${pxcCluster}\"\n\t\t\t\t\t\t\t\t\t storageName: \"gcp-cs\"\n\t\t\t\t\t\t\tEOF\n\t\t\t\t\t\t\t"
- env:
- - name: pxcCluster
- value: scheduled-backup
- imagePullPolicy: Always
- name: run-backup
- resources:
- requests:
- cpu: 600m
- memory: 1G
- terminationMessagePath: /dev/termination-log
- terminationMessagePolicy: File
- dnsPolicy: ClusterFirst
- nodeSelector:
- backupWorker: "True"
- priorityClassName: high-priority
- restartPolicy: Never
- schedulerName: default-scheduler
- securityContext:
- supplementalGroups:
- - 1001
- serviceAccount: percona-xtradb-cluster-operator
- serviceAccountName: percona-xtradb-cluster-operator
- terminationGracePeriodSeconds: 30
- tolerations:
- - effect: NoSchedule
- key: backupWorker
- operator: Equal
- value: "True"
- schedule: '* * * * *'
- successfulJobsHistoryLimit: 1
- suspend: false

DELETE
e2e-tests/scheduled-backup/compare/cronjob_f875c-each-min-gcp-cs.yml
-apiVersion: batch/v1beta1
-kind: CronJob
-metadata:
- annotations:
- testName: scheduled-backup
- labels:
- backupWorker: "True"
- cluster: scheduled-backup
- schedule: N_N_N_N_N
- type: cron
- name: f875c-each-min-gcp-cs
- ownerReferences:
- - controller: true
- kind: PerconaXtraDBCluster
- name: scheduled-backup
-spec:
- concurrencyPolicy: Allow
- failedJobsHistoryLimit: 1
- jobTemplate:
- metadata:
- ownerReferences:
- - apiVersion: batch/v1beta1
- kind: CronJob
- name: f875c-each-min-gcp-cs
- spec:
- template:
- metadata:
- annotations:
- testName: scheduled-backup
- labels:
- backupWorker: "True"
- cluster: scheduled-backup
- schedule: N_N_N_N_N
- type: cron
- spec:
- affinity:
- nodeAffinity:
- requiredDuringSchedulingIgnoredDuringExecution:
- nodeSelectorTerms:
- - matchExpressions:
- - key: backupWorker
- operator: In
- values:
- - "True"
- containers:
- - args:
- - sh
- - -c
- - "\n\t\t\t\t\t\t\tcat <<-EOF | kubectl apply -f -\n\t\t\t\t\t\t\t\t\tapiVersion: pxc.percona.com/v1\n\t\t\t\t\t\t\t\t\tkind: PerconaXtraDBClusterBackup\n\t\t\t\t\t\t\t\t\tmetadata:\n\t\t\t\t\t\t\t\t\t finalizers: [delete-s3-backup ]\n\t\t\t\t\t\t\t\t\t name: \"cron-${pxcCluster:0:16}-gcp-cs-$(date -u \"+%Y%m%d%H%M%S\")-${suffix}\"\n\t\t\t\t\t\t\t\t\t labels:\n\t\t\t\t\t\t\t\t\t ancestor: \"f875c-each-min-gcp-cs\"\n\t\t\t\t\t\t\t\t\t cluster: \"${pxcCluster}\"\n\t\t\t\t\t\t\t\t\t type: \"cron\"\n\t\t\t\t\t\t\t\t\tspec:\n\t\t\t\t\t\t\t\t\t pxcCluster: \"${pxcCluster}\"\n\t\t\t\t\t\t\t\t\t storageName: \"gcp-cs\"\n\t\t\t\t\t\t\tEOF\n\t\t\t\t\t\t\t"
- env:
- - name: pxcCluster
- value: scheduled-backup
- imagePullPolicy: Always
- name: run-backup
- resources:
- requests:
- cpu: 600m
- memory: 1G
- terminationMessagePath: /dev/termination-log
- terminationMessagePolicy: File
- dnsPolicy: ClusterFirst
- nodeSelector:
- backupWorker: "True"
- priorityClassName: high-priority
- restartPolicy: Never
- schedulerName: default-scheduler
- securityContext:
- fsGroup: 1001
- supplementalGroups:
- - 1001
- serviceAccount: percona-xtradb-cluster-operator
- serviceAccountName: percona-xtradb-cluster-operator
- terminationGracePeriodSeconds: 30
- tolerations:
- - effect: NoSchedule
- key: backupWorker
- operator: Equal
- value: "True"
- schedule: '* * * * *'
- successfulJobsHistoryLimit: 1
- suspend: false

DELETE
e2e-tests/scheduled-backup/compare/cronjob_f875c-each-min-minio-oc.yml
-apiVersion: batch/v1beta1
-kind: CronJob
-metadata:
- annotations:
- testName: scheduled-backup
- labels:
- backupWorker: "True"
- cluster: scheduled-backup
- schedule: N_N_N_N_N
- type: cron
- name: f875c-each-min-minio
- ownerReferences:
- - controller: true
- kind: PerconaXtraDBCluster
- name: scheduled-backup
-spec:
- concurrencyPolicy: Allow
- failedJobsHistoryLimit: 1
- jobTemplate:
- metadata:
- ownerReferences:
- - apiVersion: batch/v1beta1
- kind: CronJob
- name: f875c-each-min-minio
- spec:
- template:
- metadata:
- annotations:
- testName: scheduled-backup
- labels:
- backupWorker: "True"
- cluster: scheduled-backup
- schedule: N_N_N_N_N
- type: cron
- spec:
- affinity:
- nodeAffinity:
- requiredDuringSchedulingIgnoredDuringExecution:
- nodeSelectorTerms:
- - matchExpressions:
- - key: backupWorker
- operator: In
- values:
- - "True"
- containers:
- - args:
- - sh
- - -c
- - "\n\t\t\t\t\t\t\tcat <<-EOF | kubectl apply -f -\n\t\t\t\t\t\t\t\t\tapiVersion: pxc.percona.com/v1\n\t\t\t\t\t\t\t\t\tkind: PerconaXtraDBClusterBackup\n\t\t\t\t\t\t\t\t\tmetadata:\n\t\t\t\t\t\t\t\t\t finalizers: [delete-s3-backup ]\n\t\t\t\t\t\t\t\t\t name: \"cron-${pxcCluster:0:16}-minio-$(date -u \"+%Y%m%d%H%M%S\")-${suffix}\"\n\t\t\t\t\t\t\t\t\t labels:\n\t\t\t\t\t\t\t\t\t ancestor: \"f875c-each-min-minio\"\n\t\t\t\t\t\t\t\t\t cluster: \"${pxcCluster}\"\n\t\t\t\t\t\t\t\t\t type: \"cron\"\n\t\t\t\t\t\t\t\t\tspec:\n\t\t\t\t\t\t\t\t\t pxcCluster: \"${pxcCluster}\"\n\t\t\t\t\t\t\t\t\t storageName: \"minio\"\n\t\t\t\t\t\t\tEOF\n\t\t\t\t\t\t\t"
- env:
- - name: pxcCluster
- value: scheduled-backup
- imagePullPolicy: Always
- name: run-backup
- resources:
- requests:
- cpu: 600m
- memory: 1G
- terminationMessagePath: /dev/termination-log
- terminationMessagePolicy: File
- dnsPolicy: ClusterFirst
- nodeSelector:
- backupWorker: "True"
- priorityClassName: high-priority
- restartPolicy: Never
- schedulerName: default-scheduler
- securityContext:
- supplementalGroups:
- - 1001
- serviceAccount: percona-xtradb-cluster-operator
- serviceAccountName: percona-xtradb-cluster-operator
- terminationGracePeriodSeconds: 30
- tolerations:
- - effect: NoSchedule
- key: backupWorker
- operator: Equal
- value: "True"
- schedule: '* * * * *'
- successfulJobsHistoryLimit: 1
- suspend: false

DELETE
e2e-tests/scheduled-backup/compare/cronjob_f875c-each-min-minio.yml
-apiVersion: batch/v1beta1
-kind: CronJob
-metadata:
- annotations:
- testName: scheduled-backup
- labels:
- backupWorker: "True"
- cluster: scheduled-backup
- schedule: N_N_N_N_N
- type: cron
- name: f875c-each-min-minio
- ownerReferences:
- - controller: true
- kind: PerconaXtraDBCluster
- name: scheduled-backup
-spec:
- concurrencyPolicy: Allow
- failedJobsHistoryLimit: 1
- jobTemplate:
- metadata:
- ownerReferences:
- - apiVersion: batch/v1beta1
- kind: CronJob
- name: f875c-each-min-minio
- spec:
- template:
- metadata:
- annotations:
- testName: scheduled-backup
- labels:
- backupWorker: "True"
- cluster: scheduled-backup
- schedule: N_N_N_N_N
- type: cron
- spec:
- affinity:
- nodeAffinity:
- requiredDuringSchedulingIgnoredDuringExecution:
- nodeSelectorTerms:
- - matchExpressions:
- - key: backupWorker
- operator: In
- values:
- - "True"
- containers:
- - args:
- - sh
- - -c
- - "\n\t\t\t\t\t\t\tcat <<-EOF | kubectl apply -f -\n\t\t\t\t\t\t\t\t\tapiVersion: pxc.percona.com/v1\n\t\t\t\t\t\t\t\t\tkind: PerconaXtraDBClusterBackup\n\t\t\t\t\t\t\t\t\tmetadata:\n\t\t\t\t\t\t\t\t\t finalizers: [delete-s3-backup ]\n\t\t\t\t\t\t\t\t\t name: \"cron-${pxcCluster:0:16}-minio-$(date -u \"+%Y%m%d%H%M%S\")-${suffix}\"\n\t\t\t\t\t\t\t\t\t labels:\n\t\t\t\t\t\t\t\t\t ancestor: \"f875c-each-min-minio\"\n\t\t\t\t\t\t\t\t\t cluster: \"${pxcCluster}\"\n\t\t\t\t\t\t\t\t\t type: \"cron\"\n\t\t\t\t\t\t\t\t\tspec:\n\t\t\t\t\t\t\t\t\t pxcCluster: \"${pxcCluster}\"\n\t\t\t\t\t\t\t\t\t storageName: \"minio\"\n\t\t\t\t\t\t\tEOF\n\t\t\t\t\t\t\t"
- env:
- - name: pxcCluster
- value: scheduled-backup
- imagePullPolicy: Always
- name: run-backup
- resources:
- requests:
- cpu: 600m
- memory: 1G
- terminationMessagePath: /dev/termination-log
- terminationMessagePolicy: File
- dnsPolicy: ClusterFirst
- nodeSelector:
- backupWorker: "True"
- priorityClassName: high-priority
- restartPolicy: Never
- schedulerName: default-scheduler
- securityContext:
- fsGroup: 1001
- supplementalGroups:
- - 1001
- serviceAccount: percona-xtradb-cluster-operator
- serviceAccountName: percona-xtradb-cluster-operator
- terminationGracePeriodSeconds: 30
- tolerations:
- - effect: NoSchedule
- key: backupWorker
- operator: Equal
- value: "True"
- schedule: '* * * * *'
- successfulJobsHistoryLimit: 1
- suspend: false

DELETE
e2e-tests/scheduled-backup/compare/cronjob_f875c-each-min-pvc-oc.yml
-apiVersion: batch/v1beta1
-kind: CronJob
-metadata:
- annotations:
- testName: scheduled-backup
- labels:
- backupWorker: "True"
- cluster: scheduled-backup
- schedule: N_N_N_N_N
- type: cron
- name: f875c-each-min-pvc
- ownerReferences:
- - controller: true
- kind: PerconaXtraDBCluster
- name: scheduled-backup
-spec:
- concurrencyPolicy: Allow
- failedJobsHistoryLimit: 1
- jobTemplate:
- metadata:
- ownerReferences:
- - apiVersion: batch/v1beta1
- kind: CronJob
- name: f875c-each-min-pvc
- spec:
- template:
- metadata:
- annotations:
- testName: scheduled-backup
- labels:
- backupWorker: "True"
- cluster: scheduled-backup
- schedule: N_N_N_N_N
- type: cron
- spec:
- affinity:
- nodeAffinity:
- requiredDuringSchedulingIgnoredDuringExecution:
- nodeSelectorTerms:
- - matchExpressions:
- - key: backupWorker
- operator: In
- values:
- - "True"
- containers:
- - args:
- - sh
- - -c
- - "\n\t\t\t\t\t\t\tcat <<-EOF | kubectl apply -f -\n\t\t\t\t\t\t\t\t\tapiVersion: pxc.percona.com/v1\n\t\t\t\t\t\t\t\t\tkind: PerconaXtraDBClusterBackup\n\t\t\t\t\t\t\t\t\tmetadata:\n\t\t\t\t\t\t\t\t\t finalizers: [ ]\n\t\t\t\t\t\t\t\t\t name: \"cron-${pxcCluster:0:16}-pvc-$(date -u \"+%Y%m%d%H%M%S\")-${suffix}\"\n\t\t\t\t\t\t\t\t\t labels:\n\t\t\t\t\t\t\t\t\t ancestor: \"f875c-each-min-pvc\"\n\t\t\t\t\t\t\t\t\t cluster: \"${pxcCluster}\"\n\t\t\t\t\t\t\t\t\t type: \"cron\"\n\t\t\t\t\t\t\t\t\tspec:\n\t\t\t\t\t\t\t\t\t pxcCluster: \"${pxcCluster}\"\n\t\t\t\t\t\t\t\t\t storageName: \"pvc\"\n\t\t\t\t\t\t\tEOF\n\t\t\t\t\t\t\t"
- env:
- - name: pxcCluster
- value: scheduled-backup
- imagePullPolicy: Always
- name: run-backup
- resources:
- requests:
- cpu: 600m
- memory: 1G
- terminationMessagePath: /dev/termination-log
- terminationMessagePolicy: File
- dnsPolicy: ClusterFirst
- nodeSelector:
- backupWorker: "True"
- priorityClassName: high-priority
- restartPolicy: Never
- schedulerName: default-scheduler
- securityContext:
- supplementalGroups:
- - 1001
- serviceAccount: percona-xtradb-cluster-operator
- serviceAccountName: percona-xtradb-cluster-operator
- terminationGracePeriodSeconds: 30
- tolerations:
- - effect: NoSchedule
- key: backupWorker
- operator: Equal
- value: "True"
- schedule: '* * * * *'
- successfulJobsHistoryLimit: 1
- suspend: false

DELETE
e2e-tests/scheduled-backup/compare/cronjob_f875c-each-min-pvc.yml
-apiVersion: batch/v1beta1
-kind: CronJob
-metadata:
- annotations:
- testName: scheduled-backup
- labels:
- backupWorker: "True"
- cluster: scheduled-backup
- schedule: N_N_N_N_N
- type: cron
- name: f875c-each-min-pvc
- ownerReferences:
- - controller: true
- kind: PerconaXtraDBCluster
- name: scheduled-backup
-spec:
- concurrencyPolicy: Allow
- failedJobsHistoryLimit: 1
- jobTemplate:
- metadata:
- ownerReferences:
- - apiVersion: batch/v1beta1
- kind: CronJob
- name: f875c-each-min-pvc
- spec:
- template:
- metadata:
- annotations:
- testName: scheduled-backup
- labels:
- backupWorker: "True"
- cluster: scheduled-backup
- schedule: N_N_N_N_N
- type: cron
- spec:
- affinity:
- nodeAffinity:
- requiredDuringSchedulingIgnoredDuringExecution:
- nodeSelectorTerms:
- - matchExpressions:
- - key: backupWorker
- operator: In
- values:
- - "True"
- containers:
- - args:
- - sh
- - -c
- - "\n\t\t\t\t\t\t\tcat <<-EOF | kubectl apply -f -\n\t\t\t\t\t\t\t\t\tapiVersion: pxc.percona.com/v1\n\t\t\t\t\t\t\t\t\tkind: PerconaXtraDBClusterBackup\n\t\t\t\t\t\t\t\t\tmetadata:\n\t\t\t\t\t\t\t\t\t finalizers: [ ]\n\t\t\t\t\t\t\t\t\t name: \"cron-${pxcCluster:0:16}-pvc-$(date -u \"+%Y%m%d%H%M%S\")-${suffix}\"\n\t\t\t\t\t\t\t\t\t labels:\n\t\t\t\t\t\t\t\t\t ancestor: \"f875c-each-min-pvc\"\n\t\t\t\t\t\t\t\t\t cluster: \"${pxcCluster}\"\n\t\t\t\t\t\t\t\t\t type: \"cron\"\n\t\t\t\t\t\t\t\t\tspec:\n\t\t\t\t\t\t\t\t\t pxcCluster: \"${pxcCluster}\"\n\t\t\t\t\t\t\t\t\t storageName: \"pvc\"\n\t\t\t\t\t\t\tEOF\n\t\t\t\t\t\t\t"
- env:
- - name: pxcCluster
- value: scheduled-backup
- imagePullPolicy: Always
- name: run-backup
- resources:
- requests:
- cpu: 600m
- memory: 1G
- terminationMessagePath: /dev/termination-log
- terminationMessagePolicy: File
- dnsPolicy: ClusterFirst
- nodeSelector:
- backupWorker: "True"
- priorityClassName: high-priority
- restartPolicy: Never
- schedulerName: default-scheduler
- securityContext:
- fsGroup: 1001
- supplementalGroups:
- - 1001
- serviceAccount: percona-xtradb-cluster-operator
- serviceAccountName: percona-xtradb-cluster-operator
- terminationGracePeriodSeconds: 30
- tolerations:
- - effect: NoSchedule
- key: backupWorker
- operator: Equal
- value: "True"
- schedule: '* * * * *'
- successfulJobsHistoryLimit: 1
- suspend: false

MODIFY
e2e-tests/scheduled-backup/run
e2e-tests/scheduled-backup/run
@@ -170,15 +170,6 @@ main() {
label_node
sleep 20
- if [ -n "$OPERATOR_NS" ]; then
- kubectl_bin config set-context "$(kubectl_bin config current-context)" --namespace="$OPERATOR_NS"
- fi
- compare_kubectl cronjob/f875c-each-min-pvc
- compare_kubectl cronjob/f875c-each-min-minio
- if [ -z "$SKIP_BACKUPS_TO_AWS_GCP" ]; then
- compare_kubectl cronjob/f875c-each-min-aws-s3
- compare_kubectl cronjob/f875c-each-min-gcp-cs
- fi
kubectl_bin config set-context "$(kubectl_bin config current-context)" --namespace="$namespace"
sleep 300
@@ -203,20 +194,6 @@ main() {
POD_GCP_BACKUP=$(kubectl_bin get pods | grep ${JOB_GCP_BACKUP%-*} | awk '{print $1}')
fi
- compare_extrafields job ${JOB_PVC_BACKUP}
- compare_extrafields pod ${POD_PVC_BACKUP}
-
- compare_extrafields job ${JOB_MINIO_BACKUP}
- compare_extrafields pod ${POD_MINIO_BACKUP}
-
- if [ -z "$SKIP_BACKUPS_TO_AWS_GCP" ]; then
- compare_extrafields job ${JOB_AWS_BACKUP}
- compare_extrafields pod ${POD_AWS_BACKUP}
-
- compare_extrafields job ${JOB_GCP_BACKUP}
- compare_extrafields pod ${POD_GCP_BACKUP}
- fi
-
backup_name_pvc=$(get_backup_name "pvc")
backup_name_minio=$(get_backup_name "minio")
if [ -z "$SKIP_BACKUPS_TO_AWS_GCP" ]; then

DELETE
e2e-tests/security-context/compare/cronjob_adc5a-each-hour-pvc.yml
-apiVersion: batch/v1beta1
-kind: CronJob
-metadata:
- annotations:
- openshift.io/scc: privileged
- labels:
- cluster: sec-context
- schedule: 0_NE1_N_N_N
- type: cron
- name: adc5a-each-hour-pvc
- ownerReferences:
- - controller: true
- kind: PerconaXtraDBCluster
- name: sec-context
-spec:
- concurrencyPolicy: Allow
- failedJobsHistoryLimit: 1
- jobTemplate:
- metadata:
- ownerReferences:
- - apiVersion: batch/v1beta1
- kind: CronJob
- name: adc5a-each-hour-pvc
- spec:
- template:
- metadata:
- annotations:
- openshift.io/scc: privileged
- labels:
- cluster: sec-context
- schedule: 0_NE1_N_N_N
- type: cron
- spec:
- containers:
- - args:
- - sh
- - -c
- - "\n\t\t\t\t\t\t\tcat <<-EOF | kubectl apply -f -\n\t\t\t\t\t\t\t\t\tapiVersion: pxc.percona.com/v1\n\t\t\t\t\t\t\t\t\tkind: PerconaXtraDBClusterBackup\n\t\t\t\t\t\t\t\t\tmetadata:\n\t\t\t\t\t\t\t\t\t finalizers: [ ]\n\t\t\t\t\t\t\t\t\t name: \"cron-${pxcCluster:0:16}-pvc-$(date -u \"+%Y%m%d%H%M%S\")-${suffix}\"\n\t\t\t\t\t\t\t\t\t labels:\n\t\t\t\t\t\t\t\t\t ancestor: \"adc5a-each-hour-pvc\"\n\t\t\t\t\t\t\t\t\t cluster: \"${pxcCluster}\"\n\t\t\t\t\t\t\t\t\t type: \"cron\"\n\t\t\t\t\t\t\t\t\tspec:\n\t\t\t\t\t\t\t\t\t pxcCluster: \"${pxcCluster}\"\n\t\t\t\t\t\t\t\t\t storageName: \"pvc\"\n\t\t\t\t\t\t\tEOF\n\t\t\t\t\t\t\t"
- env:
- - name: pxcCluster
- value: sec-context
- imagePullPolicy: Always
- name: run-backup
- resources: {}
- securityContext:
- privileged: true
- terminationMessagePath: /dev/termination-log
- terminationMessagePolicy: File
- dnsPolicy: ClusterFirst
- restartPolicy: Never
- schedulerName: default-scheduler
- securityContext:
- fsGroup: 1001
- supplementalGroups:
- - 1001
- - 1002
- - 1003
- serviceAccount: percona-xtradb-cluster-operator
- serviceAccountName: percona-xtradb-cluster-operator
- terminationGracePeriodSeconds: 30
- schedule: 0 */1 * * *
- successfulJobsHistoryLimit: 1
- suspend: false

MODIFY
e2e-tests/security-context/run
e2e-tests/security-context/run
@@ -45,10 +45,6 @@ kubectl_bin apply -f "$test_dir/conf/$cluster-$backup.yml"
wait_backup $backup
compare_kubectl job.batch/xb-$backup
-if [ -n "$OPERATOR_NS" ]; then
- kubectl_bin config set-context "$(kubectl_bin config current-context)" --namespace="$OPERATOR_NS"
-fi
-compare_kubectl cronjob/adc5a-each-hour-pvc
kubectl_bin config set-context "$(kubectl_bin config current-context)" --namespace="$namespace"
desc 'run pvc restore'

MODIFY
pkg/controller/pxc/backup.go
pkg/controller/pxc/backup.go
@@ -6,11 +6,14 @@ import (
"crypto/sha1"
"encoding/hex"
"fmt"
- "reflect"
+ "hash/crc32"
+ "strconv"
+ "strings"
+ "time"
"github.com/pkg/errors"
+ "github.com/robfig/cron/v3"
appsv1 "k8s.io/api/apps/v1"
- batchv1beta1 "k8s.io/api/batch/v1beta1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
@@ -19,21 +22,20 @@ import (
api "github.com/percona/percona-xtradb-cluster-operator/pkg/apis/pxc/v1"
- "github.com/percona/percona-xtradb-cluster-operator/pkg/k8s"
"github.com/percona/percona-xtradb-cluster-operator/pkg/pxc/app/deployment"
- "github.com/percona/percona-xtradb-cluster-operator/pkg/pxc/backup"
)
+type BackupScheduleJob struct {
+ api.PXCScheduledBackupSchedule
+ JobID cron.EntryID
+}
+
func (r *ReconcilePerconaXtraDBCluster) reconcileBackups(cr *api.PerconaXtraDBCluster) error {
+ logger := r.logger("backup", cr.Namespace)
backups := make(map[string]api.PXCScheduledBackupSchedule)
- operatorPod, err := k8s.OperatorPod(r.client)
- if err != nil {
- return errors.Wrap(err, "get operator deployment")
- }
+ backupNamePrefix := backupJobClusterPrefix(cr.Name)
if cr.Spec.Backup != nil {
- bcpObj := backup.New(cr)
- backupNamePrefix := backupJobClusterPrefix(cr.Name)
if cr.Status.Status == api.AppStateReady && cr.Spec.Backup.PITR.Enabled && !cr.Spec.Pause {
binlogCollector, err := deployment.GetBinlogCollectorDeployment(cr)
@@ -59,86 +61,74 @@ func (r *ReconcilePerconaXtraDBCluster) reconcileBackups(cr *api.PerconaXtraDBCl
}
}
if !cr.Spec.Backup.PITR.Enabled || cr.Spec.Pause {
- err = r.deletePITR(cr)
+ err := r.deletePITR(cr)
if err != nil {
return errors.Wrap(err, "delete pitr")
}
}
- for _, bcp := range cr.Spec.Backup.Schedule {
+ for i, bcp := range cr.Spec.Backup.Schedule {
bcp.Name = backupNamePrefix + "-" + bcp.Name
backups[bcp.Name] = bcp
strg, ok := cr.Spec.Backup.Storages[bcp.StorageName]
if !ok {
- return fmt.Errorf("storage %s doesn't exist", bcp.StorageName)
- }
-
- bcpjob, err := bcpObj.Scheduled(&bcp, strg, operatorPod)
- if err != nil {
- return fmt.Errorf("unable to schedule backup: %w", err)
- }
- err = setControllerReference(cr, bcpjob, r.scheme)
- if err != nil {
- return fmt.Errorf("set owner ref to backup %s: %v", bcp.Name, err)
+ logger.Info("invalid storage name for backup", "backup name", cr.Spec.Backup.Schedule[i].Name, "storage name", bcp.StorageName)
+ continue
}
- // Check if this Job already exists
- currentBcpJob := new(batchv1beta1.CronJob)
- err = r.client.Get(context.TODO(), types.NamespacedName{
- Name: bcpjob.Name,
- Namespace: bcpjob.Namespace,
- }, currentBcpJob)
- if err != nil && !k8serrors.IsNotFound(err) {
- return errors.Wrapf(err, "create scheduled backup %s", bcp.Name)
+ sch := BackupScheduleJob{}
+ schRaw, ok := r.crons.backupJobs.Load(bcp.Name)
+ if ok {
+ sch = schRaw.(BackupScheduleJob)
}
- if k8serrors.IsNotFound(err) {
- err = r.client.Create(context.TODO(), bcpjob)
- if err != nil {
- return errors.Wrapf(err, "create scheduled backup %s", bcp.Name)
- }
- } else if !reflect.DeepEqual(currentBcpJob.Spec, bcpjob.Spec) {
- err = r.client.Update(context.TODO(), bcpjob)
+ if !ok || sch.PXCScheduledBackupSchedule.Schedule != bcp.Schedule ||
+ sch.PXCScheduledBackupSchedule.StorageName != bcp.StorageName {
+ r.log.Info("Creating or updating backup job", "name", bcp.Name, "schedule", bcp.Schedule)
+ r.deleteBackupJob(bcp.Name)
+ jobID, err := r.crons.crons.AddFunc(bcp.Schedule, r.createBackupJob(cr, bcp, strg.Type))
if err != nil {
- return errors.Wrapf(err, "update backup schedule %s", bcp.Name)
+ logger.Error(err, "can't parse cronjob schedule", "backup name", cr.Spec.Backup.Schedule[i].Name, "schedule", bcp.Schedule)
+ continue
}
+
+ r.crons.backupJobs.Store(bcp.Name, BackupScheduleJob{
+ PXCScheduledBackupSchedule: bcp,
+ JobID: jobID,
+ })
}
}
}
- // Reconcile backups list
- bcpList := batchv1beta1.CronJobList{}
- err = r.client.List(context.TODO(),
- &bcpList,
- &client.ListOptions{
- Namespace: operatorPod.ObjectMeta.Namespace,
- LabelSelector: labels.SelectorFromSet(map[string]string{
- "cluster": cr.Name,
- "type": "cron",
- }),
- },
- )
- if err != nil {
- return fmt.Errorf("get backups list: %v", err)
+ r.crons.backupJobs.Range(func(k, v interface{}) bool {
+ item := v.(BackupScheduleJob)
+ if !strings.HasPrefix(item.Name, backupNamePrefix) {
+ return true
}
-
- for _, item := range bcpList.Items {
if spec, ok := backups[item.Name]; ok {
if spec.Keep > 0 {
oldjobs, err := r.oldScheduledBackups(cr, item.Name, spec.Keep)
if err != nil {
- return fmt.Errorf("remove old backups: %v", err)
+ logger.Error(err, "failed to list old backups", "job name", item.Name)
+ return true
}
for _, todel := range oldjobs {
- _ = r.client.Delete(context.TODO(), &todel)
+ err = r.client.Delete(context.TODO(), &todel)
+ if err != nil {
+ logger.Error(err, "failed to delete old backup", "backup name", todel.Name)
}
}
- } else {
- _ = r.client.Delete(context.TODO(), &item)
+
}
+ } else {
+ r.log.Info("deleting outdated backup job", "name", item.Name)
+ r.deleteBackupJob(item.Name)
}
+ return true
+ })
+
return nil
}
@@ -192,6 +182,81 @@ func (r *ReconcilePerconaXtraDBCluster) oldScheduledBackups(cr *api.PerconaXtraD
return ret, nil
}
+func (r *ReconcilePerconaXtraDBCluster) createBackupJob(cr *api.PerconaXtraDBCluster, backupJob api.PXCScheduledBackupSchedule, storageType api.BackupStorageType) func() {
+ fins := []string{}
+ if storageType == api.BackupStorageS3 {
+ fins = append(fins, api.FinalizerDeleteS3Backup)
+ }
+
+ return func() {
+ localCr := &api.PerconaXtraDBCluster{}
+ err := r.client.Get(context.TODO(), types.NamespacedName{Name: cr.Name, Namespace: cr.Namespace}, localCr)
+ if k8serrors.IsNotFound(err) {
+ r.log.Info("cluster is not found, deleting the job",
+ "job name", jobName, "cluster", cr.Name, "namespace", cr.Namespace)
+ r.deleteBackupJob(backupJob.Name)
+ return
+ }
+
+ bcp := &api.PerconaXtraDBClusterBackup{
+ ObjectMeta: metav1.ObjectMeta{
+ Finalizers: fins,
+ Namespace: cr.Namespace,
+ Name: generateBackupName(cr, backupJob.StorageName) + "-" + strconv.FormatUint(uint64(crc32.ChecksumIEEE([]byte(backupJob.Schedule))), 32)[:5],
+ Labels: map[string]string{
+ "ancestor": backupJob.Name,
+ "cluster": cr.Name,
+ "type": "cron",
+ },
+ },
+ Spec: api.PXCBackupSpec{
+ PXCCluster: cr.Name,
+ StorageName: backupJob.StorageName,
+ },
+ }
+ err = r.client.Create(context.TODO(), bcp)
+ if err != nil {
+ r.log.Error(err, "failed to create backup")
+ }
+ }
+}
+
+func (r *ReconcilePerconaXtraDBCluster) deleteBackupJob(name string) {
+ job, ok := r.crons.backupJobs.LoadAndDelete(name)
+ if !ok {
+ return
+ }
+ r.crons.crons.Remove(job.(BackupScheduleJob).JobID)
+}
+
+func generateBackupName(cr *api.PerconaXtraDBCluster, storageName string) string {
+ result := "cron-"
+ if len(cr.Name) > 16 {
+ result += cr.Name[:16]
+ } else {
+ result += cr.Name
+ }
+ result += "-" + trimNameRight(storageName, 16) + "-"
+ tnow := time.Now()
+ result += fmt.Sprintf("%d%d%d%d%d%d", tnow.Year(), tnow.Month(), tnow.Day(), tnow.Hour(), tnow.Minute(), tnow.Second())
+ return result
+}
+
+func trimNameRight(name string, ln int) string {
+ if len(name) <= ln {
+ ln = len(name)
+ }
+
+ for ; ln > 0; ln-- {
+ if name[ln-1] >= 'a' && name[ln-1] <= 'z' ||
+ name[ln-1] >= '0' && name[ln-1] <= '9' {
+ break
+ }
+ }
+
+ return name[:ln]
+}
+
// A minHeap is a min-heap of backup jobs.
type minHeap []api.PerconaXtraDBClusterBackup

MODIFY
pkg/controller/pxc/controller.go
pkg/controller/pxc/controller.go
@@ -151,12 +151,13 @@ const (
type CronRegistry struct {
crons *cron.Cron
- jobs map[string]Shedule
+ ensureVersionJobs map[string]Schedule
+ backupJobs *sync.Map
}
-type Shedule struct {
+type Schedule struct {
ID int
- CronShedule string
+ CronSchedule string
}
const (
@@ -167,7 +168,8 @@ const (
func NewCronRegistry() CronRegistry {
c := CronRegistry{
crons: cron.New(),
- jobs: make(map[string]Shedule),
+ ensureVersionJobs: make(map[string]Schedule),
+ backupJobs: new(sync.Map),
}
c.crons.Start()

MODIFY
pkg/controller/pxc/version.go
pkg/controller/pxc/version.go
@@ -23,13 +23,13 @@ const never = "never"
const disabled = "disabled"
func (r *ReconcilePerconaXtraDBCluster) deleteEnsureVersion(jobName string) {
- r.crons.crons.Remove(cron.EntryID(r.crons.jobs[jobName].ID))
- delete(r.crons.jobs, jobName)
+ r.crons.crons.Remove(cron.EntryID(r.crons.ensureVersionJobs[jobName].ID))
+ delete(r.crons.ensureVersionJobs, jobName)
}
func (r *ReconcilePerconaXtraDBCluster) sheduleEnsurePXCVersion(cr *api.PerconaXtraDBCluster, vs VersionService) error {
jn := jobName(cr)
- schedule, ok := r.crons.jobs[jn]
+ schedule, ok := r.crons.ensureVersionJobs[jn]
if cr.Spec.UpdateStrategy != v1.SmartUpdateStatefulSetStrategyType ||
cr.Spec.UpgradeOptions.Schedule == "" ||
strings.ToLower(cr.Spec.UpgradeOptions.Apply) == never ||
@@ -40,14 +40,14 @@ func (r *ReconcilePerconaXtraDBCluster) sheduleEnsurePXCVersion(cr *api.PerconaX
return nil
}
- if ok && schedule.CronShedule == cr.Spec.UpgradeOptions.Schedule {
+ if ok && schedule.CronSchedule == cr.Spec.UpgradeOptions.Schedule {
return nil
}
logger := r.logger(cr.Name, cr.Namespace)
if ok {
- logger.Info("remove job because of new", "old", schedule.CronShedule, "new", cr.Spec.UpgradeOptions.Schedule)
+ logger.Info("remove job because of new", "old", schedule.CronSchedule, "new", cr.Spec.UpgradeOptions.Schedule)
r.deleteEnsureVersion(jn)
}
@@ -102,9 +102,9 @@ func (r *ReconcilePerconaXtraDBCluster) sheduleEnsurePXCVersion(cr *api.PerconaX
logger.Info("add new job", "name", jn, "schedule", cr.Spec.UpgradeOptions.Schedule)
- r.crons.jobs[jn] = Shedule{
+ r.crons.ensureVersionJobs[jn] = Schedule{
ID: int(id),
- CronShedule: cr.Spec.UpgradeOptions.Schedule,
+ CronSchedule: cr.Spec.UpgradeOptions.Schedule,
}
return nil

K8SPXC-701 fix cronjob updates (#841)