@@ -50,9 +50,16 @@ func (r *reconciledResource) key() kubeutil.ResourceKey {
50
50
type SyncContext interface {
51
51
// Terminate terminates sync operation. The method is asynchronous: it starts deletion is related K8S resources
52
52
// such as in-flight resource hooks, updates operation status, and exists without waiting for resource completion.
53
+ // Deprecated: use TerminateContext instead
53
54
Terminate ()
55
+ // TerminateContext terminates sync operation. The method is asynchronous: it starts deletion is related K8S resources
56
+ // such as in-flight resource hooks, updates operation status, and exists without waiting for resource completion.
57
+ TerminateContext (ctx context.Context )
54
58
// Executes next synchronization step and updates operation status.
59
+ // Deprecated: use SyncContext instead
55
60
Sync ()
61
+ // Executes next synchronization step and updates operation status.
62
+ SyncContext (ctx context.Context )
56
63
// Returns current sync operation state and information about resources synchronized so far.
57
64
GetState () (common.OperationPhase , string , []common.ResourceSyncResult )
58
65
}
@@ -75,12 +82,20 @@ func WithPermissionValidator(validator common.PermissionValidator) SyncOpt {
75
82
}
76
83
77
84
// WithHealthOverride sets specified health override
85
+ // Deprecated: use WithHealthOverrideContext instead
78
86
func WithHealthOverride (override health.HealthOverride ) SyncOpt {
79
87
return func (ctx * syncContext ) {
80
88
ctx .healthOverride = override
81
89
}
82
90
}
83
91
92
+ // WithHealthOverrideContext sets specified health override
93
+ func WithHealthOverrideContext (override health.HealthOverrideContext ) SyncOpt {
94
+ return func (ctx * syncContext ) {
95
+ ctx .healthOverrideContext = override
96
+ }
97
+ }
98
+
84
99
// WithInitialState sets sync operation initial state
85
100
func WithInitialState (phase common.OperationPhase , message string , results []common.ResourceSyncResult , startedAt metav1.Time ) SyncOpt {
86
101
return func (ctx * syncContext ) {
@@ -308,11 +323,18 @@ const (
308
323
)
309
324
310
325
// getOperationPhase returns a health status from a _live_ unstructured object
311
- func (sc * syncContext ) getOperationPhase (obj * unstructured.Unstructured ) (common.OperationPhase , string , error ) {
326
+ func (sc * syncContext ) getOperationPhase (ctx context. Context , obj * unstructured.Unstructured ) (common.OperationPhase , string , error ) {
312
327
phase := common .OperationSucceeded
313
328
message := obj .GetName () + " created"
314
329
315
- resHealth , err := health .GetResourceHealth (obj , sc .healthOverride )
330
+ var resHealth * health.HealthStatus
331
+ var err error
332
+
333
+ if sc .healthOverrideContext != nil {
334
+ resHealth , err = health .GetResourceHealthContext (ctx , obj , sc .healthOverrideContext )
335
+ } else if sc .healthOverride != nil {
336
+ resHealth , err = health .GetResourceHealth (obj , sc .healthOverride )
337
+ }
316
338
if err != nil {
317
339
return "" , "" , err
318
340
}
@@ -333,18 +355,19 @@ func (sc *syncContext) getOperationPhase(obj *unstructured.Unstructured) (common
333
355
}
334
356
335
357
type syncContext struct {
336
- healthOverride health.HealthOverride
337
- permissionValidator common.PermissionValidator
338
- resources map [kubeutil.ResourceKey ]reconciledResource
339
- hooks []* unstructured.Unstructured
340
- config * rest.Config
341
- rawConfig * rest.Config
342
- dynamicIf dynamic.Interface
343
- disco discovery.DiscoveryInterface
344
- extensionsclientset * clientset.Clientset
345
- kubectl kubeutil.Kubectl
346
- resourceOps kubeutil.ResourceOperations
347
- namespace string
358
+ healthOverride health.HealthOverride
359
+ healthOverrideContext health.HealthOverrideContext
360
+ permissionValidator common.PermissionValidator
361
+ resources map [kubeutil.ResourceKey ]reconciledResource
362
+ hooks []* unstructured.Unstructured
363
+ config * rest.Config
364
+ rawConfig * rest.Config
365
+ dynamicIf dynamic.Interface
366
+ disco discovery.DiscoveryInterface
367
+ extensionsclientset * clientset.Clientset
368
+ kubectl kubeutil.Kubectl
369
+ resourceOps kubeutil.ResourceOperations
370
+ namespace string
348
371
349
372
dryRun bool
350
373
skipDryRun bool
@@ -403,8 +426,19 @@ func (sc *syncContext) setRunningPhase(tasks []*syncTask, isPendingDeletion bool
403
426
}
404
427
}
405
428
406
- // sync has performs the actual apply or hook based sync
429
+ // Sync has performs the actual apply or hook based sync
430
+ // Deprecated: use SyncContext instead
407
431
func (sc * syncContext ) Sync () {
432
+ sc .SyncContext (context .Background ())
433
+ }
434
+
435
+ // SyncContext has performs the actual apply or hook based sync
436
+ func (sc * syncContext ) SyncContext (ctx context.Context ) {
437
+ sc .sync (ctx )
438
+ }
439
+
440
+ // sync has performs the actual apply or hook based sync
441
+ func (sc * syncContext ) sync (ctx context.Context ) {
408
442
sc .log .WithValues ("skipHooks" , sc .skipHooks , "started" , sc .started ()).Info ("Syncing" )
409
443
tasks , ok := sc .getSyncTasks ()
410
444
if ! ok {
@@ -441,7 +475,7 @@ func (sc *syncContext) Sync() {
441
475
}) {
442
476
if task .isHook () {
443
477
// update the hook's result
444
- operationState , message , err := sc .getOperationPhase (task .liveObj )
478
+ operationState , message , err := sc .getOperationPhase (ctx , task .liveObj )
445
479
if err != nil {
446
480
sc .setResourceResult (task , "" , common .OperationError , fmt .Sprintf ("failed to get resource health: %v" , err ))
447
481
} else {
@@ -1176,8 +1210,17 @@ func (sc *syncContext) hasCRDOfGroupKind(group string, kind string) bool {
1176
1210
return false
1177
1211
}
1178
1212
1179
- // terminate looks for any running jobs/workflow hooks and deletes the resource
1213
+ // Deprecated: use TerminateContext instead
1180
1214
func (sc * syncContext ) Terminate () {
1215
+ sc .TerminateContext (context .Background ())
1216
+ }
1217
+
1218
+ func (sc * syncContext ) TerminateContext (ctx context.Context ) {
1219
+ sc .terminate (ctx )
1220
+ }
1221
+
1222
+ // terminate looks for any running jobs/workflow hooks and deletes the resource
1223
+ func (sc * syncContext ) terminate (ctx context.Context ) {
1181
1224
terminateSuccessful := true
1182
1225
sc .log .V (1 ).Info ("terminating" )
1183
1226
tasks , _ := sc .getSyncTasks ()
@@ -1190,7 +1233,7 @@ func (sc *syncContext) Terminate() {
1190
1233
terminateSuccessful = false
1191
1234
continue
1192
1235
}
1193
- phase , msg , err := sc .getOperationPhase (task .liveObj )
1236
+ phase , msg , err := sc .getOperationPhase (ctx , task .liveObj )
1194
1237
if err != nil {
1195
1238
sc .setOperationPhase (common .OperationError , fmt .Sprintf ("Failed to get hook health: %v" , err ))
1196
1239
return
0 commit comments