add repo maintain result in history
Signed-off-by: Lyndon-Li <lyonghui@vmware.com>pull/8532/head
parent
c9bfd33077
commit
3b2c50b459
|
@ -0,0 +1 @@
|
|||
Fix issue #7810, add maintenance history for backupRepository CRs
|
|
@ -119,6 +119,12 @@ spec:
|
|||
description: Message is a message about the current status of
|
||||
the repo maintenance.
|
||||
type: string
|
||||
result:
|
||||
description: Result is the result of the repo maintenance.
|
||||
enum:
|
||||
- Succeeded
|
||||
- Failed
|
||||
type: string
|
||||
startTimestamp:
|
||||
description: StartTimestamp is the start time of the repo maintenance.
|
||||
format: date-time
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -81,7 +81,20 @@ type BackupRepositoryStatus struct {
|
|||
RecentMaintenanceStatus []BackupRepositoryMaintenanceStatus `json:"recentMaintenanceStatus,omitempty"`
|
||||
}
|
||||
|
||||
// BackupRepositoryMaintenanceResult represents the result of a repo maintenance.
|
||||
// +kubebuilder:validation:Enum=Succeeded;Failed
|
||||
type BackupRepositoryMaintenanceResult string
|
||||
|
||||
const (
|
||||
BackupRepositoryMaintenanceSucceeded BackupRepositoryMaintenanceResult = "Succeeded"
|
||||
BackupRepositoryMaintenanceFailed BackupRepositoryMaintenanceResult = "Failed"
|
||||
)
|
||||
|
||||
type BackupRepositoryMaintenanceStatus struct {
|
||||
// Result is the result of the repo maintenance.
|
||||
// +optional
|
||||
Result BackupRepositoryMaintenanceResult `json:"result,omitempty"`
|
||||
|
||||
// StartTimestamp is the start time of the repo maintenance.
|
||||
// +optional
|
||||
// +nullable
|
||||
|
|
|
@ -316,18 +316,18 @@ func (r *BackupRepoReconciler) runMaintenanceIfDue(ctx context.Context, req *vel
|
|||
if err := r.repositoryManager.PruneRepo(req); err != nil {
|
||||
log.WithError(err).Warn("error pruning repository")
|
||||
return r.patchBackupRepository(ctx, req, func(rr *velerov1api.BackupRepository) {
|
||||
updateRepoMaintenanceHistory(rr, startTime, r.clock.Now(), err.Error())
|
||||
updateRepoMaintenanceHistory(rr, velerov1api.BackupRepositoryMaintenanceFailed, startTime, r.clock.Now(), err.Error())
|
||||
})
|
||||
}
|
||||
|
||||
return r.patchBackupRepository(ctx, req, func(rr *velerov1api.BackupRepository) {
|
||||
completionTime := r.clock.Now()
|
||||
rr.Status.LastMaintenanceTime = &metav1.Time{Time: completionTime}
|
||||
updateRepoMaintenanceHistory(rr, startTime, completionTime, "")
|
||||
updateRepoMaintenanceHistory(rr, velerov1api.BackupRepositoryMaintenanceSucceeded, startTime, completionTime, "")
|
||||
})
|
||||
}
|
||||
|
||||
func updateRepoMaintenanceHistory(repo *velerov1api.BackupRepository, startTime time.Time, completionTime time.Time, result string) {
|
||||
func updateRepoMaintenanceHistory(repo *velerov1api.BackupRepository, result velerov1api.BackupRepositoryMaintenanceResult, startTime time.Time, completionTime time.Time, message string) {
|
||||
length := defaultMaintenanceStatusQueueLength
|
||||
if len(repo.Status.RecentMaintenanceStatus) < defaultMaintenanceStatusQueueLength {
|
||||
length = len(repo.Status.RecentMaintenanceStatus) + 1
|
||||
|
@ -342,9 +342,10 @@ func updateRepoMaintenanceHistory(repo *velerov1api.BackupRepository, startTime
|
|||
}
|
||||
|
||||
lru[length-1] = velerov1api.BackupRepositoryMaintenanceStatus{
|
||||
Result: result,
|
||||
StartTimestamp: &metav1.Time{Time: startTime},
|
||||
CompleteTimestamp: &metav1.Time{Time: completionTime},
|
||||
Message: result,
|
||||
Message: message,
|
||||
}
|
||||
|
||||
repo.Status.RecentMaintenanceStatus = lru
|
||||
|
|
|
@ -573,11 +573,13 @@ func TestUpdateRepoMaintenanceHistory(t *testing.T) {
|
|||
tests := []struct {
|
||||
name string
|
||||
backupRepo *velerov1api.BackupRepository
|
||||
result velerov1api.BackupRepositoryMaintenanceResult
|
||||
expectedHistory []velerov1api.BackupRepositoryMaintenanceStatus
|
||||
}{
|
||||
{
|
||||
name: "empty history",
|
||||
backupRepo: backupRepoWithoutHistory,
|
||||
result: velerov1api.BackupRepositoryMaintenanceSucceeded,
|
||||
expectedHistory: []velerov1api.BackupRepositoryMaintenanceStatus{
|
||||
{
|
||||
StartTimestamp: &metav1.Time{Time: standardTime},
|
||||
|
@ -589,6 +591,7 @@ func TestUpdateRepoMaintenanceHistory(t *testing.T) {
|
|||
{
|
||||
name: "less than history queue length",
|
||||
backupRepo: backupRepoWithHistory,
|
||||
result: velerov1api.BackupRepositoryMaintenanceSucceeded,
|
||||
expectedHistory: []velerov1api.BackupRepositoryMaintenanceStatus{
|
||||
{
|
||||
StartTimestamp: &metav1.Time{Time: standardTime.Add(-time.Hour * 24)},
|
||||
|
@ -605,6 +608,7 @@ func TestUpdateRepoMaintenanceHistory(t *testing.T) {
|
|||
{
|
||||
name: "full history",
|
||||
backupRepo: backupRepoWithFullHistory,
|
||||
result: velerov1api.BackupRepositoryMaintenanceFailed,
|
||||
expectedHistory: []velerov1api.BackupRepositoryMaintenanceStatus{
|
||||
{
|
||||
StartTimestamp: &metav1.Time{Time: standardTime.Add(-time.Hour * 22)},
|
||||
|
@ -626,6 +630,7 @@ func TestUpdateRepoMaintenanceHistory(t *testing.T) {
|
|||
{
|
||||
name: "over full history",
|
||||
backupRepo: backupRepoWithOverFullHistory,
|
||||
result: velerov1api.BackupRepositoryMaintenanceFailed,
|
||||
expectedHistory: []velerov1api.BackupRepositoryMaintenanceStatus{
|
||||
{
|
||||
StartTimestamp: &metav1.Time{Time: standardTime.Add(-time.Hour * 20)},
|
||||
|
@ -648,7 +653,7 @@ func TestUpdateRepoMaintenanceHistory(t *testing.T) {
|
|||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
updateRepoMaintenanceHistory(test.backupRepo, standardTime, standardTime.Add(time.Hour), "fake-message-0")
|
||||
updateRepoMaintenanceHistory(test.backupRepo, test.result, standardTime, standardTime.Add(time.Hour), "fake-message-0")
|
||||
|
||||
for at := range test.backupRepo.Status.RecentMaintenanceStatus {
|
||||
assert.Equal(t, test.expectedHistory[at].StartTimestamp.Time, test.backupRepo.Status.RecentMaintenanceStatus[at].StartTimestamp.Time)
|
||||
|
|
Loading…
Reference in New Issue