Skip to content

Commit

Permalink
feat: add backup schedule info
Browse files Browse the repository at this point in the history
  • Loading branch information
fengluodb committed Oct 9, 2023
1 parent 868bb11 commit a3e6e25
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
3 changes: 3 additions & 0 deletions internal/cli/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ func (o *ObjectsGetter) Get() (*ClusterObjects, error) {
if err = listResources(o.Dynamic, types.BackupPolicyGVR(), o.Namespace, dpListOpts, &objs.BackupPolicies); err != nil {
return nil, err
}
if err = listResources(o.Dynamic, types.BackupScheduleGVR(), o.Namespace, dpListOpts, &objs.BackupSchedules); err != nil {
return nil, err
}
var backups []dpv1alpha1.Backup
if err = listResources(o.Dynamic, types.BackupGVR(), o.Namespace, dpListOpts, &backups); err != nil {
return nil, err
Expand Down
5 changes: 3 additions & 2 deletions internal/cli/cluster/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ type ClusterObjects struct {
ConfigMaps *corev1.ConfigMapList
Events *corev1.EventList

BackupPolicies []dpv1alpha1.BackupPolicy
Backups []dpv1alpha1.Backup
BackupPolicies []dpv1alpha1.BackupPolicy
BackupSchedules []dpv1alpha1.BackupSchedule
Backups []dpv1alpha1.Backup
}

type ClusterInfo struct {
Expand Down
37 changes: 28 additions & 9 deletions internal/cli/cmd/cluster/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package cluster

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

Expand All @@ -39,7 +40,6 @@ import (
"github.com/apecloud/kubeblocks/internal/cli/printer"
"github.com/apecloud/kubeblocks/internal/cli/types"
"github.com/apecloud/kubeblocks/internal/cli/util"
dptypes "github.com/apecloud/kubeblocks/internal/dataprotection/types"
)

var (
Expand Down Expand Up @@ -160,7 +160,7 @@ func (o *describeOptions) describeCluster(name string) error {
showImages(comps, o.Out)

// data protection info
showDataProtection(o.BackupPolicies, o.Backups, o.Out)
showDataProtection(o.BackupPolicies, o.BackupSchedules, o.Out)

// events
showEvents(o.Cluster.Name, o.Cluster.Namespace, o.Out)
Expand Down Expand Up @@ -225,23 +225,42 @@ func showEndpoints(c *appsv1alpha1.Cluster, svcList *corev1.ServiceList, out io.
tbl.Print()
}

func showDataProtection(backupPolicies []dpv1alpha1.BackupPolicy, backups []dpv1alpha1.Backup, out io.Writer) {
if len(backupPolicies) == 0 {
func showDataProtection(backupPolicies []dpv1alpha1.BackupPolicy, backupSchedules []dpv1alpha1.BackupSchedule, out io.Writer) {
if len(backupPolicies) == 0 || len(backupSchedules) == 0 {
return
}
tbl := newTbl(out, "\nData Protection:", "BACKUP-REPO", "PATH-PREFIX", "BACKOFF-LIMIT", "BACKUP-METHODS")
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
}
var methods []string
for _, m := range policy.Spec.BackupMethods {
methods = append(methods, m.Name)
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
}
}
tbl.AddRow(policy.Spec.BackupRepoName, policy.Spec.PathPrefix, policy.Spec.BackoffLimit, strings.Join(methods, ","))
if policy.Spec.BackupRepoName != nil {
backupRepo = *policy.Spec.BackupRepoName
}

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

0 comments on commit a3e6e25

Please sign in to comment.