Skip to content

Commit 1697d26

Browse files
committed
feat(generator): add controller registrations (#623)
This generates `.AddController<T,T>` register calls for the operator builder to enable convenient registering.
1 parent a3a9794 commit 1697d26

File tree

55 files changed

+3836
-3430
lines changed

Some content is hidden

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

55 files changed

+3836
-3430
lines changed

examples/Operator/Controller/V1TestEntityController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ public V1TestEntityController(ILogger<V1TestEntityController> logger)
1919

2020
public Task ReconcileAsync(V1TestEntity entity)
2121
{
22-
_logger.LogInformation("Reconciling entity {EntityName}.", entity.Metadata.Name);
22+
_logger.LogInformation("Reconciling entity {Entity}.", entity);
2323
return Task.CompletedTask;
2424
}
2525

2626
public Task DeletedAsync(V1TestEntity entity)
2727
{
28-
_logger.LogInformation("Deleting entity {EntityName}.", entity.Metadata.Name);
28+
_logger.LogInformation("Deleting entity {Entity}.", entity);
2929
return Task.CompletedTask;
3030
}
3131
}

examples/Operator/Entities/V1TestEntity.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ public class V1TestEntity : IKubernetesObject<V1ObjectMeta>, ISpec<V1TestEntityS
1515
public V1TestEntitySpec Spec { get; set; } = new();
1616

1717
public V1TestEntityStatus Status { get; set; } = new();
18+
19+
public override string ToString() => $"Test Entity ({Metadata.Name}): {Spec.Username} ({Spec.Email})";
1820
}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
using k8s.Models;
2-
31
namespace Operator.Entities;
42

53
public class V1TestEntitySpec
64
{
7-
public string Spec { get; set; } = string.Empty;
8-
95
public string Username { get; set; } = string.Empty;
106

11-
public IntstrIntOrString StringOrInteger { get; set; } = 42;
7+
public string Email { get; set; } = string.Empty;
128
}

examples/Operator/Program.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,13 @@
33
using Microsoft.Extensions.Hosting;
44
using Microsoft.Extensions.Logging;
55

6-
using Operator.Controller;
7-
using Operator.Entities;
8-
96
var builder = Host.CreateApplicationBuilder(args);
107

118
builder.Logging.SetMinimumLevel(LogLevel.Trace);
129

1310
builder.Services
1411
.AddKubernetesOperator()
15-
.RegisterEntitiyMetadata()
16-
.AddController<V1TestEntityController, V1TestEntity>();
12+
.RegisterResources();
1713

1814
using var host = builder.Build();
1915
await host.RunAsync();

examples/Operator/test_entity.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ apiVersion: testing.dev/v1
22
kind: TestEntity
33
metadata:
44
name: my-test-entity
5+
spec:
6+
username: my-username
7+

