Skip to content

Commit

Permalink
chore: simplify logic
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanJosipovic committed Apr 18, 2023
1 parent 8e7bf08 commit f516d69
Showing 1 changed file with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -567,43 +567,41 @@ public static ExecCredentialResponse ExecuteExternalCommand(ExternalExecution co
}

// Wait for a maximum of 5 seconds, if a response takes longer probably something went wrong...
if (process.WaitForExitAsync().Wait(TimeSpan.FromSeconds(5)))
if (!process.WaitForExitAsync().Wait(TimeSpan.FromSeconds(5)))
{
try
{
var responseObject = KubernetesJson.Deserialize<ExecCredentialResponse>(stdout);
if (responseObject == null || responseObject.ApiVersion != config.ApiVersion)
{
throw new KubeConfigException(
$"external exec failed because api version {responseObject.ApiVersion} does not match {config.ApiVersion}");
}
throw new KubeConfigException("external exec failed due to timeout");
}

if (responseObject.Status.IsValid())
{
return responseObject;
}
else
{
throw new KubeConfigException($"external exec failed missing token or clientCertificateData field in plugin output");
}
if (!string.IsNullOrWhiteSpace(stderr))
{
throw new KubeConfigException($"external exec failed due to: {stderr}");
}

try
{
var responseObject = KubernetesJson.Deserialize<ExecCredentialResponse>(stdout);
if (responseObject == null || responseObject.ApiVersion != config.ApiVersion)
{
throw new KubeConfigException(
$"external exec failed because api version {responseObject.ApiVersion} does not match {config.ApiVersion}");
}
catch (JsonException ex)

if (responseObject.Status.IsValid())
{
throw new KubeConfigException($"external exec failed due to failed deserialization process: {ex}");
return responseObject;
}
catch (Exception ex)
else
{
throw new KubeConfigException($"external exec failed due to uncaught exception: {ex}");
throw new KubeConfigException($"external exec failed missing token or clientCertificateData field in plugin output");
}
}
else
catch (JsonException ex)
{
if (!string.IsNullOrWhiteSpace(stderr))
{
throw new KubeConfigException($"external exec failed due to: {stderr}");
}

throw new KubeConfigException("external exec failed due to timeout");
throw new KubeConfigException($"external exec failed due to failed deserialization process: {ex}");
}
catch (Exception ex)
{
throw new KubeConfigException($"external exec failed due to uncaught exception: {ex}");
}
}

Expand Down

0 comments on commit f516d69

Please sign in to comment.