Skip to content

Commit

Permalink
support handle breaking changes during upgrading kubeblocks
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyelei committed Oct 23, 2023
1 parent a150515 commit 800cb3f
Show file tree
Hide file tree
Showing 14 changed files with 1,114 additions and 6 deletions.
130 changes: 130 additions & 0 deletions BackupPolicy0.6.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
apiVersion: dataprotection.kubeblocks.io/v1alpha1
kind: BackupPolicy
metadata:
annotations:
apps.kubeblocks.io/backup-policy-template: postgresql-backup-policy-template
dataprotection.kubeblocks.io/is-default-policy: "true"
s: /fastgpt-mcqbpgda-pg-bbd2dc7a-dcf5-4154-bb14-a975a0c301b6/postgresql
dataprotection.kubeblocks.io/reconfigure-ref: |
{
"name": "postgresql-configuration",
"key": "postgresql.conf",
"enable": {
"logfile": [{"key": "archive_command","value": "''"}]
},
"disable": {
"logfile": [{ "key": "archive_command","value": "'/bin/true'"}]
}
}
creationTimestamp: "2023-09-26T07:05:49Z"
finalizers:
- cluster.kubeblocks.io/finalizer
- dataprotection.kubeblocks.io/finalizer
generation: 3
labels:
app.kubernetes.io/instance: fastgpt-mcqbpgda-pg
app.kubernetes.io/managed-by: kubeblocks
apps.kubeblocks.io/component-def-ref: postgresql
name: fastgpt-mcqbpgda-pg-postgresql-backup-policy
namespace: ns-pyde3id5
ownerReferences:
- apiVersion: apps.kubeblocks.io/v1alpha1
blockOwnerDeletion: true
controller: true
kind: Cluster
name: fastgpt-mcqbpgda-pg
uid: bbd2dc7a-dcf5-4154-bb14-a975a0c301b6
resourceVersion: "708125316"
uid: b4ef9d8a-0c26-4351-93d2-7235e68d9f1b
spec:
datafile:
backupStatusUpdates:
- containerName: postgresql
path: manifests.backupLog
script: /kb-scripts/backup-log-collector.sh true
updateStage: post
- containerName: postgresql
script: /kb-scripts/filesize-collector.sh basebackup.info
updateStage: post
backupToolName: postgres-basebackup
backupsHistoryLimit: 7
persistentVolumeClaim:
createPolicy: IfNotPresent
initCapacity: 20Gi
name: kubeblocks-backup-data
storageClassName: csi-s3
target:
labelsSelector:
matchLabels:
app.kubernetes.io/instance: fastgpt-mcqbpgda-pg
app.kubernetes.io/managed-by: kubeblocks
apps.kubeblocks.io/component-name: postgresql
secret:
name: fastgpt-mcqbpgda-pg-conn-credential
passwordKey: password
usernameKey: username
logfile:
backupStatusUpdates:
- containerName: postgresql
path: manifests.backupLog
script: /kb-scripts/backup-log-collector.sh false
updateStage: post
- containerName: postgresql
script: /kb-scripts/filesize-collector.sh logfile.info
updateStage: post
backupToolName: postgres-pitr
backupsHistoryLimit: 7
persistentVolumeClaim:
createPolicy: IfNotPresent
initCapacity: 20Gi
name: kubeblocks-backup-data
storageClassName: csi-s3
target:
labelsSelector:
matchLabels:
app.kubernetes.io/instance: fastgpt-mcqbpgda-pg
app.kubernetes.io/managed-by: kubeblocks
apps.kubeblocks.io/component-name: postgresql
secret:
name: fastgpt-mcqbpgda-pg-conn-credential
passwordKey: password
usernameKey: username
retention:
ttl: 100d
schedule:
datafile:
cronExpression: 00 18 * * *
enable: true
logfile:
cronExpression: '*/2 * * * *'
enable: false
snapshot:
cronExpression: 0 18 * * *
enable: false
startingDeadlineMinutes: 120
snapshot:
backupStatusUpdates:
- containerName: postgresql
path: manifests.backupLog
script: /kb-scripts/backup-log-collector.sh true
updateStage: post
backupsHistoryLimit: 7
hooks:
containerName: postgresql
preCommands:
- psql -c "CHECKPOINT;"
target:
labelsSelector:
matchLabels:
app.kubernetes.io/instance: fastgpt-mcqbpgda-pg
app.kubernetes.io/managed-by: kubeblocks
apps.kubeblocks.io/component-name: postgresql
secret:
name: fastgpt-mcqbpgda-pg-conn-credential
passwordKey: password
usernameKey: username
status:
lastScheduleTime: "2023-10-19T18:00:00Z"
observedGeneration: 3
phase: Available
$
76 changes: 76 additions & 0 deletions backup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@

