Skip to content

Commit 3dbcccc

Browse files
committed
use withoutcancel instead of trafering values
1 parent 2872a05 commit 3dbcccc

File tree

1 file changed

+12
-38
lines changed

1 file changed

+12
-38
lines changed

pkg/runtime/reconciler.go

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,6 @@ const (
5757
// resource if the CARM cache is not synced yet, or if the roleARN is not
5858
// available.
5959
roleARNNotAvailableRequeueDelay = 15 * time.Second
60-
// adoptOrCreate is an annotation field that decides whether to create the
61-
// resource if it doesn't exist, or adopt the resource if it exists.
62-
// value comes from getAdoptionPolicy
63-
// adoptOrCreate = "adopt-or-create"
64-
// patchContextTimeout is the default duration to patch the resource. This
65-
// is used to ensure critical metadata/spec/status updates are saved even
66-
// during controller shutdown
67-
patchContextTimeout = 10 * time.Second
6860
)
6961

7062
// reconciler describes a generic reconciler within ACK.
@@ -864,20 +856,6 @@ func (r *resourceReconciler) patchResourceMetadataAndSpec(
864856
var err error
865857
rlog := ackrtlog.FromContext(ctx)
866858

867-
// Create fresh timeout context for the patch operation
868-
// This is to ensure that the patch operation is not cancelled
869-
// when the original context is cancelled
870-
patchCtx, cancel := context.WithTimeout(context.Background(), patchContextTimeout)
871-
defer cancel()
872-
873-
// Transfer important values from the original context to the patch context
874-
patchCtx = context.WithValue(patchCtx, ackrtlog.ContextKey, rlog)
875-
if ns := ctx.Value("resourceNamespace"); ns != nil {
876-
patchCtx = context.WithValue(patchCtx, "resourceNamespace", ns)
877-
}
878-
879-
rlog.Info("created patch context with timeout", "timeout_seconds", patchContextTimeout.Seconds())
880-
881859
exit := rlog.Trace("r.patchResourceMetadataAndSpec")
882860
defer func() {
883861
exit(err)
@@ -900,7 +878,12 @@ func (r *resourceReconciler) patchResourceMetadataAndSpec(
900878
lorig := latestCleaned.DeepCopy()
901879
patch := client.MergeFrom(desiredCleaned.RuntimeObject())
902880

903-
// Use the fresh timeout context for the patch operation
881+
// NOTE (rushmash91): Always use WithoutCancel to prevent patch operations from being
882+
// cancelled while preserving context values. The 30s SIGTERM grace period acts as
883+
// the effective timeout - no additional timeout needed to avoid interfering with
884+
// normal Kubernetes client timeout/retry strategy.
885+
patchCtx := context.WithoutCancel(ctx)
886+
904887
err = r.kc.Patch(patchCtx, latestCleaned.RuntimeObject(), patch)
905888

906889
if err == nil {
@@ -930,20 +913,6 @@ func (r *resourceReconciler) patchResourceStatus(
930913
var err error
931914
rlog := ackrtlog.FromContext(ctx)
932915

933-
// Create fresh timeout context for the patch operation
934-
// This is to ensure that the patch operation is not cancelled
935-
// when the original context is cancelled
936-
patchCtx, cancel := context.WithTimeout(context.Background(), patchContextTimeout)
937-
defer cancel()
938-
939-
// Transfer important values from the original context to the patch context
940-
patchCtx = context.WithValue(patchCtx, ackrtlog.ContextKey, rlog)
941-
if ns := ctx.Value("resourceNamespace"); ns != nil {
942-
patchCtx = context.WithValue(patchCtx, "resourceNamespace", ns)
943-
}
944-
945-
rlog.Info("created patch context with timeout", "timeout_seconds", patchContextTimeout.Seconds())
946-
947916
exit := rlog.Trace("r.patchResourceStatus")
948917
defer func() {
949918
exit(err)
@@ -954,7 +923,12 @@ func (r *resourceReconciler) patchResourceStatus(
954923
lobj := latest.DeepCopy().RuntimeObject()
955924
patch := client.MergeFrom(dobj)
956925

957-
// Use the fresh timeout context for the patch operation
926+
// NOTE (rushmash91): Always use WithoutCancel to prevent patch operations from being
927+
// cancelled while preserving context values. The 30s SIGTERM grace period acts as
928+
// the effective timeout - no additional timeout needed to avoid interfering with
929+
// normal Kubernetes client timeout/retry strategy.
930+
patchCtx := context.WithoutCancel(ctx)
931+
958932
err = r.kc.Status().Patch(patchCtx, lobj, patch)
959933

960934
if err == nil {

0 commit comments

Comments
 (0)