diff --git a/cmd/backup-manager/app/util/backup_size.go b/cmd/backup-manager/app/util/backup_size.go index 6582c42171..06be5303e6 100644 --- a/cmd/backup-manager/app/util/backup_size.go +++ b/cmd/backup-manager/app/util/backup_size.go @@ -151,9 +151,9 @@ func calcBackupSize(ctx context.Context, volumes map[string]string, level string volumeId := vid // sort snapshots by timestamp workerPool.ApplyOnErrorGroup(eg, func() error { - var snapSize uint64 + var snapSize, apiReq uint64 if level == CalculateAll || level == CalculateFullSize { - snapSize, apiReq, err := calculateSnapshotSize(volumeId, snapshotId) + snapSize, apiReq, err = calculateSnapshotSize(volumeId, snapshotId) if err != nil { return err } diff --git a/pkg/fedvolumebackup/backup/backup_manager.go b/pkg/fedvolumebackup/backup/backup_manager.go index a242070d2a..b12084376a 100644 --- a/pkg/fedvolumebackup/backup/backup_manager.go +++ b/pkg/fedvolumebackup/backup/backup_manager.go @@ -209,7 +209,7 @@ func (bm *backupManager) listAllBackupMembers(ctx context.Context, volumeBackup func (bm *backupManager) initializeVolumeBackup(ctx context.Context, volumeBackup *v1alpha1.VolumeBackup) error { initializeMember := volumeBackup.Spec.Clusters[0] kubeClient := bm.deps.FedClientset[initializeMember.K8sClusterName] - backupMember := bm.buildBackupMember(volumeBackup.Name, &initializeMember, &volumeBackup.Spec.Template, true) + backupMember := bm.buildBackupMember(volumeBackup.Name, &initializeMember, &volumeBackup.Spec.Template, volumeBackup.Annotations, true) backupMember, err := kubeClient.PingcapV1alpha1().Backups(backupMember.Namespace).Create(ctx, backupMember, metav1.CreateOptions{}) if err != nil { return controller.RequeueErrorf("create initialize backup member %s to cluster %s error: %s", backupMember.Name, initializeMember.K8sClusterName, err.Error()) @@ -266,7 +266,7 @@ func (bm *backupManager) executeVolumeBackup(ctx context.Context, volumeBackup * } kubeClient := bm.deps.FedClientset[memberCluster.K8sClusterName] - backupMember := bm.buildBackupMember(volumeBackup.Name, &memberCluster, &volumeBackup.Spec.Template, false) + backupMember := bm.buildBackupMember(volumeBackup.Name, &memberCluster, &volumeBackup.Spec.Template, volumeBackup.Annotations, false) if _, err := kubeClient.PingcapV1alpha1().Backups(memberCluster.TCNamespace).Create(ctx, backupMember, metav1.CreateOptions{}); err != nil { return false, controller.RequeueErrorf("create backup member %s to cluster %s error: %s", backupMember.Name, memberCluster.K8sClusterName, err.Error()) } @@ -394,11 +394,12 @@ func (bm *backupManager) updateVolumeBackupMembersToStatus(volumeBackupStatus *v } } -func (bm *backupManager) buildBackupMember(volumeBackupName string, clusterMember *v1alpha1.VolumeBackupMemberCluster, backupTemplate *v1alpha1.VolumeBackupMemberSpec, initialize bool) *pingcapv1alpha1.Backup { +func (bm *backupManager) buildBackupMember(volumeBackupName string, clusterMember *v1alpha1.VolumeBackupMemberCluster, backupTemplate *v1alpha1.VolumeBackupMemberSpec, annotations map[string]string, initialize bool) *pingcapv1alpha1.Backup { backupMember := &pingcapv1alpha1.Backup{ ObjectMeta: metav1.ObjectMeta{ - Name: bm.generateBackupMemberName(volumeBackupName, clusterMember.K8sClusterName), - Namespace: clusterMember.TCNamespace, + Name: bm.generateBackupMemberName(volumeBackupName, clusterMember.K8sClusterName), + Namespace: clusterMember.TCNamespace, + Annotations: annotations, }, Spec: pingcapv1alpha1.BackupSpec{ Mode: pingcapv1alpha1.BackupModeVolumeSnapshot, @@ -414,6 +415,7 @@ func (bm *backupManager) buildBackupMember(volumeBackupName string, clusterMembe ServiceAccount: backupTemplate.ServiceAccount, CleanPolicy: backupTemplate.CleanPolicy, PriorityClassName: backupTemplate.PriorityClassName, + CalcSizeLevel: backupTemplate.CalcSizeLevel, }, } backupMember.Spec.S3.Prefix = fmt.Sprintf("%s-%s", backupMember.Spec.S3.Prefix, clusterMember.K8sClusterName) diff --git a/pkg/fedvolumebackup/restore/restore_manager.go b/pkg/fedvolumebackup/restore/restore_manager.go index b4aab30d2a..e94017b7b9 100644 --- a/pkg/fedvolumebackup/restore/restore_manager.go +++ b/pkg/fedvolumebackup/restore/restore_manager.go @@ -210,7 +210,7 @@ func (rm *restoreManager) executeRestoreVolumePhase(ctx context.Context, volumeR } kubeClient := rm.deps.FedClientset[k8sClusterName] - restoreMember := rm.buildRestoreMember(volumeRestore.Name, &memberCluster, &volumeRestore.Spec.Template) + restoreMember := rm.buildRestoreMember(volumeRestore.Name, &memberCluster, &volumeRestore.Spec.Template, volumeRestore.Annotations) if _, err := kubeClient.PingcapV1alpha1().Restores(memberCluster.TCNamespace).Create(ctx, restoreMember, metav1.CreateOptions{}); err != nil { return false, fmt.Errorf("create restore member %s to cluster %s error: %s", restoreMember.Name, k8sClusterName, err.Error()) } @@ -477,11 +477,12 @@ func (rm *restoreManager) skipVolumeRestore(volumeRestore *v1alpha1.VolumeRestor return v1alpha1.IsVolumeRestoreComplete(volumeRestore) || v1alpha1.IsVolumeRestoreFailed(volumeRestore) } -func (rm *restoreManager) buildRestoreMember(volumeRestoreName string, memberCluster *v1alpha1.VolumeRestoreMemberCluster, template *v1alpha1.VolumeRestoreMemberSpec) *pingcapv1alpha1.Restore { +func (rm *restoreManager) buildRestoreMember(volumeRestoreName string, memberCluster *v1alpha1.VolumeRestoreMemberCluster, template *v1alpha1.VolumeRestoreMemberSpec, annotations map[string]string) *pingcapv1alpha1.Restore { restoreMember := &pingcapv1alpha1.Restore{ ObjectMeta: metav1.ObjectMeta{ - Name: rm.generateRestoreMemberName(volumeRestoreName, memberCluster.K8sClusterName), - Namespace: memberCluster.TCNamespace, + Name: rm.generateRestoreMemberName(volumeRestoreName, memberCluster.K8sClusterName), + Namespace: memberCluster.TCNamespace, + Annotations: annotations, }, Spec: pingcapv1alpha1.RestoreSpec{ Mode: pingcapv1alpha1.RestoreModeVolumeSnapshot,