John Luo
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
23 additions and
14 deletions
-
src/Microsoft.Tye.Core/DeployApplicationKubernetesManifestStep.cs
-
src/Microsoft.Tye.Core/ValidateIngressStep.cs
-
src/shared/KubectlDetector.cs
-
src/tye/Program.DeployCommand.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."); |
|
|
} |
|
|
} |
|
|
|
|
|
@ -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."); |
|
|
} |
|
|
} |
|
|
|
|
|
@ -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() |
|
|
{ |
|
|
{ |
|
|
|
|
|
@ -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."); |
|
|
} |
|
|
} |
|
|
|