Skip to content

Commit 44817fb

Browse files
committed
fix: add timeout to apply/replace kubectl calls (argoproj#572)
Signed-off-by: Jonathan West <[email protected]>
1 parent fbecbb8 commit 44817fb

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

pkg/utils/kube/kube.go

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ const (
5555
HorizontalPodAutoscalerKind = "HorizontalPodAutoscaler"
5656
)
5757

58+
const (
59+
// defaultKubectlRequestTimeout is the timeout value used when calling the 'apply' command of kubectl. The previous default was no timeout, which would allow apply operation to potentially run forever, thus leaking YAML files into /dev/shm until Pod restart.
60+
defaultKubectlRequestTimeout = time.Hour * 1
61+
)
62+
5863
type ResourceInfoProvider interface {
5964
IsNamespaced(gk schema.GroupKind) (bool, error)
6065
}

pkg/utils/kube/resource_ops.go

+13
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ func (k *kubectlResourceOperations) ReplaceResource(ctx context.Context, obj *un
175175
if err != nil {
176176
return err
177177
}
178+
179+
// When calling the kubectl 'replace' command, it will run _without_ a timeout (as of this writing, May 2024):
180+
// - If users are finding that 'replace' operations are running forever (and thus leaking manifest files into '/dev/shm'), one can enable 'force' via sync options or annotation, which will enable a default timeout of 5 minutes within the 'replace' kubectl call.
181+
// - However, this guidance apply to replace options only (i.e. not apply).
182+
178183
return replaceOptions.Run(f)
179184
})
180185
}
@@ -261,6 +266,14 @@ func (k *kubectlResourceOperations) ApplyResource(ctx context.Context, obj *unst
261266
if err != nil {
262267
return err
263268
}
269+
270+
// If no timeout is specified (and thus an infinite wait), we will substitute a LONG default value.
271+
// This allows enough time to complete for any valid, expected long running apply operations, while also preventing excessive leaks of resources into /dev/shm, due to operations that are likely never going to complete.
272+
if applyOpts.DeleteOptions.Timeout == 0 {
273+
// Yes, this is correct: Apply uses the 'DeleteOptions' struct to set the timeout val
274+
applyOpts.DeleteOptions.Timeout = defaultKubectlRequestTimeout
275+
}
276+
264277
return applyOpts.Run()
265278
})
266279
}

0 commit comments

Comments
 (0)