@@ -76,6 +76,11 @@ func (ctrl *ProvisionController[T]) Settings() controller.QSettings {
76
76
Kind : controller .InputQMapped ,
77
77
ID : optional .Some (siderolink .ConfigID ),
78
78
},
79
+ {
80
+ Namespace : resources .InfraProviderNamespace ,
81
+ Type : infra .ConfigPatchRequestType ,
82
+ Kind : controller .InputQMappedDestroyReady ,
83
+ },
79
84
{
80
85
Namespace : t .ResourceDefinition ().DefaultNamespace ,
81
86
Type : t .ResourceDefinition ().Type ,
@@ -91,6 +96,10 @@ func (ctrl *ProvisionController[T]) Settings() controller.QSettings {
91
96
Kind : controller .OutputShared ,
92
97
Type : t .ResourceDefinition ().Type ,
93
98
},
99
+ {
100
+ Kind : controller .OutputShared ,
101
+ Type : infra .ConfigPatchRequestType ,
102
+ },
94
103
},
95
104
Concurrency : optional .Some (ctrl .concurrency ),
96
105
}
@@ -214,6 +223,7 @@ func (ctrl *ProvisionController[T]) reconcileRunning(ctx context.Context, r cont
214
223
st ,
215
224
connectionParams ,
216
225
ctrl .imageFactory ,
226
+ r ,
217
227
))
218
228
219
229
st .Metadata ().Annotations ().Set (currentStepAnnotation , step .Name ())
@@ -259,6 +269,41 @@ func (ctrl *ProvisionController[T]) reconcileRunning(ctx context.Context, r cont
259
269
return nil
260
270
}
261
271
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
+
262
307
func (ctrl * ProvisionController [T ]) initializeStatus (ctx context.Context , r controller.QRuntime , logger * zap.Logger , machineRequest * infra.MachineRequest ) (* infra.MachineRequestStatus , error ) {
263
308
mrs , err := safe .ReaderGetByID [* infra.MachineRequestStatus ](ctx , r , machineRequest .Metadata ().ID ())
264
309
if err != nil && ! state .IsNotFoundError (err ) {
@@ -309,6 +354,18 @@ func (ctrl *ProvisionController[T]) reconcileTearingDown(ctx context.Context, r
309
354
return err
310
355
}
311
356
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
+
312
369
resources := []resource.Metadata {
313
370
resource .NewMetadata (t .ResourceDefinition ().DefaultNamespace , t .ResourceDefinition ().Type , machineRequest .Metadata ().ID (), resource .VersionUndefined ),
314
371
* infra .NewMachineRequestStatus (machineRequest .Metadata ().ID ()).Metadata (),
0 commit comments