@@ -158,35 +158,37 @@ func (r *Restorer) reconcileInProgressPVC(ctx context.Context, restoreRequestNam
158
158
// PVC hasn't been found, restore it from VolumeSnapshot. For this we need pre-provisioned VolumeSnapshot
159
159
// and VolumeSnapshotContent resources.
160
160
161
- // Check if the pre-provisioned VolumeSnapshot resource exists. If it doesn't, create it.
162
161
volumeSnapshotName := fmt .Sprintf ("%s-%s" , config .PersistentVolumeClaim .Name , restoreRequestName )
163
162
pvcName := types.NamespacedName {
164
163
Namespace : config .PersistentVolumeClaim .Namespace ,
165
164
Name : config .PersistentVolumeClaim .Name ,
166
165
}
167
- volumeSnapshot , err := r .snapshotsClient .SnapshotV1 ().VolumeSnapshots (pvcName .Namespace ).Get (ctx , volumeSnapshotName , metav1.GetOptions {})
166
+
167
+ // Check if the pre-provisioned VolumeSnapshotContent resource exists. If it doesn't, create it.
168
168
justCreated := false
169
+ volumeSnapshotContent , err := r .snapshotsClient .SnapshotV1 ().VolumeSnapshotContents ().Get (ctx , volumeSnapshotName , metav1.GetOptions {})
169
170
if kerrors .IsNotFound (err ) {
170
- // create new VolumeSnapshot
171
- volumeSnapshot , err = r .createVolumeSnapshotResource (ctx , restoreRequestName , volumeSnapshotName , pvcName , config . VolumeSnapshotClassName )
171
+ // create new VolumeSnapshotContent
172
+ volumeSnapshotContent , err = r .createVolumeSnapshotContentResource (ctx , restoreRequestName , volumeSnapshotName , config , restoreStatus )
172
173
if err != nil {
173
- return status , fmt .Errorf ("failed to create VolumeSnapshot for the PersistentVolumeClaim %s: %w" , pvcName , err )
174
+ return status , fmt .Errorf ("failed to create VolumeSnapshotContent for the PersistentVolumeClaim %s: %w" , pvcName , err )
174
175
}
175
176
justCreated = true
176
- // we don't wait for the VolumeSnapshot to be ready, because it also needs the VolumeSnapshotContent to become ready
177
177
} else if err != nil {
178
- return status , fmt .Errorf ("failed to get VolumeSnapshot %s/%s : %w" , volumeSnapshot . Namespace , volumeSnapshot .Name , err )
178
+ return status , fmt .Errorf ("failed to get VolumeSnapshotContent %s: %w" , volumeSnapshotContent .Name , err )
179
179
}
180
180
181
- // Check if the pre-provisioned VolumeSnapshotContent resource exists. If it doesn't, create it.
182
- volumeSnapshotContent , err := r .snapshotsClient .SnapshotV1 ().VolumeSnapshotContents ( ).Get (ctx , volumeSnapshotName , metav1.GetOptions {})
181
+ // Check if the pre-provisioned VolumeSnapshot resource exists. If it doesn't, create it.
182
+ volumeSnapshot , err := r .snapshotsClient .SnapshotV1 ().VolumeSnapshots ( pvcName . Namespace ).Get (ctx , volumeSnapshotName , metav1.GetOptions {})
183
183
if kerrors .IsNotFound (err ) {
184
- // create new VolumeSnapshotContent
185
- volumeSnapshotContent , err = r .createVolumeSnapshotContentResource (ctx , restoreRequestName , volumeSnapshotName , config , restoreStatus )
184
+ // create new VolumeSnapshot
185
+ volumeSnapshot , err = r .createVolumeSnapshotResource (ctx , restoreRequestName , volumeSnapshotName , pvcName , config . VolumeSnapshotClassName )
186
186
if err != nil {
187
- return status , fmt .Errorf ("failed to create VolumeSnapshotContent for the PersistentVolumeClaim %s: %w" , pvcName , err )
187
+ return status , fmt .Errorf ("failed to create VolumeSnapshot for the PersistentVolumeClaim %s: %w" , pvcName , err )
188
188
}
189
189
justCreated = true
190
+ } else if err != nil {
191
+ return status , fmt .Errorf ("failed to get VolumeSnapshot %s/%s: %w" , volumeSnapshot .Namespace , volumeSnapshot .Name , err )
190
192
}
191
193
192
194
if justCreated {
@@ -196,10 +198,14 @@ func (r *Restorer) reconcileInProgressPVC(ctx context.Context, restoreRequestNam
196
198
197
199
// check if VolumeSnapshot has failed
198
200
if volumeSnapshot .Status .Error != nil {
199
- // VolumeSnapshot has failed
200
201
var errorMessage string
201
202
if volumeSnapshot .Status .Error .Message != nil {
202
- errorMessage = * volumeSnapshot .Status .Error .Message
203
+ errorMessage = fmt .Sprintf (
204
+ "VolumeSnapshot %s/%s (for PersistentVolumeClaim %s) has a status error message %s" ,
205
+ volumeSnapshot .Namespace ,
206
+ volumeSnapshot .Name ,
207
+ pvcName .String (),
208
+ * volumeSnapshot .Status .Error .Message )
203
209
} else {
204
210
errorMessage = fmt .Sprintf (
205
211
"VolumeSnapshot %s/%s (for PersistentVolumeClaim %s) has failed with an unknown error" ,
@@ -219,10 +225,13 @@ func (r *Restorer) reconcileInProgressPVC(ctx context.Context, restoreRequestNam
219
225
220
226
// check if VolumeSnapshotContent has failed
221
227
if volumeSnapshotContent .Status .Error != nil {
222
- // volumeSnapshotContent has failed
223
228
var errorMessage string
224
229
if volumeSnapshotContent .Status .Error .Message != nil {
225
- errorMessage = * volumeSnapshotContent .Status .Error .Message
230
+ errorMessage = fmt .Sprintf (
231
+ "VolumeSnapshotContent %s (for PersistentVolumeClaim %s) has a status error message: %s" ,
232
+ volumeSnapshotContent .Name ,
233
+ pvcName .String (),
234
+ * volumeSnapshotContent .Status .Error .Message )
226
235
} else {
227
236
errorMessage = fmt .Sprintf (
228
237
"VolumeSnapshotContent %s (for PersistentVolumeClaim %s) has failed with an unknown error" ,
0 commit comments