Skip to content

Commit

Permalink
chore: reduce teh nesting depth
Browse files Browse the repository at this point in the history
  • Loading branch information
fengluodb committed Oct 9, 2023
1 parent a3e6e25 commit 48691ae
Showing 1 changed file with 16 additions and 24 deletions.
40 changes: 16 additions & 24 deletions internal/cli/cmd/cluster/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package cluster

import (
"fmt"
dptypes "github.com/apecloud/kubeblocks/internal/dataprotection/types"
"io"
"strings"

Expand Down Expand Up @@ -230,37 +229,30 @@ func showDataProtection(backupPolicies []dpv1alpha1.BackupPolicy, backupSchedule
return
}
tbl := newTbl(out, "\nData Protection:", "BACKUP-REPO", "AUTO-BACKUP", "BACKUP-SCHEDULE", "BACKUP-METHOD", "BACKUP-RETENTION")
for _, policy := range backupPolicies {
if policy.Annotations[dptypes.DefaultBackupPolicyAnnotationKey] != "true" {
continue
}
if policy.Status.Phase != dpv1alpha1.AvailablePhase {
continue
}
for _, schedule := range backupSchedules {
backupRepo := printer.NoneString
backupMethod := printer.NoneString
backupSchedule := printer.NoneString
backupRetention := printer.NoneString
scheduleEnable := "Disabled"
for _, schedule := range backupSchedules {
if schedule.Spec.BackupPolicyName == policy.Name {
for _, shcedulePolicy := range schedule.Spec.Schedules {
if shcedulePolicy.Enabled != nil && *shcedulePolicy.Enabled {
scheduleEnable = "Enabled"
backupMethod = shcedulePolicy.BackupMethod
backupSchedule = shcedulePolicy.CronExpression
backupRetention = shcedulePolicy.RetentionPeriod.String()
break
}
}
break
for _, policy := range backupPolicies {
if policy.Name != schedule.Spec.BackupPolicyName {
continue
}
if policy.Spec.BackupRepoName != nil {
backupRepo = *policy.Spec.BackupRepoName
}
}
if policy.Spec.BackupRepoName != nil {
backupRepo = *policy.Spec.BackupRepoName
for _, schedulePolicy := range schedule.Spec.Schedules {
if schedulePolicy.Enabled != nil && *schedulePolicy.Enabled == false {
continue
}
scheduleEnable = "Enabled"
backupMethod = schedulePolicy.BackupMethod
backupSchedule = schedulePolicy.CronExpression
backupRetention = schedulePolicy.RetentionPeriod.String()
tbl.AddRow(backupRepo, scheduleEnable, backupSchedule, backupMethod, backupRetention)
}

tbl.AddRow(backupRepo, scheduleEnable, backupSchedule, backupMethod, backupRetention)
}
tbl.Print()
}
Expand Down

0 comments on commit 48691ae

Please sign in to comment.