Skip to content

Commit a95278d

Browse files
authored
feat(client): Use true generics again (#640)
This readds all methods in the kubernetes client that were annotated with <TEntity> in their methods. This allows true generic calls.
1 parent 881111b commit a95278d

File tree

42 files changed

+999
-1043
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+999
-1043
lines changed

examples/Operator/Controller/V1TestEntityController.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using KubeOps.Abstractions.Events;
33
using KubeOps.Abstractions.Queue;
44
using KubeOps.Abstractions.Rbac;
5-
using KubeOps.KubernetesClient;
65

76
using Microsoft.Extensions.Logging;
87

@@ -14,18 +13,15 @@ namespace Operator.Controller;
1413
public class V1TestEntityController : IEntityController<V1TestEntity>
1514
{
1615
private readonly ILogger<V1TestEntityController> _logger;
17-
private readonly IKubernetesClient<V1TestEntity> _client;
1816
private readonly EntityRequeue<V1TestEntity> _requeue;
1917
private readonly EventPublisher _eventPublisher;
2018

2119
public V1TestEntityController(
2220
ILogger<V1TestEntityController> logger,
23-
IKubernetesClient<V1TestEntity> client,
2421
EntityRequeue<V1TestEntity> requeue,
2522
EventPublisher eventPublisher)
2623
{
2724
_logger = logger;
28-
_client = client;
2925
_requeue = requeue;
3026
_eventPublisher = eventPublisher;
3127
}

src/Directory.Build.props

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
</PropertyGroup>
2525

2626
<ItemGroup>
27-
<None Include="README.md" Pack="true" PackagePath="\"/>
28-
<None Include="$(MSBuildThisFileDirectory)\..\LICENSE" Pack="true" PackagePath="\"/>
27+
<None Include="README.md" Pack="true" PackagePath="\" />
28+
<None Include="$(MSBuildThisFileDirectory)\..\LICENSE" Pack="true" PackagePath="\" />
2929
<None Include="$(MSBuildThisFileDirectory)\..\res\icon.png">
3030
<Pack>true</Pack>
3131
<PackagePath>\</PackagePath>
@@ -35,16 +35,16 @@
3535

3636
<ItemGroup>
3737
<PackageReference
38-
Include="StyleCop.Analyzers"
39-
Version="1.2.0-beta.507"
40-
PrivateAssets="all"
41-
Condition="$(MSBuildProjectExtension) == '.csproj'"/>
38+
Include="StyleCop.Analyzers"
39+
Version="1.2.0-beta.507"
40+
PrivateAssets="all"
41+
Condition="$(MSBuildProjectExtension) == '.csproj'" />
4242
<PackageReference
43-
Include="SonarAnalyzer.CSharp"
44-
Version="9.12.0.78982"
45-
PrivateAssets="all"
46-
Condition="$(MSBuildProjectExtension) == '.csproj'"/>
47-
<PackageReference Include="Roslynator.Analyzers" Version="4.5.0" PrivateAssets="All"/>
43+
Include="SonarAnalyzer.CSharp"
44+
Version="9.12.0.78982"
45+
PrivateAssets="all"
46+
Condition="$(MSBuildProjectExtension) == '.csproj'" />
47+
<PackageReference Include="Roslynator.Analyzers" Version="4.5.0" PrivateAssets="All" />
4848
</ItemGroup>
4949

5050
<ItemGroup>
@@ -56,4 +56,4 @@
5656
<_Parameter1>DynamicProxyGenAssembly2</_Parameter1>
5757
</AssemblyAttribute>
5858
</ItemGroup>
59-
</Project>
59+
</Project>

src/KubeOps.Abstractions/Builder/IOperatorBuilder.cs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using k8s.Models;
33

44
using KubeOps.Abstractions.Controller;
5-
using KubeOps.Abstractions.Entities;
65
using KubeOps.Abstractions.Finalizer;
76

87
using Microsoft.Extensions.DependencyInjection;
@@ -19,34 +18,6 @@ public interface IOperatorBuilder
1918
/// </summary>
2019
IServiceCollection Services { get; }
2120

22-
/// <summary>
23-
/// <para>
24-
/// Register an entity Kubernetes client within the operator.
25-
/// This is used to register IKubernetesClient{TEntity} for the entity.
26-
/// An alternative way to create any Kubernetes client is to use the
27-
/// KubernetesClientFactory or instantiate the client by yourself.
28-
/// </para>
29-
/// </summary>
30-
/// <param name="metadata">The metadata of the entity.</param>
31-
/// <typeparam name="TEntity">The type of the entity.</typeparam>
32-
/// <returns>The builder for chaining.</returns>
33-
IOperatorBuilder AddEntityClient<TEntity>(EntityMetadata metadata)
34-
where TEntity : IKubernetesObject<V1ObjectMeta>;
35-
36-
/// <summary>
37-
/// <para>
38-
/// Register an entity Kubernetes client within the operator.
39-
/// This is used to register IKubernetesClient{TEntity} for the entity.
40-
/// An alternative way to create any Kubernetes client is to use the
41-
/// KubernetesClientFactory or instantiate the client by yourself.
42-
/// This method uses reflection to get the metadata from the entity.
43-
/// </para>
44-
/// </summary>
45-
/// <typeparam name="TEntity">The type of the entity.</typeparam>
46-
/// <returns>The builder for chaining.</returns>
47-
IOperatorBuilder AddEntityClient<TEntity>()
48-
where TEntity : IKubernetesObject<V1ObjectMeta>;
49-
5021
/// <summary>
5122
/// Add a controller implementation for a specific entity to the operator.
5223
/// The metadata for the entity must be added as well.

src/KubeOps.Abstractions/Builder/OperatorSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public sealed class OperatorSettings
4242
/// Defaults to `false`.
4343
/// </para>
4444
/// </summary>
45-
public bool EnableLeaderElection { get; set; }
45+
public bool EnableLeaderElection { get; set; } = false;
4646

4747
/// <summary>
4848
/// Defines how long one lease is valid for any leader.

src/KubeOps.Cli/Commands/Utilities/Version.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ public static Command Command
1212
{
1313
get
1414
{
15-
var cmd = new Command("api-version", "Prints the actual server version of the connected kubernetes cluster.");
15+
var cmd = new Command(
16+
"api-version",
17+
"Prints the actual server version of the connected kubernetes cluster.");
1618
cmd.AddAlias("av");
1719
cmd.SetHandler(() =>
1820
Handler(AnsiConsole.Console, new Kubernetes(KubernetesClientConfiguration.BuildDefaultConfig())));

src/KubeOps.Cli/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
.UseParseErrorReporting(ExitCodes.UsageError)
2020
.UseExceptionHandler((ex, ctx) =>
2121
{
22-
AnsiConsole.MarkupLineInterpolated($"[red]An error occurred whiled executing {ctx.ParseResult.CommandResult.Command}[/]");
22+
AnsiConsole.MarkupLineInterpolated(
23+
$"[red]An error occurred whiled executing {ctx.ParseResult.CommandResult.Command}[/]");
2324
AnsiConsole.MarkupLineInterpolated($"[red]{ex.Message}[/]");
2425
ctx.ExitCode = ExitCodes.Error;
2526
})

src/KubeOps.Generator/Generators/EntityDefinitionGenerator.cs

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -78,41 +78,7 @@ public void Execute(GeneratorExecutionContext context)
7878
TokenList(
7979
Token(SyntaxKind.PublicKeyword),
8080
Token(SyntaxKind.StaticKeyword),
81-
Token(SyntaxKind.ReadOnlyKeyword))))))
82-
.AddMembers(MethodDeclaration(IdentifierName("IOperatorBuilder"), "RegisterEntities")
83-
.WithModifiers(
84-
TokenList(Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.StaticKeyword)))
85-
.WithParameterList(ParameterList(
86-
SingletonSeparatedList(
87-
Parameter(
88-
Identifier("builder"))
89-
.WithModifiers(
90-
TokenList(
91-
Token(SyntaxKind.ThisKeyword)))
92-
.WithType(
93-
IdentifierName("IOperatorBuilder")))))
94-
.WithBody(Block(
95-
receiver.Entities
96-
.Select(e => ExpressionStatement(
97-
InvocationExpression(
98-
MemberAccessExpression(
99-
SyntaxKind.SimpleMemberAccessExpression,
100-
IdentifierName("builder"),
101-
GenericName(Identifier("AddEntityClient"))
102-
.WithTypeArgumentList(
103-
TypeArgumentList(
104-
SingletonSeparatedList<TypeSyntax>(
105-
IdentifierName(context.Compilation
106-
.GetSemanticModel(e.Class.SyntaxTree)
107-
.GetDeclaredSymbol(e.Class)!
108-
.ToDisplayString(SymbolDisplayFormat
109-
.FullyQualifiedFormat)))))))
110-
.WithArgumentList(
111-
ArgumentList(
112-
SingletonSeparatedList(
113-
Argument(
114-
IdentifierName(e.Class.Identifier)))))))
115-
.Append<StatementSyntax>(ReturnStatement(IdentifierName("builder"))))))))
81+
Token(SyntaxKind.ReadOnlyKeyword))))))))
11682
.NormalizeWhitespace();
11783