apiVersion: dataprotection.kubeblocks.io/v1alpha1
kind: Backup
metadata:
annotations:
dataprotection.kubeblocks.io/target-pod-name: pg-postgresql-0
kubeblocks.io/cluster-snapshot: '{"metadata":{"name":"pg","namespace":"default","creationTimestamp":null},"spec":{"clusterDefinitionRef":"postgresql","clusterVersionRef":"postgresql-14.8.0","terminationPolicy":"Delete","componentSpecs":[{"name":"postgresql","componentDefRef":"postgresql","enabledLogs":["running"],"replicas":1,"resources":{"limits":{"cpu":"500m","memory":"512Mi"},"requests":{"cpu":"500m","memory":"512Mi"}},"volumeClaimTemplates":[{"name":"data","spec":{"accessModes":["ReadWriteOnce"],"resources":{"requests":{"storage":"20Gi"}}}}],"switchPolicy":{"type":"Noop"}}],"affinity":{"podAntiAffinity":"Preferred","topologyKeys":["kubernetes.io/hostname"],"tenancy":"SharedNode"},"resources":{"cpu":"0","memory":"0"},"storage":{"size":"0"},"monitor":{}},"status":{}}'
creationTimestamp: "2023-10-19T02:04:28Z"
finalizers:
- dataprotection.kubeblocks.io/finalizer
generation: 1
labels:
app.kubernetes.io/instance: pg
app.kubernetes.io/managed-by: kubeblocks
apps.kubeblocks.io/component-name: postgresql
dataprotection.kubeblocks.io/backup-repo-name: backuprepo-cxfzj
dataprotection.kubeblocks.io/backup-type: Full
dataprotection.kubeblocks.io/cluster-uid: 3da60857-860e-43ee-bdf0-e660e89f5348
kubeblocks.io/backup-protection: retain
name: backup-default-pg-20231019100428
namespace: default
resourceVersion: "5951129"
uid: b94e3ca6-a3ed-4af2-97e9-a8362e5e4ba1
spec:
backupMethod: pg-basebackup
backupPolicyName: pg-postgresql-backup-policy
deletionPolicy: Delete
status:
actions:
- actionType: Job
completionTimestamp: "2023-10-19T02:04:39Z"
name: dp-backup
objectRef:
apiVersion: batch/v1
kind: Job
name: dp-backup-backup-default-pg-20231019100428-b94e3ca6
namespace: default
resourceVersion: "5951126"
uid: d94cf70f-52fc-4dc5-98b8-a585ffa9d17b
phase: Completed
startTimestamp: "2023-10-19T02:04:29Z"
backupMethod:
actionSetName: postgres-basebackup
env:
- name: IMAGE_TAG
value: 14.8.0-pgvector-v0.5.0
name: pg-basebackup
snapshotVolumes: false
targetVolumes:
volumeMounts:
- mountPath: /home/postgres/pgdata
name: data
backupRepoName: backuprepo-cxfzj
completionTimestamp: "2023-10-19T02:04:39Z"
duration: 10s
formatVersion: 0.1.0
path: /default/pg-3da60857-860e-43ee-bdf0-e660e89f5348/postgresql/backup-default-pg-20231019100428
persistentVolumeClaimName: pvc-backuprepo-cxfzj-xz4bwt
phase: Completed
startTimestamp: "2023-10-19T02:04:29Z"
target:
connectionCredential:
passwordKey: password
secretName: pg-conn-credential
usernameKey: username
podSelector:
matchLabels:
app.kubernetes.io/instance: pg
app.kubernetes.io/managed-by: kubeblocks
apps.kubeblocks.io/component-name: postgresql
strategy: Any
serviceAccountName: kb-pg
timeRange:
end: "2023-10-19T02:04:30Z"
start: "2023-10-19T00:00:00Z"
totalSize: "4867834"
42 changes: 42 additions & 0 deletions backup0.6.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
piVersion: dataprotection.kubeblocks.io/v1alpha1
kind: Backup
metadata:
annotations:
dataprotection.kubeblocks.io/target-pod-name: fastgpt-mcqbpgda-pg-postgresql-0
kubeblocks.io/cluster-snapshot: '{"metadata":{"name":"fastgpt-mcqbpgda-pg","namespace":"ns-pyde3id5","creationTimestamp":null},"spec":{"clusterDefinitionRef":"postgresql","clusterVersionRef":"postgresql-14.8.0","terminationPolicy":"Delete","componentSpecs":[{"name":"postgresql","componentDefRef":"postgresql","monitor":true,"replicas":1,"resources":{"limits":{"cpu":"500m","memory":"512Mi"},"requests":{"cpu":"50m","memory":"51Mi"}},"volumeClaimTemplates":[{"name":"data","spec":{"accessModes":["ReadWriteOnce"],"resources":{"requests":{"storage":"3Gi"}},"storageClassName":"openebs-backup"}}],"switchPolicy":{"type":"Noop"},"serviceAccountName":"fastgpt-mcqbpgda-pg"}],"affinity":{"podAntiAffinity":"Preferred","tenancy":"SharedNode"},"resources":{"cpu":"0","memory":"0"},"storage":{"size":"0"},"monitor":{}},"status":{}}'
creationTimestamp: "2023-10-18T18:00:04Z"
finalizers:
- dataprotection.kubeblocks.io/finalizer
generation: 1
labels:
app.kubernetes.io/instance: fastgpt-mcqbpgda-pg
app.kubernetes.io/managed-by: kubeblocks
apps.kubeblocks.io/component-name: postgresql
dataprotection.kubeblocks.io/autobackup: "true"
dataprotection.kubeblocks.io/backup-type: datafile
dataprotection.kubeblocks.io/cluster-uid: bbd2dc7a-dcf5-4154-bb14-a975a0c301b6
name: backup-ns-pyde3id5-fastgpt-mcqbpgda-pg-20231018180002
namespace: ns-pyde3id5
resourceVersion: "704269629"
uid: 3875aeb0-b105-4df2-a095-d8c63a83d8b4
spec:
backupPolicyName: fastgpt-mcqbpgda-pg-postgresql-backup-policy
backupType: datafile
status:
backupToolName: postgres-basebackup
completionTimestamp: "2023-10-18T18:00:21Z"
duration: 18s
expiration: "2024-01-26T18:00:04Z"
manifests:
backupLog:
startTime: "2023-10-18T07:19:49Z"
stopTime: "2023-10-18T07:19:49Z"
backupTool:
filePath: /ns-pyde3id5/fastgpt-mcqbpgda-pg-bbd2dc7a-dcf5-4154-bb14-a975a0c301b6/postgresql/backup-ns-pyde3id5-fastgpt-mcqbpgda-pg-20231018180002
uploadTotalSize: 54M
volumeName: pvc-c8e829b3-612b-4bff-8ae7-c6e0e2891126
persistentVolumeClaimName: kubeblocks-backup-data
phase: Completed
sourceCluster: fastgpt-mcqbpgda-pg
startTimestamp: "2023-10-18T18:00:04Z"
totalSize: 54M
59 changes: 59 additions & 0 deletions backupPolicy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
apiVersion: dataprotection.kubeblocks.io/v1alpha1
kind: BackupPolicy
metadata:
annotations:
apps.kubeblocks.io/backup-policy-template: postgresql-backup-policy-template
dataprotection.kubeblocks.io/is-default-policy: "true"
creationTimestamp: "2023-10-18T07:24:12Z"
finalizers:
- cluster.kubeblocks.io/finalizer
- dataprotection.kubeblocks.io/finalizer
generation: 1
labels:
app.kubernetes.io/instance: pg
app.kubernetes.io/managed-by: kubeblocks
apps.kubeblocks.io/component-def-ref: postgresql
name: pg-postgresql-backup-policy
namespace: default
ownerReferences:
- apiVersion: apps.kubeblocks.io/v1alpha1
blockOwnerDeletion: true
controller: true
kind: Cluster
name: pg
uid: 3da60857-860e-43ee-bdf0-e660e89f5348
resourceVersion: "5918220"
uid: aab0285b-da1c-411f-8ee9-b00d8b254952
spec:
backupMethods:
- actionSetName: postgres-basebackup
env:
- name: IMAGE_TAG
value: 14.8.0-pgvector-v0.5.0
name: pg-basebackup
snapshotVolumes: false
targetVolumes:
volumeMounts:
- mountPath: /home/postgres/pgdata
name: data
- name: volume-snapshot
snapshotVolumes: true
targetVolumes:
volumes:
- data
pathPrefix: /pg-3da60857-860e-43ee-bdf0-e660e89f5348/postgresql
target:
connectionCredential:
passwordKey: password
secretName: pg-conn-credential
usernameKey: username
podSelector:
matchLabels:
app.kubernetes.io/instance: pg
app.kubernetes.io/managed-by: kubeblocks
apps.kubeblocks.io/component-name: postgresql
strategy: Any
serviceAccountName: kb-pg
status:
observedGeneration: 1
phase: Available
45 changes: 45 additions & 0 deletions backupSchedule
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
apiVersion: v1
items:
- apiVersion: dataprotection.kubeblocks.io/v1alpha1
kind: BackupSchedule
metadata:
annotations:
apps.kubeblocks.io/backup-policy-template: postgresql-backup-policy-template
dataprotection.kubeblocks.io/is-default-policy: "true"
creationTimestamp: "2023-10-20T03:06:34Z"
finalizers:
- cluster.kubeblocks.io/finalizer
- dataprotection.kubeblocks.io/finalizer
generation: 1
labels:
app.kubernetes.io/instance: pg
app.kubernetes.io/managed-by: kubeblocks
apps.kubeblocks.io/component-def-ref: postgresql
name: pg-postgresql-backup-schedule
namespace: default
ownerReferences:
- apiVersion: apps.kubeblocks.io/v1alpha1
blockOwnerDeletion: true
controller: true
kind: Cluster
name: pg
uid: 3da60857-860e-43ee-bdf0-e660e89f5348
resourceVersion: "6017392"
uid: 4a227fc1-a7af-4f49-9be6-15f9ca8ebf37
spec:
backupPolicyName: pg-postgresql-backup-policy
schedules:
- backupMethod: pg-basebackup
cronExpression: 0 18 * * *
enabled: false
retentionPeriod: 7d
- backupMethod: volume-snapshot
cronExpression: 0 18 * * *
enabled: false
retentionPeriod: 7d
status:
observedGeneration: 1
phase: Available
kind: List
metadata:
resourceVersion: ""
10 changes: 10 additions & 0 deletions backup_tools.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apecloud-mysql-pitr-tool 24d
mongodb-physical-backup-tool 168d
mongodb-pitr-backup-tool 24d
postgres-basebackup 144d
postgres-pitr 144d
postgres-wal-g 24d
qdrant-snapshot 24d
redis-physical-backup-tool 24d
xtrabackup-for-apecloud-mysql 144d
xtrabackup-for-apecloud-mysql-for-hscale 24d
3 changes: 2 additions & 1 deletion controllers/apps/transformer_backup_policy_tpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ func (r *BackupPolicyTplTransformer) buildBackupPolicy(backupPolicyName string)

// syncBackupMethods syncs the backupMethod of tpl to backupPolicy.
func (r *BackupPolicyTplTransformer) syncBackupMethods(backupPolicy *dpv1alpha1.BackupPolicy) {
// TODO: sync new created BackupMethods.
var backupMethods []dpv1alpha1.BackupMethod
for _, v := range r.backupPolicy.BackupMethods {
mappingEnv := r.doEnvMapping(v.EnvMapping)
Expand Down Expand Up @@ -425,7 +426,7 @@ func (r *BackupPolicyTplTransformer) mergeClusterBackup(
r.EventRecorder.Event(r.Cluster, corev1.EventTypeWarning,
"BackupPolicyNotFound", "backup policy is nil, can not enable cluster backup")
}
return nil
return backupSchedule
}

backup := cluster.Spec.Backup
Expand Down
Loading

0 comments on commit 800cb3f

Please sign in to comment.