Skip to content

Commit 0380f95

Browse files
committed
Non-blocking standard output stream parsing
1 parent f3f1f03 commit 0380f95

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Net;
66
using System.Runtime.InteropServices;
77
using System.Security.Cryptography.X509Certificates;
8+
using System.Text;
89

910
namespace k8s
1011
{
@@ -537,13 +538,23 @@ public static ExecCredentialResponse ExecuteExternalCommand(ExternalExecution co
537538

538539
try
539540
{
540-
var responseObject = KubernetesJson.Deserialize<ExecCredentialResponse>(process.StandardOutput.ReadToEnd());
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();
541550

542551
if (!process.WaitForExit((int)ExecTimeout.TotalMilliseconds))
543552
{
544553
throw new KubeConfigException("external exec failed due to timeout");
545554
}
546555

556+
var responseObject = KubernetesJson.Deserialize<ExecCredentialResponse>(output.ToString());
557+
547558
if (responseObject == null || responseObject.ApiVersion != config.ApiVersion)
548559
{
549560
throw new KubeConfigException(
@@ -554,10 +565,8 @@ public static ExecCredentialResponse ExecuteExternalCommand(ExternalExecution co
554565
{
555566
return responseObject;
556567
}
557-
else
558-
{
559-
throw new KubeConfigException($"external exec failed missing token or clientCertificateData field in plugin output");
560-
}
568+
569+
throw new KubeConfigException($"external exec failed missing token or clientCertificateData field in plugin output");
561570
}
562571
catch (JsonException ex)
563572
{

0 commit comments

Comments
 (0)