Browse Source

Add logging for KubectlDetector logic (#586)

pull/595/head
John Luo 6 years ago
committed by GitHub
parent
commit
43e38c0d12
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/Microsoft.Tye.Core/DeployApplicationKubernetesManifestStep.cs
  2. 4
      src/Microsoft.Tye.Core/ValidateIngressStep.cs
  3. 25
      src/shared/KubectlDetector.cs
  4. 4
      src/tye/Program.DeployCommand.cs

4
src/Microsoft.Tye.Core/DeployApplicationKubernetesManifestStep.cs

@ -17,12 +17,12 @@ namespace Microsoft.Tye
{ {
using var step = output.BeginStep(""); using var step = output.BeginStep("");
if (!await KubectlDetector.Instance.IsKubectlInstalled.Value) if (!await KubectlDetector.IsKubectlInstalledAsync(output))
{ {
throw new CommandException($"Cannot apply manifests because kubectl is not installed."); throw new CommandException($"Cannot apply manifests because kubectl is not installed.");
} }
if (!await KubectlDetector.Instance.IsKubectlConnectedToCluster.Value) if (!await KubectlDetector.IsKubectlConnectedToClusterAsync(output))
{ {
throw new CommandException($"Cannot apply manifests because kubectl is not connected to a cluster."); throw new CommandException($"Cannot apply manifests because kubectl is not connected to a cluster.");
} }

4
src/Microsoft.Tye.Core/ValidateIngressStep.cs

@ -43,12 +43,12 @@ namespace Microsoft.Tye
return; return;
} }
if (!await KubectlDetector.Instance.IsKubectlInstalled.Value) if (!await KubectlDetector.IsKubectlInstalledAsync(output))
{ {
throw new CommandException($"Cannot validate ingress because kubectl is not installed."); throw new CommandException($"Cannot validate ingress because kubectl is not installed.");
} }
if (!await KubectlDetector.Instance.IsKubectlConnectedToCluster.Value) if (!await KubectlDetector.IsKubectlConnectedToClusterAsync(output))
{ {
throw new CommandException($"Cannot validate ingress because kubectl is not connected to a cluster."); throw new CommandException($"Cannot validate ingress because kubectl is not connected to a cluster.");
} }

25
src/shared/KubectlDetector.cs

@ -7,19 +7,28 @@ using System.Threading.Tasks;
namespace Microsoft.Tye namespace Microsoft.Tye
{ {
internal class KubectlDetector internal static class KubectlDetector
{ {
public static KubectlDetector Instance { get; } = new KubectlDetector(); private static Lazy<Task<bool>> _kubectlInstalled = new Lazy<Task<bool>>(DetectKubectlInstalled);
private static Lazy<Task<bool>> _kubectlConnectedToCluster = new Lazy<Task<bool>>(DetectKubectlConnectedToCluster);
private KubectlDetector() public static Task<bool> IsKubectlInstalledAsync(OutputContext output)
{ {
IsKubectlInstalled = new Lazy<Task<bool>>(DetectKubectlInstalled); if (!_kubectlInstalled.IsValueCreated)
IsKubectlConnectedToCluster = new Lazy<Task<bool>>(DetectKubectlConnectedToCluster); {
output.WriteInfoLine("Verifying kubectl installation...");
}
return _kubectlInstalled.Value;
} }
public Lazy<Task<bool>> IsKubectlInstalled { get; } public static Task<bool> IsKubectlConnectedToClusterAsync(OutputContext output)
{
public Lazy<Task<bool>> IsKubectlConnectedToCluster { get; } if (!_kubectlConnectedToCluster.IsValueCreated)
{
output.WriteInfoLine("Verifying kubectl connection to cluster...");
}
return _kubectlConnectedToCluster.Value;
}
private static async Task<bool> DetectKubectlInstalled() private static async Task<bool> DetectKubectlInstalled()
{ {

4
src/tye/Program.DeployCommand.cs

@ -66,12 +66,12 @@ namespace Microsoft.Tye
{ {
var watch = System.Diagnostics.Stopwatch.StartNew(); var watch = System.Diagnostics.Stopwatch.StartNew();
if (!await KubectlDetector.Instance.IsKubectlInstalled.Value) if (!await KubectlDetector.IsKubectlInstalledAsync(output))
{ {
throw new CommandException($"Cannot apply manifests because kubectl is not installed."); throw new CommandException($"Cannot apply manifests because kubectl is not installed.");
} }
if (!await KubectlDetector.Instance.IsKubectlConnectedToCluster.Value) if (!await KubectlDetector.IsKubectlConnectedToClusterAsync(output))
{ {
throw new CommandException($"Cannot apply manifests because kubectl is not connected to a cluster."); throw new CommandException($"Cannot apply manifests because kubectl is not connected to a cluster.");
} }

Loading…
Cancel
Save