11884
context.AddSource(

src/KubeOps.Generator/Generators/OperatorBuilderGenerator.cs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,16 @@ public void Execute(GeneratorExecutionContext context)
4040
.WithBody(Block(
4141
ExpressionStatement(
4242
InvocationExpression(
43-
MemberAccessExpression(
44-
SyntaxKind.SimpleMemberAccessExpression,
45-
IdentifierName("builder"),
46-
IdentifierName("RegisterEntities")))),
43+
MemberAccessExpression(
44+
SyntaxKind.SimpleMemberAccessExpression,
45+
IdentifierName("builder"),
46+
IdentifierName("RegisterControllers")))),
4747
ExpressionStatement(
4848
InvocationExpression(
49-
MemberAccessExpression(
50-
SyntaxKind.SimpleMemberAccessExpression,
51-
IdentifierName("builder"),
52-
IdentifierName("RegisterControllers")))),
53-
ExpressionStatement(
54-
InvocationExpression(
55-
MemberAccessExpression(
56-
SyntaxKind.SimpleMemberAccessExpression,
57-
IdentifierName("builder"),
58-
IdentifierName("RegisterFinalizers")))),
49+
MemberAccessExpression(
50+
SyntaxKind.SimpleMemberAccessExpression,
51+
IdentifierName("builder"),
52+
IdentifierName("RegisterFinalizers")))),
5953
ReturnStatement(IdentifierName("builder")))))))
6054
.NormalizeWhitespace();
6155

0 commit comments

Comments
 (0)