Skip to content
This repository has been archived by the owner on Nov 20, 2023. It is now read-only.

Commit

Permalink
Fix undeploy (#537)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotalik authored Jun 9, 2020
1 parent 0ebb615 commit 7899373
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Microsoft.Tye.Core/ApplicationFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static async Task<ApplicationBuilder> CreateAsync(OutputContext output, F
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>()));
Expand Down
2 changes: 2 additions & 0 deletions src/Microsoft.Tye.Core/ConfigModel/ConfigFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ private static ConfigApplication FromProject(FileInfo file)
var application = new ConfigApplication()
{
Source = file,
Name = NameInferer.InferApplicationName(file)
};

var service = new ConfigService()
Expand All @@ -57,6 +58,7 @@ private static ConfigApplication FromSolution(FileInfo file)
var application = new ConfigApplication()
{
Source = file,
Name = NameInferer.InferApplicationName(file)
};

// BE CAREFUL modifying this code. Avoid proliferating MSBuild types
Expand Down
27 changes: 27 additions & 0 deletions src/Microsoft.Tye.Core/ConfigModel/NameInferer.cs
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions src/Microsoft.Tye.Core/Serialization/YamlParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public ConfigApplication ParseConfigApplication()
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)
Expand Down
4 changes: 0 additions & 4 deletions src/tye/InitHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public static (string, string) CreateTyeFileContent(FileInfo? path, bool force)
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!;

Expand All @@ -81,9 +80,6 @@ public static (string, string) CreateTyeFileContent(FileInfo? path, bool force)
}
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;
}
Expand Down
12 changes: 7 additions & 5 deletions src/tye/UndeployHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static async Task UndeployAsync(IConsole console, FileInfo path, Verbosit

// 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;
}
Expand Down Expand Up @@ -72,12 +72,14 @@ public static async Task ExecuteUndeployAsync(OutputContext output, ConfigApplic
// - 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)
{
Expand All @@ -99,7 +101,7 @@ public static async Task ExecuteUndeployAsync(OutputContext output, ConfigApplic
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)
{
Expand All @@ -121,7 +123,7 @@ public static async Task ExecuteUndeployAsync(OutputContext output, ConfigApplic
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)
{
Expand All @@ -144,7 +146,7 @@ public static async Task ExecuteUndeployAsync(OutputContext output, ConfigApplic
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)
{
Expand Down

0 comments on commit 7899373

Please sign in to comment.