examples/Operator/todos.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
todo:
2+
- finalizer
3+
- events
4+
- leadership election
5+
- requeue
6+
- build targets
7+
- other CLI commands
8+
- web: webhooks
9+
- cache?
10+
- try .net 8 AOT?
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
using k8s;
2-
using k8s.Models;
3-
4-
namespace KubeOps.Abstractions.Entities;
5-
6-
/// <summary>
7-
/// Base class for custom Kubernetes entities. The interface <see cref="IKubernetesObject{TMetadata}"/>
8-
/// can be used on its own, but this class provides convenience initializers.
9-
/// </summary>
10-
public abstract class CustomKubernetesEntity : KubernetesObject, IKubernetesObject<V1ObjectMeta>
11-
{
12-
/// <summary>
13-
/// The metadata of the kubernetes object.
14-
/// </summary>
15-
public V1ObjectMeta Metadata { get; set; } = new();
16-
}
1+
using k8s;
2+
using k8s.Models;
3+
4+
namespace KubeOps.Abstractions.Entities;
5+
6+
/// <summary>
7+
/// Base class for custom Kubernetes entities. The interface <see cref="IKubernetesObject{TMetadata}"/>
8+
/// can be used on its own, but this class provides convenience initializers.
9+
/// </summary>
10+
public abstract class CustomKubernetesEntity : KubernetesObject, IKubernetesObject<V1ObjectMeta>
11+
{
12+
/// <summary>
13+
/// The metadata of the kubernetes object.
14+
/// </summary>
15+
public V1ObjectMeta Metadata { get; set; } = new();
16+
}
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
using k8s;
2-
3-
namespace KubeOps.Abstractions.Entities;
4-
5-
/// <summary>
6-
/// Defines a custom Kubernetes entity.
7-
/// This entity contains a spec (like <see cref="CustomKubernetesEntity{TSpec}"/>)
8-
/// and a status (<see cref="Status"/>) which can be updated to reflect the state
9-
/// of the entity.
10-
/// </summary>
11-
/// <typeparam name="TSpec">The type of the specified data.</typeparam>
12-
/// <typeparam name="TStatus">The type of the status data.</typeparam>
13-
public abstract class CustomKubernetesEntity<TSpec, TStatus> : CustomKubernetesEntity<TSpec>, IStatus<TStatus>
14-
where TSpec : new()
15-
where TStatus : new()
16-
{
17-
/// <summary>
18-
/// Status object for the entity.
19-
/// </summary>
20-
public TStatus Status { get; set; } = new();
21-
}
1+
using k8s;
2+
3+
namespace KubeOps.Abstractions.Entities;
4+
5+
/// <summary>
6+
/// Defines a custom Kubernetes entity.
7+
/// This entity contains a spec (like <see cref="CustomKubernetesEntity{TSpec}"/>)
8+
/// and a status (<see cref="Status"/>) which can be updated to reflect the state
9+
/// of the entity.
10+
/// </summary>
11+
/// <typeparam name="TSpec">The type of the specified data.</typeparam>
12+
/// <typeparam name="TStatus">The type of the status data.</typeparam>
13+
public abstract class CustomKubernetesEntity<TSpec, TStatus> : CustomKubernetesEntity<TSpec>, IStatus<TStatus>
14+
where TSpec : new()
15+
where TStatus : new()
16+
{
17+
/// <summary>
18+
/// Status object for the entity.
19+
/// </summary>
20+
public TStatus Status { get; set; } = new();
21+
}
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
using k8s;
2-
3-
namespace KubeOps.Abstractions.Entities;
4-
5-
/// <summary>
6-
/// Defines a custom kubernetes entity which can be used in finalizers and controllers.
7-
/// This entity contains a <see cref="Spec"/>, which means in contains specified data.
8-
/// </summary>
9-
/// <typeparam name="TSpec">The type of the specified data.</typeparam>
10-
public abstract class CustomKubernetesEntity<TSpec> : CustomKubernetesEntity, ISpec<TSpec>
11-
where TSpec : new()
12-
{
13-
/// <summary>
14-
/// Specification of the kubernetes object.
15-
/// </summary>
16-
public TSpec Spec { get; set; } = new();
17-
}
1+
using k8s;
2+
3+
namespace KubeOps.Abstractions.Entities;
4+
5+
/// <summary>
6+
/// Defines a custom kubernetes entity which can be used in finalizers and controllers.
7+
/// This entity contains a <see cref="Spec"/>, which means in contains specified data.
8+
/// </summary>
9+
/// <typeparam name="TSpec">The type of the specified data.</typeparam>
10+
public abstract class CustomKubernetesEntity<TSpec> : CustomKubernetesEntity, ISpec<TSpec>
11+
where TSpec : new()
12+
{
13+
/// <summary>
14+
/// Specification of the kubernetes object.
15+
/// </summary>
16+
public TSpec Spec { get; set; } = new();
17+
}
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
using k8s;
2-
using k8s.Models;
3-
4-
namespace KubeOps.Abstractions.Entities;
5-
6-
/// <summary>
7-
/// Type for a list of entities.
8-
/// </summary>
9-
/// <typeparam name="T">Type for the list entries.</typeparam>
10-
public class EntityList<T> : KubernetesObject
11-
where T : IKubernetesObject
12-
{
13-
/// <summary>
14-
/// Official list metadata object of kubernetes.
15-
/// </summary>
16-
public V1ListMeta Metadata { get; set; } = new();
17-
18-
/// <summary>
19-
/// The list of items.
20-
/// </summary>
21-
public IList<T> Items { get; set; } = new List<T>();
22-
}
1+
using k8s;
2+
using k8s.Models;
3+
4+
namespace KubeOps.Abstractions.Entities;
5+
6+
/// <summary>
7+
/// Type for a list of entities.
8+
/// </summary>
9+
/// <typeparam name="T">Type for the list entries.</typeparam>
10+
public class EntityList<T> : KubernetesObject
11+
where T : IKubernetesObject
12+
{
13+
/// <summary>
14+
/// Official list metadata object of kubernetes.
15+
/// </summary>
16+
public V1ListMeta Metadata { get; set; } = new();
17+
18+
/// <summary>
19+
/// The list of items.
20+
/// </summary>
21+
public IList<T> Items { get; set; } = new List<T>();
22+
}

0 commit comments

Comments
 (0)