@@ -50,9 +50,16 @@ func (r *reconciledResource) key() kubeutil.ResourceKey {
5050type SyncContext interface {
5151 // Terminate terminates sync operation. The method is asynchronous: it starts deletion is related K8S resources
5252 // such as in-flight resource hooks, updates operation status, and exists without waiting for resource completion.
53+ // Deprecated: use TerminateContext instead
5354 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 )
5458 // Executes next synchronization step and updates operation status.
59+ // Deprecated: use SyncContext instead
5560 Sync ()
61+ // Executes next synchronization step and updates operation status.
62+ SyncContext (ctx context.Context )
5663 // Returns current sync operation state and information about resources synchronized so far.
5764 GetState () (common.OperationPhase , string , []common.ResourceSyncResult )
5865}
@@ -75,12 +82,20 @@ func WithPermissionValidator(validator common.PermissionValidator) SyncOpt {
7582}
7683
7784// WithHealthOverride sets specified health override
85+ // Deprecated: use WithHealthOverrideContext instead
7886func WithHealthOverride (override health.HealthOverride ) SyncOpt {
7987 return func (ctx * syncContext ) {
8088 ctx .healthOverride = override
8189 }
8290}
8391
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+
8499// WithInitialState sets sync operation initial state
85100func WithInitialState (phase common.OperationPhase , message string , results []common.ResourceSyncResult , startedAt metav1.Time ) SyncOpt {
86101 return func (ctx * syncContext ) {
@@ -308,11 +323,18 @@ const (
308323)
309324
310325// 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 ) {
312327 phase := common .OperationSucceeded
313328 message := obj .GetName () + " created"
314329
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+ }
316338 if err != nil {
317339 return "" , "" , err
318340 }
@@ -333,18 +355,19 @@ func (sc *syncContext) getOperationPhase(obj *unstructured.Unstructured) (common
333355}
334356
335357type 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
348371
349372 dryRun bool
350373 skipDryRun bool
@@ -403,8 +426,19 @@ func (sc *syncContext) setRunningPhase(tasks []*syncTask, isPendingDeletion bool
403426 }
404427}
405428
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
407431func (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 ) {
408442 sc .log .WithValues ("skipHooks" , sc .skipHooks , "started" , sc .started ()).Info ("Syncing" )
409443 tasks , ok := sc .getSyncTasks ()
410444 if ! ok {
@@ -441,7 +475,7 @@ func (sc *syncContext) Sync() {
441475 }) {
442476 if task .isHook () {
443477 // update the hook's result
444- operationState , message , err := sc .getOperationPhase (task .liveObj )
478+ operationState , message , err := sc .getOperationPhase (ctx , task .liveObj )
445479 if err != nil {
446480 sc .setResourceResult (task , "" , common .OperationError , fmt .Sprintf ("failed to get resource health: %v" , err ))
447481 } else {
@@ -1176,8 +1210,17 @@ func (sc *syncContext) hasCRDOfGroupKind(group string, kind string) bool {
11761210 return false
11771211}
11781212
1179- // terminate looks for any running jobs/workflow hooks and deletes the resource
1213+ // Deprecated: use TerminateContext instead
11801214func (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 ) {
11811224 terminateSuccessful := true
11821225 sc .log .V (1 ).Info ("terminating" )
11831226 tasks , _ := sc .getSyncTasks ()
@@ -1190,7 +1233,7 @@ func (sc *syncContext) Terminate() {
11901233 terminateSuccessful = false
11911234 continue
11921235 }
1193- phase , msg , err := sc .getOperationPhase (task .liveObj )
1236+ phase , msg , err := sc .getOperationPhase (ctx , task .liveObj )
11941237 if err != nil {
11951238 sc .setOperationPhase (common .OperationError , fmt .Sprintf ("Failed to get hook health: %v" , err ))
11961239 return
0 commit comments