diff --git a/pkg/exposer/csi_snapshot.go b/pkg/exposer/csi_snapshot.go index d0dab6ca5..df9b08546 100644 --- a/pkg/exposer/csi_snapshot.go +++ b/pkg/exposer/csi_snapshot.go @@ -94,7 +94,7 @@ func (e *csiSnapshotExposer) Expose(ctx context.Context, ownerObject corev1.Obje curLog.Info("Exposing CSI snapshot") - volumeSnapshot, err := csi.WaitVolumeSnapshotReady(ctx, e.csiSnapshotClient, csiExposeParam.SnapshotName, csiExposeParam.SourceNamespace, csiExposeParam.Timeout) + volumeSnapshot, err := csi.WaitVolumeSnapshotReady(ctx, e.csiSnapshotClient, csiExposeParam.SnapshotName, csiExposeParam.SourceNamespace, csiExposeParam.Timeout, curLog) if err != nil { return errors.Wrapf(err, "error wait volume snapshot ready") } diff --git a/pkg/util/csi/volume_snapshot.go b/pkg/util/csi/volume_snapshot.go index 91e560d4f..b9b134fde 100644 --- a/pkg/util/csi/volume_snapshot.go +++ b/pkg/util/csi/volume_snapshot.go @@ -26,6 +26,7 @@ import ( "github.com/pkg/errors" "github.com/sirupsen/logrus" "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/wait" "github.com/vmware-tanzu/velero/pkg/util/boolptr" @@ -45,8 +46,9 @@ const ( // WaitVolumeSnapshotReady waits a VS to become ready to use until the timeout reaches func WaitVolumeSnapshotReady(ctx context.Context, snapshotClient snapshotter.SnapshotV1Interface, - volumeSnapshot string, volumeSnapshotNS string, timeout time.Duration) (*snapshotv1api.VolumeSnapshot, error) { + volumeSnapshot string, volumeSnapshotNS string, timeout time.Duration, log logrus.FieldLogger) (*snapshotv1api.VolumeSnapshot, error) { var updated *snapshotv1api.VolumeSnapshot + errMessage := sets.NewString() err := wait.PollImmediate(waitInternal, timeout, func() (bool, error) { tmpVS, err := snapshotClient.VolumeSnapshots(volumeSnapshotNS).Get(ctx, volumeSnapshot, metav1.GetOptions{}) @@ -59,7 +61,7 @@ func WaitVolumeSnapshotReady(ctx context.Context, snapshotClient snapshotter.Sna } if tmpVS.Status.Error != nil { - return false, errors.Errorf("volume snapshot creation error %s", stringptr.GetString(tmpVS.Status.Error.Message)) + errMessage.Insert(stringptr.GetString(tmpVS.Status.Error.Message)) } if !boolptr.IsSetToTrue(tmpVS.Status.ReadyToUse) { @@ -70,6 +72,14 @@ func WaitVolumeSnapshotReady(ctx context.Context, snapshotClient snapshotter.Sna return true, nil }) + if err == wait.ErrWaitTimeout { + err = errors.Errorf("volume snapshot is not ready until timeout, errors: %v", errMessage.List()) + } + + if errMessage.Len() > 0 { + log.Warnf("Some errors happened during waiting for ready snapshot, errors: %v", errMessage.List()) + } + return updated, err } diff --git a/pkg/util/csi/volume_snapshot_test.go b/pkg/util/csi/volume_snapshot_test.go index 7a678deb9..66e76b10c 100644 --- a/pkg/util/csi/volume_snapshot_test.go +++ b/pkg/util/csi/volume_snapshot_test.go @@ -84,7 +84,7 @@ func TestWaitVolumeSnapshotReady(t *testing.T) { }, }, }, - err: "timed out waiting for the condition", + err: "volume snapshot is not ready until timeout, errors: []", }, { name: "vsc is nil in status", @@ -99,7 +99,7 @@ func TestWaitVolumeSnapshotReady(t *testing.T) { Status: &snapshotv1api.VolumeSnapshotStatus{}, }, }, - err: "timed out waiting for the condition", + err: "volume snapshot is not ready until timeout, errors: []", }, { name: "ready to use is nil in status", @@ -116,7 +116,7 @@ func TestWaitVolumeSnapshotReady(t *testing.T) { }, }, }, - err: "timed out waiting for the condition", + err: "volume snapshot is not ready until timeout, errors: []", }, { name: "ready to use is false", @@ -134,7 +134,7 @@ func TestWaitVolumeSnapshotReady(t *testing.T) { }, }, }, - err: "timed out waiting for the condition", + err: "volume snapshot is not ready until timeout, errors: []", }, { name: "snapshot creation error with message", @@ -153,7 +153,7 @@ func TestWaitVolumeSnapshotReady(t *testing.T) { }, }, }, - err: "volume snapshot creation error fake-snapshot-creation-error", + err: "volume snapshot is not ready until timeout, errors: [fake-snapshot-creation-error]", }, { name: "snapshot creation error without message", @@ -170,7 +170,7 @@ func TestWaitVolumeSnapshotReady(t *testing.T) { }, }, }, - err: "volume snapshot creation error " + stringptr.NilString, + err: "volume snapshot is not ready until timeout, errors: [" + stringptr.NilString + "]", }, { name: "success", @@ -187,7 +187,7 @@ func TestWaitVolumeSnapshotReady(t *testing.T) { t.Run(test.name, func(t *testing.T) { fakeSnapshotClient := snapshotFake.NewSimpleClientset(test.clientObj...) - vs, err := WaitVolumeSnapshotReady(context.Background(), fakeSnapshotClient.SnapshotV1(), test.vsName, test.namespace, time.Millisecond) + vs, err := WaitVolumeSnapshotReady(context.Background(), fakeSnapshotClient.SnapshotV1(), test.vsName, test.namespace, time.Millisecond, velerotest.NewLogger()) if err != nil { assert.EqualError(t, err, test.err) } else {