File tree 1 file changed +22
-6
lines changed
1 file changed +22
-6
lines changed Original file line number Diff line number Diff line change 5
5
using System . Net ;
6
6
using System . Runtime . InteropServices ;
7
7
using System . Security . Cryptography . X509Certificates ;
8
+ using System . Text ;
8
9
9
10
namespace k8s
10
11
{
@@ -537,12 +538,29 @@ public static ExecCredentialResponse ExecuteExternalCommand(ExternalExecution co
537
538
538
539
try
539
540
{
540
- if ( ! process . WaitForExit ( ( int ) ( ExecTimeout . TotalMilliseconds ) ) )
541
+ var output = new StringBuilder ( ) ;
542
+ process . OutputDataReceived += ( _ , args ) =>
543
+ {
544
+ if ( args . Data != null )
545
+ {
546
+ output . Append ( args . Data ) ;
547
+ }
548
+ } ;
549
+ process . BeginOutputReadLine ( ) ;
550
+
551
+ if ( ! process . WaitForExit ( ( int ) ExecTimeout . TotalMilliseconds ) )
541
552
{
542
553
throw new KubeConfigException ( "external exec failed due to timeout" ) ;
543
554
}
544
555
545
- var responseObject = KubernetesJson . Deserialize < ExecCredentialResponse > ( process . StandardOutput . ReadToEnd ( ) ) ;
556
+ // Force flush the output buffer to avoid case of missing data
557
+ if ( ExecTimeout != Timeout . InfiniteTimeSpan )
558
+ {
559
+ process . WaitForExit ( ) ;
560
+ }
561
+
562
+ var responseObject = KubernetesJson . Deserialize < ExecCredentialResponse > ( output . ToString ( ) ) ;
563
+
546
564
if ( responseObject == null || responseObject . ApiVersion != config . ApiVersion )
547
565
{
548
566
throw new KubeConfigException (
@@ -553,10 +571,8 @@ public static ExecCredentialResponse ExecuteExternalCommand(ExternalExecution co
553
571
{
554
572
return responseObject ;
555
573
}
556
- else
557
- {
558
- throw new KubeConfigException ( $ "external exec failed missing token or clientCertificateData field in plugin output") ;
559
- }
574
+
575
+ throw new KubeConfigException ( $ "external exec failed missing token or clientCertificateData field in plugin output") ;
560
576
}
561
577
catch ( JsonException ex )
562
578
{
You can’t perform that action at this time.
0 commit comments