Skip to content

Commit

Permalink
feat(abstractions): add custom kubernetes entity helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Bühler committed Sep 29, 2023
1 parent e0625f0 commit bcd1f52
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/KubeOps.Abstractions/Entities/CustomKubernetesEntity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using k8s;
using k8s.Models;

namespace KubeOps.Abstractions.Entities;

/// <summary>
/// Base class for custom Kubernetes entities. The interface <see cref="IKubernetesObject{TMetadata}"/>
/// can be used on its own, but this class provides convenience initializers.
/// </summary>
public abstract class CustomKubernetesEntity : KubernetesObject, IKubernetesObject<V1ObjectMeta>
{
/// <summary>
/// The metadata of the kubernetes object.
/// </summary>
public V1ObjectMeta Metadata { get; set; } = new();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using k8s;

namespace KubeOps.Abstractions.Entities;

/// <summary>
/// Defines a custom Kubernetes entity.
/// This entity contains a spec (like <see cref="CustomKubernetesEntity{TSpec}"/>)
/// and a status (<see cref="Status"/>) which can be updated to reflect the state
/// of the entity.
/// </summary>
/// <typeparam name="TSpec">The type of the specified data.</typeparam>
/// <typeparam name="TStatus">The type of the status data.</typeparam>
public abstract class CustomKubernetesEntity<TSpec, TStatus> : CustomKubernetesEntity<TSpec>, IStatus<TStatus>
where TSpec : new()
where TStatus : new()
{
/// <summary>
/// Status object for the entity.
/// </summary>
public TStatus Status { get; set; } = new();
}
17 changes: 17 additions & 0 deletions src/KubeOps.Abstractions/Entities/CustomKubernetesEntity{TSpec}.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using k8s;

namespace KubeOps.Abstractions.Entities;

/// <summary>
/// Defines a custom kubernetes entity which can be used in finalizers and controllers.
/// This entity contains a <see cref="Spec"/>, which means in contains specified data.
/// </summary>
/// <typeparam name="TSpec">The type of the specified data.</typeparam>
public abstract class CustomKubernetesEntity<TSpec> : CustomKubernetesEntity, ISpec<TSpec>
where TSpec : new()
{
/// <summary>
/// Specification of the kubernetes object.
/// </summary>
public TSpec Spec { get; set; } = new();
}

0 comments on commit bcd1f52

Please sign in to comment.