Browse Source

Add the ability to specify a namespace for tye deploy.

davidfowl/ingress-changes
Brendan Burns 7 years ago
committed by Ryan Nowak
parent
commit
b91c73195f
  1. 2
      src/Microsoft.Tye.Core/ApplicationBuilder.cs
  2. 2
      src/Microsoft.Tye.Core/ApplicationFactory.cs
  3. 2
      src/Microsoft.Tye.Core/ConfigModel/ConfigApplication.cs
  4. 2
      src/Microsoft.Tye.Core/GenerateKubernetesManifestStep.cs
  5. 6
      src/Microsoft.Tye.Core/KubernetesManifestGenerator.cs
  6. 3
      src/Microsoft.Tye.Core/Serialization/ConfigApplicationParser.cs
  7. 13
      src/Microsoft.Tye.Core/StandardOptions.cs
  8. 8
      src/tye/GenerateHost.cs
  9. 18
      src/tye/Program.DeployCommand.cs
  10. 5
      src/tye/Program.GenerateCommand.cs

2
src/Microsoft.Tye.Core/ApplicationBuilder.cs

@ -19,6 +19,8 @@ namespace Microsoft.Tye
public string Name { get; set; } public string Name { get; set; }
public string? Namespace { get; set; }
public ContainerRegistry? Registry { get; set; } public ContainerRegistry? Registry { get; set; }
public List<ExtensionConfiguration> Extensions { get; } = new List<ExtensionConfiguration>(); public List<ExtensionConfiguration> Extensions { get; } = new List<ExtensionConfiguration>();

2
src/Microsoft.Tye.Core/ApplicationFactory.cs

@ -28,7 +28,7 @@ namespace Microsoft.Tye
rootConfig.Validate(); rootConfig.Validate();
var root = new ApplicationBuilder(source, rootConfig.Name ?? source.Directory.Name.ToLowerInvariant()); var root = new ApplicationBuilder(source, rootConfig.Name ?? source.Directory.Name.ToLowerInvariant());
root.Namespace = rootConfig.Namespace;
queue.Enqueue(rootConfig); queue.Enqueue(rootConfig);
while (queue.Count > 0) while (queue.Count > 0)

2
src/Microsoft.Tye.Core/ConfigModel/ConfigApplication.cs

@ -24,6 +24,8 @@ namespace Microsoft.Tye.ConfigModel
public string? Name { get; set; } public string? Name { get; set; }
public string? Namespace { get; set; }
public string? Registry { get; set; } public string? Registry { get; set; }
public string? Network { get; set; } public string? Network { get; set; }

2
src/Microsoft.Tye.Core/GenerateKubernetesManifestStep.cs

@ -12,6 +12,8 @@ namespace Microsoft.Tye
public string Environment { get; set; } = "production"; public string Environment { get; set; } = "production";
public string? Namespace { get; set; } = null;
public override Task ExecuteAsync(OutputContext output, ApplicationBuilder application, ServiceBuilder service) public override Task ExecuteAsync(OutputContext output, ApplicationBuilder application, ServiceBuilder service)
{ {

6
src/Microsoft.Tye.Core/KubernetesManifestGenerator.cs

@ -26,6 +26,9 @@ namespace Microsoft.Tye
var metadata = new YamlMappingNode(); var metadata = new YamlMappingNode();
root.Add("metadata", metadata); root.Add("metadata", metadata);
metadata.Add("name", project.Name); metadata.Add("name", project.Name);
if (!String.IsNullOrEmpty(application.Namespace)) {
metadata.Add("namespace", application.Namespace);
}
if (service.Annotations.Count > 0) if (service.Annotations.Count > 0)
{ {
@ -104,6 +107,9 @@ namespace Microsoft.Tye
var metadata = new YamlMappingNode(); var metadata = new YamlMappingNode();
root.Add("metadata", metadata); root.Add("metadata", metadata);
metadata.Add("name", project.Name); metadata.Add("name", project.Name);
if (!String.IsNullOrEmpty(application.Namespace)) {
metadata.Add("namespace", application.Namespace);
}
if (deployment.Annotations.Count > 0) if (deployment.Annotations.Count > 0)
{ {

3
src/Microsoft.Tye.Core/Serialization/ConfigApplicationParser.cs

@ -20,6 +20,9 @@ namespace Tye.Serialization
case "name": case "name":
app.Name = YamlParser.GetScalarValue(key, child.Value); app.Name = YamlParser.GetScalarValue(key, child.Value);
break; break;
case "namespace":
app.Namespace = YamlParser.GetScalarValue(key, child.Value);
break;
case "network": case "network":
app.Network = YamlParser.GetScalarValue(key, child.Value); app.Network = YamlParser.GetScalarValue(key, child.Value);
break; break;

13
src/Microsoft.Tye.Core/StandardOptions.cs

@ -195,5 +195,18 @@ namespace Microsoft.Tye
}; };
} }
} }
public static Option Namespace
{
get
{
return new Option(new[] { "-n", "--namespace" })
{
Description = "Specify the namespace for the deployment",
Required = false,
Argument = new Argument<string>(),
};
}
}
} }
} }

8
src/tye/GenerateHost.cs

