Skip to content

Commit

Permalink
recall repo maintenance history on restart
Browse files Browse the repository at this point in the history
Signed-off-by: Lyndon-Li <[email protected]>
  • Loading branch information
Lyndon-Li committed Jan 15, 2025
1 parent fc96836 commit 3900f2f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
8 changes: 4 additions & 4 deletions pkg/controller/backup_repository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ type BackupRepoReconciler struct {
repositoryManager repomanager.Manager
keepLatestMaintenanceJobs int
repoMaintenanceConfig string
podResources kube.PodResources
maintenanceJobResources kube.PodResources
logLevel logrus.Level
logFormat *logging.FormatFlag
}

func NewBackupRepoReconciler(namespace string, logger logrus.FieldLogger, client client.Client, repositoryManager repomanager.Manager,
maintenanceFrequency time.Duration, backupRepoConfig string, keepLatestMaintenanceJobs int, repoMaintenanceConfig string, podResources kube.PodResources,
maintenanceFrequency time.Duration, backupRepoConfig string, keepLatestMaintenanceJobs int, repoMaintenanceConfig string, maintenanceJobResources kube.PodResources,
logLevel logrus.Level, logFormat *logging.FormatFlag) *BackupRepoReconciler {
c := &BackupRepoReconciler{
client,
Expand All @@ -83,7 +83,7 @@ func NewBackupRepoReconciler(namespace string, logger logrus.FieldLogger, client
repositoryManager,
keepLatestMaintenanceJobs,
repoMaintenanceConfig,
podResources,
maintenanceJobResources,
logLevel,
logFormat,
}
Expand Down Expand Up @@ -427,7 +427,7 @@ func (r *BackupRepoReconciler) runMaintenanceIfDue(ctx context.Context, req *vel

log.Info("Running maintenance on backup repository")

job, err := funcStartMaintenanceJob(r.Client, ctx, req, r.repoMaintenanceConfig, r.podResources, r.logLevel, r.logFormat, log)
job, err := funcStartMaintenanceJob(r.Client, ctx, req, r.repoMaintenanceConfig, r.maintenanceJobResources, r.logLevel, r.logFormat, log)
if err != nil {
log.WithError(err).Warn("Starting repo maintenance failed")
return r.patchBackupRepository(ctx, req, func(rr *velerov1api.BackupRepository) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/repository/maintenance/maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func WaitAllJobsComplete(ctx context.Context, cli client.Client, repo *velerov1a

history := []velerov1api.BackupRepositoryMaintenanceStatus{}

startPos := len(history) - limit
startPos := len(jobList.Items) - limit
if startPos < 0 {
startPos = 0
}
Expand Down
7 changes: 1 addition & 6 deletions pkg/repository/maintenance/maintenance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ func TestGetJobConfig(t *testing.T) {
}
}

func TestWaitAlJobsComplete(t *testing.T) {
func TestWaitAllJobsComplete(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*2)

veleroNamespace := "velero"
Expand Down Expand Up @@ -680,11 +680,6 @@ func TestWaitAlJobsComplete(t *testing.T) {
jobPodSucceeded3,
},
expectedStatus: []velerov1api.BackupRepositoryMaintenanceStatus{
{
Result: velerov1api.BackupRepositoryMaintenanceSucceeded,
StartTimestamp: &metav1.Time{Time: now},
CompleteTimestamp: &metav1.Time{Time: now.Add(time.Hour)},
},
{
Result: velerov1api.BackupRepositoryMaintenanceFailed,
StartTimestamp: &metav1.Time{Time: now.Add(time.Hour)},
Expand Down

0 comments on commit 3900f2f

Please sign in to comment.