Skip to content

Commit

Permalink
br: support iam with pod authorization and fix calcSizeLevel invalid (#…
Browse files Browse the repository at this point in the history
…5220) (#5222)

Signed-off-by: WangLe1321 <wangle1321@163.com>
Co-authored-by: WangLe1321 <wangle1321@163.com>
  • Loading branch information
ti-chi-bot and WangLe1321 authored Aug 3, 2023
1 parent ec03b10 commit 62f179f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cmd/backup-manager/app/util/backup_size.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 7 additions & 5 deletions pkg/fedvolumebackup/backup/backup_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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())
}
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions pkg/fedvolumebackup/restore/restore_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 62f179f

Please sign in to comment.