@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.CommandLine; using System.CommandLine;
using System.IO; using System.IO;
@ -12,7 +13,7 @@ namespace Microsoft.Tye
{ {
public static class GenerateHost public static class GenerateHost
{ {
public static async Task GenerateAsync(IConsole console, FileInfo path, Verbosity verbosity, bool interactive) public static async Task GenerateAsync(IConsole console, FileInfo path, Verbosity verbosity, bool interactive, string ns)
{ {
var output = new OutputContext(console, verbosity); var output = new OutputContext(console, verbosity);
@ -22,7 +23,10 @@ namespace Microsoft.Tye
{ {
throw new CommandException($"No services found in \"{application.Source.Name}\""); throw new CommandException($"No services found in \"{application.Source.Name}\"");
} }
if (!String.IsNullOrEmpty(ns))
{
application.Namespace = ns;
}
await ExecuteGenerateAsync(output, application, environment: "production", interactive); await ExecuteGenerateAsync(output, application, environment: "production", interactive);
} }

18
src/tye/Program.DeployCommand.cs

@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.CommandLine; using System.CommandLine;
using System.CommandLine.Invocation; using System.CommandLine.Invocation;
@ -21,6 +22,7 @@ namespace Microsoft.Tye
CommonArguments.Path_Required, CommonArguments.Path_Required,
StandardOptions.Interactive, StandardOptions.Interactive,
StandardOptions.Verbosity, StandardOptions.Verbosity,
StandardOptions.Namespace,
}; };
command.AddOption(new Option(new[] { "-f", "--force" }) command.AddOption(new Option(new[] { "-f", "--force" })
@ -29,7 +31,7 @@ namespace Microsoft.Tye
Required = false Required = false
}); });
command.Handler = CommandHandler.Create<IConsole, FileInfo, Verbosity, bool, bool>(async (console, path, verbosity, interactive, force) => command.Handler = CommandHandler.Create<IConsole, FileInfo, Verbosity, bool, bool, string>(async (console, path, verbosity, interactive, force, @namespace) =>
{ {
// Workaround for https://github.com/dotnet/command-line-api/issues/723#issuecomment-593062654 // Workaround for https://github.com/dotnet/command-line-api/issues/723#issuecomment-593062654
if (path is null) if (path is null)
@ -45,7 +47,10 @@ namespace Microsoft.Tye
{ {
throw new CommandException($"No services found in \"{application.Source.Name}\""); throw new CommandException($"No services found in \"{application.Source.Name}\"");
} }
if (!String.IsNullOrEmpty(@namespace))
{
application.Namespace = @namespace;
}
await ExecuteDeployAsync(new OutputContext(console, verbosity), application, environment: "production", interactive, force); await ExecuteDeployAsync(new OutputContext(console, verbosity), application, environment: "production", interactive, force);
}); });
@ -75,7 +80,7 @@ namespace Microsoft.Tye
new ValidateSecretStep() { Environment = environment, Interactive = interactive, Force = force, }, new ValidateSecretStep() { Environment = environment, Interactive = interactive, Force = force, },
}; };
steps.Add(new GenerateKubernetesManifestStep() { Environment = environment, }); steps.Add(new GenerateKubernetesManifestStep() { Environment = environment, Namespace = application.Namespace });
steps.Add(new DeployServiceYamlStep() { Environment = environment, }); steps.Add(new DeployServiceYamlStep() { Environment = environment, });
ApplyRegistryAndDefaults(output, application, interactive, requireRegistry: true); ApplyRegistryAndDefaults(output, application, interactive, requireRegistry: true);
@ -103,7 +108,12 @@ namespace Microsoft.Tye
await ApplicationYamlWriter.WriteAsync(output, writer, application); await ApplicationYamlWriter.WriteAsync(output, writer, application);
} }
output.WriteDebugLine("Running 'kubectl apply'."); string ns = $"namespace ${application.Namespace}";
if (String.IsNullOrEmpty(application.Namespace))
{
ns = "current namespace";
}
output.WriteDebugLine($"Running 'kubectl apply' in ${ns}");
output.WriteCommandLine("kubectl", $"apply -f \"{tempFile.FilePath}\""); output.WriteCommandLine("kubectl", $"apply -f \"{tempFile.FilePath}\"");
var capture = output.Capture(); var capture = output.Capture();
var exitCode = await Process.ExecuteAsync( var exitCode = await Process.ExecuteAsync(

5
src/tye/Program.GenerateCommand.cs

@ -21,13 +21,14 @@ namespace Microsoft.Tye
CommonArguments.Path_Required, CommonArguments.Path_Required,
StandardOptions.Interactive, StandardOptions.Interactive,
StandardOptions.Verbosity, StandardOptions.Verbosity,
StandardOptions.Namespace,
}; };
// This is a super-secret VIP-only command! It's useful for testing, but we're // This is a super-secret VIP-only command! It's useful for testing, but we're
// not documenting it right now. // not documenting it right now.
command.IsHidden = true; command.IsHidden = true;
command.Handler = CommandHandler.Create<IConsole, FileInfo, Verbosity, bool>((console, path, verbosity, interactive) => command.Handler = CommandHandler.Create<IConsole, FileInfo, Verbosity, bool, string>((console, path, verbosity, interactive, @namespace) =>
{ {
// Workaround for https://github.com/dotnet/command-line-api/issues/723#issuecomment-593062654 // Workaround for https://github.com/dotnet/command-line-api/issues/723#issuecomment-593062654
if (path is null) if (path is null)
@ -35,7 +36,7 @@ namespace Microsoft.Tye
throw new CommandException("No project or solution file was found."); throw new CommandException("No project or solution file was found.");
} }
return GenerateHost.GenerateAsync(console, path, verbosity, interactive); return GenerateHost.GenerateAsync(console, path, verbosity, interactive, @namespace);
}); });
return command; return command;

Loading…
Cancel
Save