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

Commit 7899373

Browse files
authored
Fix undeploy (#537)
1 parent 0ebb615 commit 7899373

File tree

6 files changed

+38
-10
lines changed

6 files changed

+38
-10
lines changed

src/Microsoft.Tye.Core/ApplicationFactory.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static async Task<ApplicationBuilder> CreateAsync(OutputContext output, F
2828
var rootConfig = ConfigFactory.FromFile(source);
2929
rootConfig.Validate();
3030

31-
var root = new ApplicationBuilder(source, rootConfig.Name ?? source.Directory.Name.ToLowerInvariant());
31+
var root = new ApplicationBuilder(source, rootConfig.Name!);
3232
root.Namespace = rootConfig.Namespace;
3333

3434
queue.Enqueue((rootConfig, new HashSet<string>()));

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

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ private static ConfigApplication FromProject(FileInfo file)
3939
var application = new ConfigApplication()
4040
{
4141
Source = file,
42+
Name = NameInferer.InferApplicationName(file)
4243
};
4344

4445
var service = new ConfigService()
@@ -57,6 +58,7 @@ private static ConfigApplication FromSolution(FileInfo file)
5758
var application = new ConfigApplication()
5859
{
5960
Source = file,
61+
Name = NameInferer.InferApplicationName(file)
6062
};
6163

6264
// BE CAREFUL modifying this code. Avoid proliferating MSBuild types
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.IO;
6+
7+
namespace Microsoft.Tye.ConfigModel
8+
{
9+
internal static class NameInferer
10+
{
11+
public static string? InferApplicationName(FileInfo fileInfo)
12+
{
13+
if (fileInfo == null)
14+
{
15+
return null;
16+
}
17+
18+
var extension = fileInfo.Extension;
19+
if (extension == ".sln" || extension == ".csproj" || extension == ".fsproj")
20+
{
21+
return Path.GetFileNameWithoutExtension(fileInfo.Name).ToLowerInvariant();
22+
}
23+
24+
return fileInfo.Directory.Parent.Name.ToLowerInvariant();
25+
}
26+
}
27+
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public ConfigApplication ParseConfigApplication()
5454
ConfigApplicationParser.HandleConfigApplication((YamlMappingNode)node, app);
5555

5656
app.Source = _fileInfo!;
57+
app.Name ??= NameInferer.InferApplicationName(_fileInfo!);
5758

5859
// TODO confirm if these are ever null.
5960
foreach (var service in app.Services)

src/tye/InitHost.cs

-4
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ public static (string, string) CreateTyeFileContent(FileInfo? path, bool force)
6464
if (extension == ".sln" || extension == ".csproj" || extension == ".fsproj")
6565
{
6666
// If the input file is a project or solution then use that as the name
67-
application.Name = Path.GetFileNameWithoutExtension(path.Name).ToLowerInvariant();
6867
application.Extensions = null!;
6968
application.Ingress = null!;
7069

@@ -81,9 +80,6 @@ public static (string, string) CreateTyeFileContent(FileInfo? path, bool force)
8180
}
8281
else
8382
{
84-
// If the input file is a yaml, then use the directory name.
85-
application.Name = path.Directory.Name.ToLowerInvariant();
86-
8783
// If the input file is a yaml, then replace it.
8884
outputFilePath = path.FullName;
8985
}

src/tye/UndeployHost.cs

+7-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static async Task UndeployAsync(IConsole console, FileInfo path, Verbosit
2727

2828
// We don't need to know anything about the services, just the application name.
2929
var application = ConfigFactory.FromFile(path);
30-
if (!String.IsNullOrEmpty(@namespace))
30+
if (!string.IsNullOrEmpty(@namespace))
3131
{
3232
application.Namespace = @namespace;
3333
}
@@ -72,12 +72,14 @@ public static async Task ExecuteUndeployAsync(OutputContext output, ConfigApplic
7272
// - handcrafting requests to delete each resource
7373
var resources = new List<Resource>();
7474

75+
var applicationName = application.Name;
76+
7577
try
7678
{
7779
output.WriteDebugLine("Querying services");
7880
var response = await kubernetes.ListNamespacedServiceWithHttpMessagesAsync(
7981
config.Namespace,
80-
labelSelector: $"app.kubernetes.io/part-of={application.Name}");
82+
labelSelector: $"app.kubernetes.io/part-of={applicationName}");
8183

8284
foreach (var resource in response.Body.Items)
8385
{
@@ -99,7 +101,7 @@ public static async Task ExecuteUndeployAsync(OutputContext output, ConfigApplic
99101
output.WriteDebugLine("Querying deployments");
100102
var response = await kubernetes.ListNamespacedDeploymentWithHttpMessagesAsync(
101103
config.Namespace,
102-
labelSelector: $"app.kubernetes.io/part-of={application.Name}");
104+
labelSelector: $"app.kubernetes.io/part-of={applicationName}");
103105

104106
foreach (var resource in response.Body.Items)
105107
{
@@ -121,7 +123,7 @@ public static async Task ExecuteUndeployAsync(OutputContext output, ConfigApplic
121123
output.WriteDebugLine("Querying secrets");
122124
var response = await kubernetes.ListNamespacedSecretWithHttpMessagesAsync(
123125
config.Namespace,
124-
labelSelector: $"app.kubernetes.io/part-of={application.Name}");
126+
labelSelector: $"app.kubernetes.io/part-of={applicationName}");
125127

126128
foreach (var resource in response.Body.Items)
127129
{
@@ -144,7 +146,7 @@ public static async Task ExecuteUndeployAsync(OutputContext output, ConfigApplic
144146
output.WriteDebugLine("Querying ingresses");
145147
var response = await kubernetes.ListNamespacedIngressWithHttpMessagesAsync(
146148
config.Namespace,
147-
labelSelector: $"app.kubernetes.io/part-of={application.Name}");
149+
labelSelector: $"app.kubernetes.io/part-of={applicationName}");
148150

149151
foreach (var resource in response.Body.Items)
150152
{

0 commit comments

Comments
 (0)