diff --git a/src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs b/src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs
index 9d439ad78..85085838c 100644
--- a/src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs
+++ b/src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs
@@ -28,6 +28,16 @@ public partial class KubernetesClientConfiguration
// For testing
internal static string KubeConfigEnvironmentVariable { get; set; } = "KUBECONFIG";
+ ///
+ /// Exec process timeout
+ ///
+ public static TimeSpan ExecTimeout { get; set; } = TimeSpan.FromMinutes(2);
+
+ ///
+ /// Exec process Standard Errors
+ ///
+ public static event EventHandler ExecStdError;
+
///
/// Initializes a new instance of the from default locations
/// If the KUBECONFIG environment variable is set, then that will be used.
@@ -552,25 +562,25 @@ public static ExecCredentialResponse ExecuteExternalCommand(ExternalExecution co
try
{
process.Start();
+ if (ExecStdError != null)
+ {
+ process.ErrorDataReceived += (s, e) => ExecStdError.Invoke(s, e);
+ process.BeginErrorReadLine();
+ }
}
catch (Exception ex)
{
throw new KubeConfigException($"external exec failed due to: {ex.Message}");
}
- var stdout = process.StandardOutput.ReadToEnd();
- var stderr = process.StandardError.ReadToEnd();
- if (string.IsNullOrWhiteSpace(stderr) == false)
- {
- throw new KubeConfigException($"external exec failed due to: {stderr}");
- }
-
- // Wait for a maximum of 5 seconds, if a response takes longer probably something went wrong...
- process.WaitForExit(5);
-
try
{
- var responseObject = KubernetesJson.Deserialize(stdout);
+ if (!process.WaitForExit((int)(ExecTimeout.TotalMilliseconds)))
+ {
+ throw new KubeConfigException("external exec failed due to timeout");
+ }
+
+ var responseObject = KubernetesJson.Deserialize(process.StandardOutput.ReadToEnd());
if (responseObject == null || responseObject.ApiVersion != config.ApiVersion)
{
throw new KubeConfigException(