Skip to content

Commit c016a27

Browse files
authored
refactor(generator): change generators from ISourceGenerator to IIncrementalGenerator (#1151)
- implemented IIncrementalGenerator - added Caching - fixed code warnings this will fix the issues in #1144 and #1147
1 parent e6d3922 commit c016a27

39 files changed

Lines changed: 507 additions & 435 deletions

examples/ConversionWebhookOperator/Program.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,28 @@
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
44

5+
#if DEBUG
56
using System.Net;
7+
#endif
68

79
using KubeOps.Operator;
10+
11+
#if DEBUG
812
using KubeOps.Operator.Web.Builder;
913
using KubeOps.Operator.Web.Certificates;
14+
#endif
1015

1116
var builder = WebApplication.CreateBuilder(args);
17+
18+
#if !DEBUG
19+
builder.Services
20+
.AddKubernetesOperator()
21+
.RegisterComponents();
22+
#else
1223
var opBuilder = builder.Services
1324
.AddKubernetesOperator()
1425
.RegisterComponents();
26+
#endif
1527

1628
#if DEBUG
1729
const string ip = "192.168.1.100";

examples/ConversionWebhookOperator/Webhooks/TestConversionWebhook.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public sealed class TestConversionWebhook : ConversionWebhook<V3TestEntity>
1919
new V1ToV3(), new V2ToV3(),
2020
};
2121

22-
private class V1ToV3 : IEntityConverter<V1TestEntity, V3TestEntity>
22+
private sealed class V1ToV3 : IEntityConverter<V1TestEntity, V3TestEntity>
2323
{
2424
public V3TestEntity Convert(V1TestEntity from)
2525
{
@@ -38,7 +38,7 @@ public V1TestEntity Revert(V3TestEntity to)
3838
}
3939
}
4040

41-
private class V2ToV3 : IEntityConverter<V2TestEntity, V3TestEntity>
41+
private sealed class V2ToV3 : IEntityConverter<V2TestEntity, V3TestEntity>
4242
{
4343
public V3TestEntity Convert(V2TestEntity from)
4444
{

examples/Operator/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#if DEBUG
66
using KubeOps.Abstractions.Crds;
77
#endif
8+
89
using KubeOps.Operator;
910

1011
using Microsoft.Extensions.Hosting;

examples/WebhookOperator/Program.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,28 @@
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
44

5+
#if DEBUG
56
using System.Net;
7+
#endif
68

79
using KubeOps.Operator;
10+
11+
#if DEBUG
812
using KubeOps.Operator.Web.Builder;
913
using KubeOps.Operator.Web.Certificates;
14+
#endif
1015

1116
var builder = WebApplication.CreateBuilder(args);
17+
18+
#if !DEBUG
19+
builder.Services
20+
.AddKubernetesOperator()
21+
.RegisterComponents();
22+
#else
1223
var opBuilder = builder.Services
1324
.AddKubernetesOperator()
1425
.RegisterComponents();
26+
#endif
1527

1628
#if DEBUG
1729
const string ip = "192.168.1.100";

renovate.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
"enabled": false
1818
},
1919
{
20-
"matchManagers": ["dotnet"],
20+
"matchManagers": ["nuget"],
2121
"matchDepNames": ["Microsoft.CodeAnalysis.CSharp"],
22-
"matchFileNames": ["KubeOps.Generator.csproj"],
22+
"matchFileNames": ["**/KubeOps.Generator.csproj"],
2323
"enabled": false
2424
},
2525
{

src/KubeOps.Abstractions/Entities/IEntityFieldSelector{TEntity}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace KubeOps.Abstractions.Entities;
99

1010
// This is the same pattern used by Microsoft on ILogger<T>.
11-
// An alternative would be to use a KeyedSingleton when registering this however that's only valid from .NET 8 and above.
11+
// An alternative would be to use a KeyedSingleton when registering this; however, that's only valid from .NET 8 and above.
1212
// Other methods are far less elegant
1313
#pragma warning disable S2326
1414
public interface IEntityFieldSelector<TEntity>

src/KubeOps.Abstractions/Entities/IEntityLabelSelector{TEntity}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace KubeOps.Abstractions.Entities;
99

1010
// This is the same pattern used by Microsoft on ILogger<T>.
11-
// An alternative would be to use a KeyedSingleton when registering this however that's only valid from .NET 8 and above.
11+
// An alternative would be to use a KeyedSingleton when registering this; however, that's only valid from .NET 8 and above.
1212
// Other methods are far less elegant
1313
#pragma warning disable S2326
1414
public interface IEntityLabelSelector<TEntity>

src/KubeOps.Aspire.Hosting/KubeOpsHostingExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ private static void ConfigureOperatorPod(
377377
string name,
378378
KubeOpsKubernetesManifestOptions options)
379379
{
380-
var podSpec = kubernetes.Workload?.PodTemplate?.Spec;
380+
var podSpec = kubernetes.Workload?.PodTemplate.Spec;
381381
if (podSpec is null)
382382
{
383383
return;
@@ -626,7 +626,7 @@ private static void MergeKubeOpsDeployment(KubernetesResource kubernetes, JsonOb
626626
}
627627

628628
var generatedPodSpec = generatedSpec["template"]?["spec"] as JsonObject;
629-
var podSpec = kubernetes.Workload?.PodTemplate?.Spec;
629+
var podSpec = kubernetes.Workload?.PodTemplate.Spec;
630630
if (generatedPodSpec is null || podSpec is null)
631631
{
632632
return;

src/KubeOps.Aspire/KubeOpsServiceDefaultsExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
using KubeOps.Abstractions.Builder;
66

7-
using Microsoft.Extensions.Configuration;
87
using Microsoft.Extensions.DependencyInjection;
98
using Microsoft.Extensions.Diagnostics.HealthChecks;
109
using Microsoft.Extensions.Hosting;

src/KubeOps.Cli/Commands/Generator/Generate.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System.CommandLine;
6-
using System.CommandLine.Help;
76

87
namespace KubeOps.Cli.Commands.Generator;
98

0 commit comments

Comments
 (0)