Browse Source

Fix undeploy (#537)

pull/542/head
Justin Kotalik 6 years ago
committed by GitHub
parent
commit
7899373606
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/Microsoft.Tye.Core/ApplicationFactory.cs
  2. 2
      src/Microsoft.Tye.Core/ConfigModel/ConfigFactory.cs
  3. 27
      src/Microsoft.Tye.Core/ConfigModel/NameInferer.cs
  4. 1
      src/Microsoft.Tye.Core/Serialization/YamlParser.cs
  5. 4
      src/tye/InitHost.cs
  6. 12
      src/tye/UndeployHost.cs

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

@ -28,7 +28,7 @@ namespace Microsoft.Tye
var rootConfig = ConfigFactory.FromFile(source);
rootConfig.Validate();
var root = new ApplicationBuilder(source, rootConfig.Name ?? source.Directory.Name.ToLowerInvariant());
var root = new ApplicationBuilder(source, rootConfig.Name!);
root.Namespace = rootConfig.Namespace;
queue.Enqueue((rootConfig, new HashSet<string>()));

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

@ -39,6 +39,7 @@ namespace Microsoft.Tye.ConfigModel
var application = new ConfigApplication()
{
Source = file,
Name = NameInferer.InferApplicationName(file)
};
var service = new ConfigService()
@ -57,6 +58,7 @@ namespace Microsoft.Tye.ConfigModel
var application = new ConfigApplication()
{
Source = file,
Name = NameInferer.InferApplicationName(file)
};
// BE CAREFUL modifying this code. Avoid proliferating MSBuild types

27
src/Microsoft.Tye.Core/ConfigModel/NameInferer.cs

@ -0,0 +1,27 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.IO;
namespace Microsoft.Tye.ConfigModel
{
internal static class NameInferer
{
public static string? InferApplicationName(FileInfo fileInfo)
{
if (fileInfo == null)
{
return null;
}
var extension = fileInfo.Extension;
if (extension == ".sln" || extension == ".csproj" || extension == ".fsproj")
{
return Path.GetFileNameWithoutExtension(fileInfo.Name).ToLowerInvariant();
}
return fileInfo.Directory.Parent.Name.ToLowerInvariant();
}
}
}

1
src/Microsoft.Tye.Core/Serialization/YamlParser.cs

@ -54,6 +54,7 @@ namespace Tye.Serialization
ConfigApplicationParser.HandleConfigApplication((YamlMappingNode)node, app);
app.Source = _fileInfo!;
app.Name ??= NameInferer.InferApplicationName(_fileInfo!);
// TODO confirm if these are ever null.
foreach (var service in app.Services)

4
src/tye/InitHost.cs

@ -64,7 +64,6 @@ services:
if (extension == ".sln" || extension == ".csproj" || extension == ".fsproj")
{
// If the input file is a project or solution then use that as the name
application.Name = Path.GetFileNameWithoutExtension(path.Name).ToLowerInvariant();
application.Extensions = null!;
application.Ingress = null!;
@ -81,9 +80,6 @@ services:
}
else
{
// If the input file is a yaml, then use the directory name.
application.Name = path.Directory.Name.ToLowerInvariant();
// If the input file is a yaml, then replace it.
outputFilePath = path.FullName;
}

12
src/tye/UndeployHost.cs

@ -27,7 +27,7 @@ namespace Microsoft.Tye
// We don't need to know anything about the services, just the application name.
var application = ConfigFactory.FromFile(path);
if (!String.IsNullOrEmpty(@namespace))
if (!string.IsNullOrEmpty(@namespace))
{
application.Namespace = @namespace;
}
@ -72,12 +72,14 @@ namespace Microsoft.Tye
// - handcrafting requests to delete each resource
var resources = new List<Resource>();
var applicationName = application.Name;
try
{
output.WriteDebugLine("Querying services");
var response = await kubernetes.ListNamespacedServiceWithHttpMessagesAsync(
config.Namespace,
labelSelector: $"app.kubernetes.io/part-of={application.Name}");
labelSelector: $"app.kubernetes.io/part-of={applicationName}");
foreach (var resource in response.Body.Items)
{
@ -99,7 +101,7 @@ namespace Microsoft.Tye
output.WriteDebugLine("Querying deployments");
var response = await kubernetes.ListNamespacedDeploymentWithHttpMessagesAsync(
config.Namespace,
labelSelector: $"app.kubernetes.io/part-of={application.Name}");
labelSelector: $"app.kubernetes.io/part-of={applicationName}");
foreach (var resource in response.Body.Items)
{
@ -121,7 +123,7 @@ namespace Microsoft.Tye
output.WriteDebugLine("Querying secrets");
var response = await kubernetes.ListNamespacedSecretWithHttpMessagesAsync(
config.Namespace,
labelSelector: $"app.kubernetes.io/part-of={application.Name}");
labelSelector: $"app.kubernetes.io/part-of={applicationName}");
foreach (var resource in response.Body.Items)
{
@ -144,7 +146,7 @@ namespace Microsoft.Tye
output.WriteDebugLine("Querying ingresses");
var response = await kubernetes.ListNamespacedIngressWithHttpMessagesAsync(
config.Namespace,
labelSelector: $"app.kubernetes.io/part-of={application.Name}");
labelSelector: $"app.kubernetes.io/part-of={applicationName}");
foreach (var resource in response.Body.Items)
{

Loading…
Cancel
Save