Skip to content

Commit 40b0034

Browse files
authored
Installer optimizations (#13)
1 parent 1f0e88d commit 40b0034

22 files changed

+120
-97
lines changed

K8sOperator.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleOperator", "examples\
3434
EndProject
3535
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "K8sOperator.NET.Generators", "src\K8sOperator.NET.Generators\K8sOperator.NET.Generators.csproj", "{183BE367-0544-4AD1-B741-2BA2F186BC0E}"
3636
EndProject
37+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "K8sOperator.NET.Generators.Tests", "test\K8sOperator.NET.Generators.Tests\K8sOperator.NET.Generators.Tests.csproj", "{D07BFDEA-0E46-4822-9F38-9581425FD93F}"
38+
EndProject
3739
Global
3840
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3941
Debug|Any CPU = Debug|Any CPU
@@ -56,6 +58,10 @@ Global
5658
{183BE367-0544-4AD1-B741-2BA2F186BC0E}.Debug|Any CPU.Build.0 = Debug|Any CPU
5759
{183BE367-0544-4AD1-B741-2BA2F186BC0E}.Release|Any CPU.ActiveCfg = Release|Any CPU
5860
{183BE367-0544-4AD1-B741-2BA2F186BC0E}.Release|Any CPU.Build.0 = Release|Any CPU
61+
{D07BFDEA-0E46-4822-9F38-9581425FD93F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
62+
{D07BFDEA-0E46-4822-9F38-9581425FD93F}.Debug|Any CPU.Build.0 = Debug|Any CPU
63+
{D07BFDEA-0E46-4822-9F38-9581425FD93F}.Release|Any CPU.ActiveCfg = Release|Any CPU
64+
{D07BFDEA-0E46-4822-9F38-9581425FD93F}.Release|Any CPU.Build.0 = Release|Any CPU
5965
EndGlobalSection
6066
GlobalSection(SolutionProperties) = preSolution
6167
HideSolutionNode = FALSE
@@ -67,6 +73,7 @@ Global
6773
{160DFED1-DD63-412C-9D60-84D965626DD9} = {898CC489-C84A-49BD-9D77-3CEA1F6A7180}
6874
{B7588B10-BDD2-4622-BB16-18EFFBE7BE25} = {ED5FF81E-F3EA-4BEF-9B72-31A24F9386E3}
6975
{183BE367-0544-4AD1-B741-2BA2F186BC0E} = {898CC489-C84A-49BD-9D77-3CEA1F6A7180}
76+
{D07BFDEA-0E46-4822-9F38-9581425FD93F} = {9320CC2F-6BB6-4B29-B625-EB427EE87891}
7077
EndGlobalSection
7178
GlobalSection(ExtensibilityGlobals) = postSolution
7279
SolutionGuid = {49DE7562-1920-49AD-A220-E10302CEC632}

examples/SimpleOperator/Program.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using K8sOperator.NET;
22
using K8sOperator.NET.Extensions;
3+
using K8sOperator.NET.Generators;
34
using SimpleOperator.Projects;
45

56

@@ -13,4 +14,10 @@
1314

1415
var app = builder.Build();
1516

17+
var writer = new StringWriter();
18+
19+
await new Install(app, writer).RunAsync();
20+
21+
Console.WriteLine(writer.ToString());
22+
1623
await app.RunAsync();

examples/SimpleOperator/Properties/launchSettings.json

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,27 @@
33
"Operator": {
44
"commandName": "Project",
55
"commandLineArgs": "--operator",
6-
"launchBrowser": true,
76
"environmentVariables": {
87
"ASPNETCORE_ENVIRONMENT": "Development"
98
},
10-
"dotnetRunMessages": true,
11-
"applicationUrl": "http://localhost:5276"
9+
"dotnetRunMessages": true
1210
},
13-
"install": {
11+
"Install": {
1412
"commandName": "Project",
1513
"commandLineArgs": "install=true --export true",
16-
"launchBrowser": true,
1714
"environmentVariables": {
1815
"ASPNETCORE_ENVIRONMENT": "Development"
1916
},
20-
"dotnetRunMessages": true,
21-
"applicationUrl": "http://localhost:5276"
17+
"dotnetRunMessages": true
2218
},
2319
"CLI": {
2420
"commandName": "Project",
2521
"commandLineArgs": "",
26-
"launchBrowser": true,
2722
"environmentVariables": {
2823
"ASPNETCORE_ENVIRONMENT": "Development"
2924
},
30-
"dotnetRunMessages": true,
31-
"applicationUrl": "http://localhost:5276"
32-
},
33-
"IIS Express": {
34-
"commandName": "IISExpress",
35-
"launchBrowser": true,
36-
"environmentVariables": {
37-
"ASPNETCORE_ENVIRONMENT": "Development"
38-
}
25+
"dotnetRunMessages": true
3926
}
4027
},
41-
"$schema": "http://json.schemastore.org/launchsettings.json",
42-
"iisSettings": {
43-
"windowsAuthentication": false,
44-
"anonymousAuthentication": true,
45-
"iisExpress": {
46-
"applicationUrl": "http://localhost:36443",
47-
"sslPort": 0
48-
}
49-
}
28+
"$schema": "http://json.schemastore.org/launchsettings.json"
5029
}

src/K8sOperator.NET.Generators/Builders/ClusterRoleBindingBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using k8s;
22
using k8s.Models;
33

4-
namespace K8sOperator.NET.Generator.Builders;
4+
namespace K8sOperator.NET.Generators.Builders;
55

6-
internal class ClusterRoleBindingBuilder : KubernetesObjectBuilderWithMetaData<V1ClusterRoleBinding>
6+
internal class ClusterRoleBindingBuilder : KubernetesObjectBuilderWithMetaData<V1ClusterRoleBinding>
77
{
88
public override V1ClusterRoleBinding Build()
99
{

src/K8sOperator.NET.Generators/Builders/ClusterRoleBindingBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using k8s.Models;
22

3-
namespace K8sOperator.NET.Generator.Builders;
3+
namespace K8sOperator.NET.Generators.Builders;
44

55
/// <summary>
66
/// Provides extension methods for building Kubernetes ClusterRoleBindings.

src/K8sOperator.NET.Generators/Builders/ClusterRoleBuilder.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
using k8s;
22
using k8s.Models;
33

4-
namespace K8sOperator.NET.Generator.Builders;
4+
namespace K8sOperator.NET.Generators.Builders;
55

6-
internal class ClusterRoleBuilder : KubernetesObjectBuilderWithMetaData<V1ClusterRole> {
6+
internal class ClusterRoleBuilder : KubernetesObjectBuilderWithMetaData<V1ClusterRole>
7+
{
78
public override V1ClusterRole Build()
89
{
910
var role = base.Build();

src/K8sOperator.NET.Generators/Builders/ClusterRoleBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using k8s.Models;
22

3-
namespace K8sOperator.NET.Generator.Builders;
3+
namespace K8sOperator.NET.Generators.Builders;
44

55
/// <summary>
66
/// Provides extension methods for building Kubernetes ClusterRoles.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using k8s.Models;
22

3-
namespace K8sOperator.NET.Generator.Builders;
3+
namespace K8sOperator.NET.Generators.Builders;
44

55
internal class ContainerBuilder : KubernetesObjectBuilder<V1Container>
66
{
7-
7+
88
}

src/K8sOperator.NET.Generators/Builders/CustomResourceDefinitionBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using k8s;
22
using k8s.Models;
33

4-
namespace K8sOperator.NET.Generator.Builders;
4+
namespace K8sOperator.NET.Generators.Builders;
55

66
internal class CustomResourceDefinitionBuilder : KubernetesObjectBuilderWithMetaData<V1CustomResourceDefinition>
77
{

src/K8sOperator.NET.Generators/Builders/CustomResourceDefinitionBuilderExtensions.cs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
using k8s;
22
using k8s.Models;
3+
using K8sOperator.NET.Generators;
34
using K8sOperator.NET.Helpers;
45
using K8sOperator.NET.Metadata;
56
using K8sOperator.NET.Models;
67
using System.Reflection;
78

8-
namespace K8sOperator.NET.Generator.Builders;
9+
namespace K8sOperator.NET.Generators.Builders;
910

1011
/// <summary>
1112
/// Provides extension methods for building Kubernetes CustomResourceDefinitions.
1213
/// </summary>
13-
public static class CustomResourceDefinitionBuilderExtensions {
14+
public static class CustomResourceDefinitionBuilderExtensions
15+
{
1416

1517
/// <summary>
1618
/// Configures the spec section of the CustomResourceDefinition.
@@ -52,7 +54,7 @@ public static TBuilder WithGroup<TBuilder>(this TBuilder builder, string group)
5254
/// <param name="shortnames">Optional short names for the resource.</param>
5355
/// <param name="categories">Optional categories for the resource.</param>
5456
/// <returns>The configured builder.</returns>
55-
public static TBuilder WithNames<TBuilder>(this TBuilder builder,
57+
public static TBuilder WithNames<TBuilder>(this TBuilder builder,
5658
string kind,
5759
string kindList,
5860
string plural,
@@ -102,14 +104,15 @@ public static TBuilder WithVersion<TBuilder>(this TBuilder builder, string name,
102104
b.Add(x => x.Name = name);
103105
schema(b);
104106

105-
builder.Add(x => {
107+
builder.Add(x =>
108+
{
106109

107110
x.Versions ??= [];
108-
if(!x.Versions.Any(x=>x.Name == name))
111+
if (!x.Versions.Any(x => x.Name == name))
109112
{
110113
x.Versions.Add(b.Build());
111114
}
112-
115+
113116
});
114117
return builder;
115118
}
@@ -160,12 +163,14 @@ public static TBuilder WithSchemaForType<TBuilder>(this TBuilder builder, Type r
160163
var status = resourceType.GetProperty("Status")!;
161164
var spec = resourceType.GetProperty("Spec")!;
162165

163-
s.WithProperty("status", sub => {
166+
s.WithProperty("status", sub =>
167+
{
164168
sub.ObjectType(status.PropertyType);
165169
});
166170
s.WithProperty("spec", sub => sub.ObjectType(spec.PropertyType));
167171

168-
builder.Add(x => {
172+
builder.Add(x =>
173+
{
169174
b.Add(x => x.OpenAPIV3Schema = s.Build());
170175
x.Schema = b.Build();
171176
});
@@ -185,9 +190,10 @@ public static TBuilder WithSchema<TBuilder>(this TBuilder builder, Action<IKuber
185190
var b = new KubernetesObjectBuilder<V1CustomResourceValidation>();
186191
var s = new KubernetesObjectBuilder<V1JSONSchemaProps>();
187192
schema(s);
188-
189-
builder.Add(x =>{
190-
b.Add(x=>x.OpenAPIV3Schema = s.Build());
193+
194+
builder.Add(x =>
195+
{
196+
b.Add(x => x.OpenAPIV3Schema = s.Build());
191197
x.Schema = b.Build();
192198
});
193199
return builder;
@@ -270,7 +276,8 @@ public static TBuilder WithProperty<TBuilder>(this TBuilder builder, string name
270276
var p = new KubernetesObjectBuilder<V1JSONSchemaProps>();
271277
schema(p);
272278

273-
builder.Add(x => {
279+
builder.Add(x =>
280+
{
274281
x.Properties ??= new Dictionary<string, V1JSONSchemaProps>();
275282
x.Properties.Add($"{name[..1].ToLowerInvariant()}{name[1..]}", p.Build());
276283
});
@@ -329,18 +336,18 @@ private static TBuilder ObjectType<TBuilder>(this TBuilder builder, Type type)
329336

330337
builder.OfType("object");
331338
builder.IsNullable(false);
332-
foreach(var prop in type.GetProperties())
339+
foreach (var prop in type.GetProperties())
333340
{
334341
builder.WithProperty(prop.Name, s => s.OfType(prop.PropertyType));
335342
}
336343

337344
builder.WithRequired(type.GetProperties()
338345
.Where(x => !x.IsNullable())
339346
.Select(x => x.Name).ToList() switch
340-
{
341-
{ Count: > 0 } p => p,
342-
_ => null,
343-
});
347+
{
348+
{ Count: > 0 } p => p,
349+
_ => null,
350+
});
344351

345352
return builder;
346353
}
@@ -356,8 +363,8 @@ private static TBuilder EnumType<TBuilder>(this TBuilder builder, Type type)
356363
return builder;
357364
}
358365

359-
360366

361-
367+
368+
362369
}
363370

0 commit comments

Comments
 (0)