@@ -119,7 +119,7 @@ func (ds RegistryDataSource) Sync(ctx context.Context, vd *v1alpha2.VirtualDisk)
119119 case IsDiskProvisioningFinished (condition ):
120120 log .Debug ("Disk provisioning finished: clean up" )
121121
122- setPhaseConditionForFinishedDisk (pvc , cb , & vd .Status .Phase , supgen )
122+ setPhaseConditionForFinishedDisk (vd , pvc , cb , & vd .Status .Phase , supgen )
123123
124124 // Protect Ready Disk and underlying PVC.
125125 err = ds .diskService .Protect (ctx , supgen , vd , nil , pvc )
@@ -163,17 +163,14 @@ func (ds RegistryDataSource) Sync(ctx context.Context, vd *v1alpha2.VirtualDisk)
163163 // OK.
164164 case common .ErrQuotaExceeded (err ):
165165 ds .recorder .Event (vd , corev1 .EventTypeWarning , v1alpha2 .ReasonDataSourceQuotaExceeded , "DataSource quota exceed" )
166- return setQuotaExceededPhaseCondition (cb , & vd .Status .Phase , err , vd .CreationTimestamp ), nil
166+ return setQuotaExceededPhaseCondition (vd , cb , & vd .Status .Phase , err , vd .CreationTimestamp ), nil
167167 default :
168- setPhaseConditionToFailed (cb , & vd .Status .Phase , fmt .Errorf ("unexpected error: %w" , err ))
168+ setPhaseConditionToFailed (vd , cb , & vd .Status .Phase , fmt .Errorf ("unexpected error: %w" , err ))
169169 return reconcile.Result {}, err
170170 }
171171
172172 vd .Status .Phase = v1alpha2 .DiskPending
173- cb .
174- Status (metav1 .ConditionFalse ).
175- Reason (vdcondition .WaitForUserUpload ).
176- Message ("DVCR Provisioner not found: create the new one." )
173+ setReadyConditionWithWFFCAccounting (vd , cb , metav1 .ConditionFalse , vdcondition .WaitForUserUpload , "DVCR Provisioner not found: create the new one." )
177174
178175 return reconcile.Result {RequeueAfter : time .Second }, nil
179176 case ! podutil .IsPodComplete (pod ):
@@ -185,10 +182,7 @@ func (ds RegistryDataSource) Sync(ctx context.Context, vd *v1alpha2.VirtualDisk)
185182 }
186183
187184 vd .Status .Phase = v1alpha2 .DiskProvisioning
188- cb .
189- Status (metav1 .ConditionFalse ).
190- Reason (vdcondition .Provisioning ).
191- Message ("DVCR Provisioner not found: create the new one." )
185+ setReadyConditionWithWFFCAccounting (vd , cb , metav1 .ConditionFalse , vdcondition .Provisioning , "DVCR Provisioner not found: create the new one." )
192186
193187 vd .Status .Progress = ds .statService .GetProgress (vd .GetUID (), pod , vd .Status .Progress , service .NewScaleOption (0 , 50 ))
194188
@@ -200,6 +194,13 @@ func (ds RegistryDataSource) Sync(ctx context.Context, vd *v1alpha2.VirtualDisk)
200194 if isStorageClassWFFC (sc ) && len (vd .Status .AttachedToVirtualMachines ) != 1 {
201195 vd .Status .Progress = "50%"
202196 vd .Status .Phase = v1alpha2 .DiskWaitForFirstConsumer
197+ setReadyConditionWithWFFCAccounting (
198+ vd ,
199+ cb ,
200+ metav1 .ConditionFalse ,
201+ vdcondition .WaitingForFirstConsumer ,
202+ "The provisioning has been suspended: a created and scheduled virtual machine is awaited." ,
203+ )
203204 return reconcile.Result {}, nil
204205 }
205206
@@ -217,10 +218,7 @@ func (ds RegistryDataSource) Sync(ctx context.Context, vd *v1alpha2.VirtualDisk)
217218 switch {
218219 case errors .Is (err , service .ErrProvisioningFailed ):
219220 ds .recorder .Event (vd , corev1 .EventTypeWarning , v1alpha2 .ReasonDataSourceDiskProvisioningFailed , "Disk provisioning failed" )
220- cb .
221- Status (metav1 .ConditionFalse ).
222- Reason (vdcondition .ProvisioningFailed ).
223- Message (service .CapitalizeFirstLetter (err .Error () + "." ))
221+ setReadyConditionWithWFFCAccounting (vd , cb , metav1 .ConditionFalse , vdcondition .ProvisioningFailed , service .CapitalizeFirstLetter (err .Error ()+ "." ))
224222 return reconcile.Result {}, nil
225223 default :
226224 return reconcile.Result {}, err
@@ -230,14 +228,14 @@ func (ds RegistryDataSource) Sync(ctx context.Context, vd *v1alpha2.VirtualDisk)
230228 vd .Status .Progress = "50%"
231229
232230 if imageformat .IsISO (ds .statService .GetFormat (pod )) {
233- setPhaseConditionToFailed (cb , & vd .Status .Phase , ErrISOSourceNotSupported )
231+ setPhaseConditionToFailed (vd , cb , & vd .Status .Phase , ErrISOSourceNotSupported )
234232 return reconcile.Result {}, nil
235233 }
236234
237235 var diskSize resource.Quantity
238236 diskSize , err = ds .getPVCSize (vd , pod )
239237 if err != nil {
240- setPhaseConditionToFailed (cb , & vd .Status .Phase , err )
238+ setPhaseConditionToFailed (vd , cb , & vd .Status .Phase , err )
241239
242240 if errors .Is (err , service .ErrInsufficientPVCSize ) {
243241 return reconcile.Result {}, nil
@@ -251,7 +249,7 @@ func (ds RegistryDataSource) Sync(ctx context.Context, vd *v1alpha2.VirtualDisk)
251249 var nodePlacement * provisioner.NodePlacement
252250 nodePlacement , err = getNodePlacement (ctx , ds .client , vd )
253251 if err != nil {
254- setPhaseConditionToFailed (cb , & vd .Status .Phase , fmt .Errorf ("unexpected error: %w" , err ))
252+ setPhaseConditionToFailed (vd , cb , & vd .Status .Phase , fmt .Errorf ("unexpected error: %w" , err ))
255253 return reconcile.Result {}, fmt .Errorf ("failed to get importer tolerations: %w" , err )
256254 }
257255
@@ -266,39 +264,27 @@ func (ds RegistryDataSource) Sync(ctx context.Context, vd *v1alpha2.VirtualDisk)
266264 return reconcile.Result {}, err
267265 }
268266 vd .Status .Phase = v1alpha2 .DiskProvisioning
269- cb .
270- Status (metav1 .ConditionFalse ).
271- Reason (vdcondition .Provisioning ).
272- Message ("PVC Provisioner not found: create the new one." )
267+ setReadyConditionWithWFFCAccounting (vd , cb , metav1 .ConditionFalse , vdcondition .Provisioning , "PVC Provisioner not found: create the new one." )
273268
274269 return reconcile.Result {RequeueAfter : time .Second }, nil
275270 case dvQuotaNotExceededCondition != nil && dvQuotaNotExceededCondition .Status == corev1 .ConditionFalse :
276271 vd .Status .Phase = v1alpha2 .DiskPending
277272 if dv .Status .ClaimName != "" && isStorageClassWFFC (sc ) {
278273 vd .Status .Phase = v1alpha2 .DiskWaitForFirstConsumer
279274 }
280- cb .
281- Status (metav1 .ConditionFalse ).
282- Reason (vdcondition .QuotaExceeded ).
283- Message (dvQuotaNotExceededCondition .Message )
275+ setReadyConditionWithWFFCAccounting (vd , cb , metav1 .ConditionFalse , vdcondition .QuotaExceeded , dvQuotaNotExceededCondition .Message )
284276 return reconcile.Result {}, nil
285277 case dvRunningCondition != nil && dvRunningCondition .Status != corev1 .ConditionTrue && dvRunningCondition .Reason == DVImagePullFailedReason :
286278 vd .Status .Phase = v1alpha2 .DiskPending
287279 if dv .Status .ClaimName != "" && isStorageClassWFFC (sc ) {
288280 vd .Status .Phase = v1alpha2 .DiskWaitForFirstConsumer
289281 }
290- cb .
291- Status (metav1 .ConditionFalse ).
292- Reason (vdcondition .ImagePullFailed ).
293- Message (dvRunningCondition .Message )
282+ setReadyConditionWithWFFCAccounting (vd , cb , metav1 .ConditionFalse , vdcondition .ImagePullFailed , dvRunningCondition .Message )
294283 ds .recorder .Event (vd , corev1 .EventTypeWarning , vdcondition .ImagePullFailed .String (), dvRunningCondition .Message )
295284 return reconcile.Result {}, nil
296285 case pvc == nil :
297286 vd .Status .Phase = v1alpha2 .DiskProvisioning
298- cb .
299- Status (metav1 .ConditionFalse ).
300- Reason (vdcondition .Provisioning ).
301- Message ("PVC not found: waiting for creation." )
287+ setReadyConditionWithWFFCAccounting (vd , cb , metav1 .ConditionFalse , vdcondition .Provisioning , "PVC not found: waiting for creation." )
302288 return reconcile.Result {RequeueAfter : time .Second }, nil
303289 case ds .diskService .IsImportDone (dv , pvc ):
304290 log .Info ("Import has completed" , "dvProgress" , dv .Status .Progress , "dvPhase" , dv .Status .Phase , "pvcPhase" , pvc .Status .Phase )
@@ -311,10 +297,7 @@ func (ds RegistryDataSource) Sync(ctx context.Context, vd *v1alpha2.VirtualDisk)
311297 )
312298
313299 vd .Status .Phase = v1alpha2 .DiskReady
314- cb .
315- Status (metav1 .ConditionTrue ).
316- Reason (vdcondition .Ready ).
317- Message ("" )
300+ setReadyConditionWithWFFCAccounting (vd , cb , metav1 .ConditionTrue , vdcondition .Ready , "" )
318301
319302 vd .Status .Progress = "100%"
320303 vd .Status .Capacity = ds .diskService .GetCapacity (pvc )
0 commit comments