Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Net;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;

namespace k8s
{
Expand Down Expand Up @@ -537,12 +538,29 @@ public static ExecCredentialResponse ExecuteExternalCommand(ExternalExecution co

try
{
if (!process.WaitForExit((int)(ExecTimeout.TotalMilliseconds)))
var output = new StringBuilder();
process.OutputDataReceived += (_, args) =>
{
if (args.Data != null)
{
output.Append(args.Data);
}
};
process.BeginOutputReadLine();

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

var responseObject = KubernetesJson.Deserialize<ExecCredentialResponse>(process.StandardOutput.ReadToEnd());
// Force flush the output buffer to avoid case of missing data
if (ExecTimeout != Timeout.InfiniteTimeSpan)
{
process.WaitForExit();
}

var responseObject = KubernetesJson.Deserialize<ExecCredentialResponse>(output.ToString());

if (responseObject == null || responseObject.ApiVersion != config.ApiVersion)
{
throw new KubeConfigException(
Expand All @@ -553,10 +571,8 @@ public static ExecCredentialResponse ExecuteExternalCommand(ExternalExecution co
{
return responseObject;
}
else
{
throw new KubeConfigException($"external exec failed missing token or clientCertificateData field in plugin output");
}

throw new KubeConfigException($"external exec failed missing token or clientCertificateData field in plugin output");
}
catch (JsonException ex)
{
Expand Down