diff --git a/src/Microsoft.Tye.Core/DeployApplicationKubernetesManifestStep.cs b/src/Microsoft.Tye.Core/DeployApplicationKubernetesManifestStep.cs index cd7cf247..a2a7ec9a 100644 --- a/src/Microsoft.Tye.Core/DeployApplicationKubernetesManifestStep.cs +++ b/src/Microsoft.Tye.Core/DeployApplicationKubernetesManifestStep.cs @@ -17,12 +17,12 @@ namespace Microsoft.Tye { 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."); } - 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."); } diff --git a/src/Microsoft.Tye.Core/ValidateIngressStep.cs b/src/Microsoft.Tye.Core/ValidateIngressStep.cs index 6d99fd17..70a4a1cc 100644 --- a/src/Microsoft.Tye.Core/ValidateIngressStep.cs +++ b/src/Microsoft.Tye.Core/ValidateIngressStep.cs @@ -43,12 +43,12 @@ namespace Microsoft.Tye return; } - if (!await KubectlDetector.Instance.IsKubectlInstalled.Value) + if (!await KubectlDetector.IsKubectlInstalledAsync(output)) { 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."); } diff --git a/src/shared/KubectlDetector.cs b/src/shared/KubectlDetector.cs index 8149ac6c..575dd2ca 100644 --- a/src/shared/KubectlDetector.cs +++ b/src/shared/KubectlDetector.cs @@ -7,19 +7,28 @@ using System.Threading.Tasks; namespace Microsoft.Tye { - internal class KubectlDetector + internal static class KubectlDetector { - public static KubectlDetector Instance { get; } = new KubectlDetector(); + private static Lazy> _kubectlInstalled = new Lazy>(DetectKubectlInstalled); + private static Lazy> _kubectlConnectedToCluster = new Lazy>(DetectKubectlConnectedToCluster); - private KubectlDetector() + public static Task IsKubectlInstalledAsync(OutputContext output) { - IsKubectlInstalled = new Lazy>(DetectKubectlInstalled); - IsKubectlConnectedToCluster = new Lazy>(DetectKubectlConnectedToCluster); + if (!_kubectlInstalled.IsValueCreated) + { + output.WriteInfoLine("Verifying kubectl installation..."); + } + return _kubectlInstalled.Value; } - public Lazy> IsKubectlInstalled { get; } - - public Lazy> IsKubectlConnectedToCluster { get; } + public static Task IsKubectlConnectedToClusterAsync(OutputContext output) + { + if (!_kubectlConnectedToCluster.IsValueCreated) + { + output.WriteInfoLine("Verifying kubectl connection to cluster..."); + } + return _kubectlConnectedToCluster.Value; + } private static async Task DetectKubectlInstalled() { diff --git a/src/tye/Program.DeployCommand.cs b/src/tye/Program.DeployCommand.cs index f2f1fbaf..e50f2891 100644 --- a/src/tye/Program.DeployCommand.cs +++ b/src/tye/Program.DeployCommand.cs @@ -66,12 +66,12 @@ namespace Microsoft.Tye { 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."); } - 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."); }