@@ -76,6 +76,11 @@ func (ctrl *ProvisionController[T]) Settings() controller.QSettings {
7676 Kind : controller .InputQMapped ,
7777 ID : optional .Some (siderolink .ConfigID ),
7878 },
79+ {
80+ Namespace : resources .InfraProviderNamespace ,
81+ Type : infra .ConfigPatchRequestType ,
82+ Kind : controller .InputQMappedDestroyReady ,
83+ },
7984 {
8085 Namespace : t .ResourceDefinition ().DefaultNamespace ,
8186 Type : t .ResourceDefinition ().Type ,
@@ -91,6 +96,10 @@ func (ctrl *ProvisionController[T]) Settings() controller.QSettings {
9196 Kind : controller .OutputShared ,
9297 Type : t .ResourceDefinition ().Type ,
9398 },
99+ {
100+ Kind : controller .OutputShared ,
101+ Type : infra .ConfigPatchRequestType ,
102+ },
94103 },
95104 Concurrency : optional .Some (ctrl .concurrency ),
96105 }
@@ -214,6 +223,7 @@ func (ctrl *ProvisionController[T]) reconcileRunning(ctx context.Context, r cont
214223 st ,
215224 connectionParams ,
216225 ctrl .imageFactory ,
226+ r ,
217227 ))
218228
219229 st .Metadata ().Annotations ().Set (currentStepAnnotation , step .Name ())
@@ -259,6 +269,41 @@ func (ctrl *ProvisionController[T]) reconcileRunning(ctx context.Context, r cont
259269 return nil
260270}
261271
272+ func (ctrl * ProvisionController [T ]) removePatches (ctx context.Context , r controller.QRuntime , requestID string ) (bool , error ) {
273+ destroyReady := true
274+
275+ patches , err := safe .ReaderListAll [* infra.ConfigPatchRequest ](ctx , r , state .WithLabelQuery (
276+ resource .LabelEqual (omni .LabelInfraProviderID , ctrl .providerID ),
277+ resource .LabelEqual (omni .LabelMachineRequest , requestID ),
278+ ))
279+ if err != nil {
280+ return false , err
281+ }
282+
283+ for request := range patches .All () {
284+ ready , err := r .Teardown (ctx , request .Metadata ())
285+ if err != nil {
286+ if state .IsNotFoundError (err ) {
287+ continue
288+ }
289+
290+ return false , err
291+ }
292+
293+ if ! ready {
294+ destroyReady = false
295+
296+ continue
297+ }
298+
299+ if err = r .Destroy (ctx , request .Metadata ()); err != nil && ! state .IsNotFoundError (err ) {
300+ return false , err
301+ }
302+ }
303+
304+ return destroyReady , nil
305+ }
306+
262307func (ctrl * ProvisionController [T ]) initializeStatus (ctx context.Context , r controller.QRuntime , logger * zap.Logger , machineRequest * infra.MachineRequest ) (* infra.MachineRequestStatus , error ) {
263308 mrs , err := safe .ReaderGetByID [* infra.MachineRequestStatus ](ctx , r , machineRequest .Metadata ().ID ())
264309 if err != nil && ! state .IsNotFoundError (err ) {
@@ -309,6 +354,18 @@ func (ctrl *ProvisionController[T]) reconcileTearingDown(ctx context.Context, r
309354 return err
310355 }
311356
357+ {
358+ var ready bool
359+
360+ if ready , err = ctrl .removePatches (ctx , r , machineRequest .Metadata ().ID ()); err != nil {
361+ return err
362+ }
363+
364+ if ! ready {
365+ return nil
366+ }
367+ }
368+
312369 resources := []resource.Metadata {
313370 resource .NewMetadata (t .ResourceDefinition ().DefaultNamespace , t .ResourceDefinition ().Type , machineRequest .Metadata ().ID (), resource .VersionUndefined ),
314371 * infra .NewMachineRequestStatus (machineRequest .Metadata ().ID ()).Metadata (),
0 commit comments