@@ -28,6 +28,16 @@ public partial class KubernetesClientConfiguration
28
28
// For testing
29
29
internal static string KubeConfigEnvironmentVariable { get ; set ; } = "KUBECONFIG" ;
30
30
31
+ /// <summary>
32
+ /// Exec process timeout
33
+ /// </summary>
34
+ public static TimeSpan ExecTimeout { get ; set ; } = TimeSpan . FromMinutes ( 2 ) ;
35
+
36
+ /// <summary>
37
+ /// Exec process Standard Errors
38
+ /// </summary>
39
+ public static event EventHandler < DataReceivedEventArgs > ExecStdError ;
40
+
31
41
/// <summary>
32
42
/// Initializes a new instance of the <see cref="KubernetesClientConfiguration" /> from default locations
33
43
/// If the KUBECONFIG environment variable is set, then that will be used.
@@ -552,25 +562,25 @@ public static ExecCredentialResponse ExecuteExternalCommand(ExternalExecution co
552
562
try
553
563
{
554
564
process . Start ( ) ;
565
+ if ( ExecStdError != null )
566
+ {
567
+ process . ErrorDataReceived += ( s , e ) => ExecStdError . Invoke ( s , e ) ;
568
+ process . BeginErrorReadLine ( ) ;
569
+ }
555
570
}
556
571
catch ( Exception ex )
557
572
{
558
573
throw new KubeConfigException ( $ "external exec failed due to: { ex . Message } ") ;
559
574
}
560
575
561
- var stdout = process . StandardOutput . ReadToEnd ( ) ;
562
- var stderr = process . StandardError . ReadToEnd ( ) ;
563
- if ( string . IsNullOrWhiteSpace ( stderr ) == false )
564
- {
565
- throw new KubeConfigException ( $ "external exec failed due to: { stderr } ") ;
566
- }
567
-
568
- // Wait for a maximum of 5 seconds, if a response takes longer probably something went wrong...
569
- process . WaitForExit ( 5 ) ;
570
-
571
576
try
572
577
{
573
- var responseObject = KubernetesJson . Deserialize < ExecCredentialResponse > ( stdout ) ;
578
+ if ( ! process . WaitForExit ( ( int ) ( ExecTimeout . TotalMilliseconds ) ) )
579
+ {
580
+ throw new KubeConfigException ( "external exec failed due to timeout" ) ;
581
+ }
582
+
583
+ var responseObject = KubernetesJson . Deserialize < ExecCredentialResponse > ( process . StandardOutput . ReadToEnd ( ) ) ;
574
584
if ( responseObject == null || responseObject . ApiVersion != config . ApiVersion )
575
585
{
576
586
throw new KubeConfigException (
0 commit comments