Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return directly if no pod volme backup are tracked #8728

Merged
merged 1 commit into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelogs/unreleased/8728-ywk253100
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Return directly if no pod volme backup are tracked
8 changes: 7 additions & 1 deletion pkg/podvolume/backupper.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,13 +387,19 @@ func (b *backupper) WaitAllPodVolumesProcessed(log logrus.FieldLogger) []*velero
}
}()

var podVolumeBackups []*velerov1api.PodVolumeBackup
// if no pod volume backups are tracked, return directly to avoid issue mentioned in
// https://github.com/vmware-tanzu/velero/issues/8723
if len(b.pvbIndexer.List()) == 0 {
return podVolumeBackups
}

done := make(chan struct{})
go func() {
defer close(done)
b.wg.Wait()
}()

var podVolumeBackups []*velerov1api.PodVolumeBackup
select {
case <-b.ctx.Done():
log.Error("timed out waiting for all PodVolumeBackups to complete")
Expand Down
32 changes: 24 additions & 8 deletions pkg/podvolume/backupper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,26 +725,33 @@ func (l *logHook) Fire(entry *logrus.Entry) error {
}

func TestWaitAllPodVolumesProcessed(t *testing.T) {
timeoutCtx, cancelFunc := context.WithTimeout(context.Background(), 1*time.Second)
defer func() {
cancelFunc()
}()
timeoutCtx, cancelFunc := context.WithCancel(context.Background())
cancelFunc()
log := logrus.New()
pvb := builder.ForPodVolumeBackup(velerov1api.DefaultNamespace, "pvb").
PodNamespace("pod-namespace").PodName("pod-name").Volume("volume").Result()
cases := []struct {
name string
ctx context.Context
pvb *velerov1api.PodVolumeBackup
statusToBeUpdated *velerov1api.PodVolumeBackupStatus
expectedErr string
expectedPVBPhase velerov1api.PodVolumeBackupPhase
}{
{
name: "contains no pvb should report no error",
ctx: timeoutCtx,
},
{
name: "context canceled",
ctx: timeoutCtx,
pvb: pvb,
expectedErr: "timed out waiting for all PodVolumeBackups to complete",
},
{
name: "failed pvbs",
ctx: context.Background(),
pvb: pvb,
statusToBeUpdated: &velerov1api.PodVolumeBackupStatus{
Phase: velerov1api.PodVolumeBackupPhaseFailed,
Message: "failed",
Expand All @@ -755,6 +762,7 @@ func TestWaitAllPodVolumesProcessed(t *testing.T) {
{
name: "completed pvbs",
ctx: context.Background(),
pvb: pvb,
statusToBeUpdated: &velerov1api.PodVolumeBackupStatus{
Phase: velerov1api.PodVolumeBackupPhaseCompleted,
Message: "completed",
Expand All @@ -764,10 +772,13 @@ func TestWaitAllPodVolumesProcessed(t *testing.T) {
}

for _, c := range cases {
newPVB := builder.ForPodVolumeBackup(velerov1api.DefaultNamespace, "pvb").Result()
var objs []ctrlclient.Object
if c.pvb != nil {
objs = append(objs, c.pvb)
}
scheme := runtime.NewScheme()
velerov1api.AddToScheme(scheme)
client := ctrlfake.NewClientBuilder().WithScheme(scheme).WithObjects(newPVB).Build()
client := ctrlfake.NewClientBuilder().WithScheme(scheme).WithObjects(objs...).Build()

lw := kube.InternalLW{
Client: client,
Expand All @@ -786,11 +797,14 @@ func TestWaitAllPodVolumesProcessed(t *testing.T) {
logger.Hooks.Add(logHook)

backuper := newBackupper(c.ctx, log, nil, nil, informer, nil, "", &velerov1api.Backup{})
backuper.wg.Add(1)
if c.pvb != nil {
backuper.pvbIndexer.Add(c.pvb)
backuper.wg.Add(1)
}

if c.statusToBeUpdated != nil {
pvb := &velerov1api.PodVolumeBackup{}
err := client.Get(context.Background(), ctrlclient.ObjectKey{Namespace: newPVB.Namespace, Name: newPVB.Name}, pvb)
err := client.Get(context.Background(), ctrlclient.ObjectKey{Namespace: c.pvb.Namespace, Name: c.pvb.Name}, pvb)
require.NoError(t, err)

pvb.Status = *c.statusToBeUpdated
Expand All @@ -802,6 +816,8 @@ func TestWaitAllPodVolumesProcessed(t *testing.T) {

if c.expectedErr != "" {
assert.Equal(t, c.expectedErr, logHook.entry.Message)
} else {
assert.Nil(t, logHook.entry)
}

if c.expectedPVBPhase != "" {
Expand Down
Loading