Skip to content

Commit

Permalink
feat: upgrade KubernetesClient
Browse files Browse the repository at this point in the history
  • Loading branch information
buehler committed Oct 9, 2023
1 parent 38a4e5c commit 1c870bf
Show file tree
Hide file tree
Showing 15 changed files with 18 additions and 130 deletions.
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,21 @@ detailed documentation, head to the [GitHub Pages](https://buehler.github.io/dot

## Packages

All packages support .NET6.0 and higher. The reason is that modern C# features are
used and client libraries are still possible for .NET 6.0 and up.
Also, the KubernetesClient package follows the same strategy regarding the
older framework versions.
The following packages exist:

| Package | Description | Framework Support | Latest Version |
|----------------------------------------------------------------------|--------------------------------------------------------|---------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [KubeOps.Abstractions](./src/KubeOps.Abstractions/README.md) | Contains abstractions, attributes, etc. for the SDK | netstandard2.0 netstandard2.1 net6.0 net7.0 | [![Nuget](https://img.shields.io/nuget/vpre/KubeOps.Abstractions?label=nuget%20prerelease)](https://www.nuget.org/packages/KubeOps.Abstractions/absoluteLatest) |
| [KubeOps.Cli](./src/KubeOps.Cli/README.md) | CLI Dotnet Tool to generate stuff | net7.0 | [![Nuget](https://img.shields.io/nuget/vpre/KubeOps.Cli?label=nuget%20prerelease)](https://www.nuget.org/packages/KubeOps.Cli/absoluteLatest) |
| [KubeOps.Generator](./src/KubeOps.Generator/README.md) | Source Generator for the SDK | netstandard2.0 | [![Nuget](https://img.shields.io/nuget/vpre/KubeOps.Generator?label=nuget%20prerelease)](https://www.nuget.org/packages/KubeOps.Generator/absoluteLatest) |
| [KubeOps.KubernetesClient](./src/KubeOps.KubernetesClient/README.md) | Extended client to communicate with the Kubernetes API | net6.0 net7.0 | [![Nuget](https://img.shields.io/nuget/vpre/KubeOps.KubernetesClient?label=nuget%20prerelease)](https://www.nuget.org/packages/KubeOps.KubernetesClient/absoluteLatest) |
| [KubeOps.Operator](./src/KubeOps.Operator/README.md) | Main SDK entrypoint to create an operator | net6.0 net7.0 | [![Nuget](https://img.shields.io/nuget/vpre/KubeOps.Operator?label=nuget%20prerelease)](https://www.nuget.org/packages/KubeOps.Operator/absoluteLatest) |
| [KubeOps.Operator.Web](./src/KubeOps.Operator.Web/README.md) | Web part of the operator (for webhooks) | net6.0 net7.0 | [![Nuget](https://img.shields.io/nuget/vpre/KubeOps.Operator.Web?label=nuget%20prerelease)](https://www.nuget.org/packages/KubeOps.Operator.Web/absoluteLatest) |
| [KubeOps.Transpiler](./src/KubeOps.Transpiler/README.md) | Transpilation helpers for CRDs and RBAC elements | netstandard2.0 netstandard2.1 net6.0 net7.0 | [![Nuget](https://img.shields.io/nuget/vpre/KubeOps.Transpiler?label=nuget%20prerelease)](https://www.nuget.org/packages/KubeOps.Transpiler/absoluteLatest) |
| Package | Description | Latest Version |
|----------------------------------------------------------------------|--------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [KubeOps.Abstractions](./src/KubeOps.Abstractions/README.md) | Contains abstractions, attributes, etc. for the SDK | [![Nuget](https://img.shields.io/nuget/vpre/KubeOps.Abstractions?label=nuget%20prerelease)](https://www.nuget.org/packages/KubeOps.Abstractions/absoluteLatest) |
| [KubeOps.Cli](./src/KubeOps.Cli/README.md) | CLI Dotnet Tool to generate stuff | [![Nuget](https://img.shields.io/nuget/vpre/KubeOps.Cli?label=nuget%20prerelease)](https://www.nuget.org/packages/KubeOps.Cli/absoluteLatest) |
| [KubeOps.Generator](./src/KubeOps.Generator/README.md) | Source Generator for the SDK | [![Nuget](https://img.shields.io/nuget/vpre/KubeOps.Generator?label=nuget%20prerelease)](https://www.nuget.org/packages/KubeOps.Generator/absoluteLatest) |
| [KubeOps.KubernetesClient](./src/KubeOps.KubernetesClient/README.md) | Extended client to communicate with the Kubernetes API | [![Nuget](https://img.shields.io/nuget/vpre/KubeOps.KubernetesClient?label=nuget%20prerelease)](https://www.nuget.org/packages/KubeOps.KubernetesClient/absoluteLatest) |
| [KubeOps.Operator](./src/KubeOps.Operator/README.md) | Main SDK entrypoint to create an operator | [![Nuget](https://img.shields.io/nuget/vpre/KubeOps.Operator?label=nuget%20prerelease)](https://www.nuget.org/packages/KubeOps.Operator/absoluteLatest) |
| [KubeOps.Operator.Web](./src/KubeOps.Operator.Web/README.md) | Web part of the operator (for webhooks) | [![Nuget](https://img.shields.io/nuget/vpre/KubeOps.Operator.Web?label=nuget%20prerelease)](https://www.nuget.org/packages/KubeOps.Operator.Web/absoluteLatest) |
| [KubeOps.Transpiler](./src/KubeOps.Transpiler/README.md) | Transpilation helpers for CRDs and RBAC elements | [![Nuget](https://img.shields.io/nuget/vpre/KubeOps.Transpiler?label=nuget%20prerelease)](https://www.nuget.org/packages/KubeOps.Transpiler/absoluteLatest) |

## Contribution

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,8 @@ public interface IEntityController<in TEntity>
/// </summary>
/// <param name="entity">The entity that fired the reconcile event.</param>
/// <returns>A task that completes when the reconciliation is done.</returns>
#if NETSTANDARD2_0
Task ReconcileAsync(TEntity entity);
#else
Task ReconcileAsync(TEntity entity) =>
Task.CompletedTask;
#endif

/// <summary>
/// Called for `delete` events for a given entity.
Expand All @@ -55,10 +51,6 @@ Task ReconcileAsync(TEntity entity) =>
/// <returns>
/// A task that completes, when the reconciliation is done.
/// </returns>
#if NETSTANDARD2_0
Task DeletedAsync(TEntity entity);
#else
Task DeletedAsync(TEntity entity) =>
Task.CompletedTask;
#endif
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using k8s.Models;

namespace KubeOps.Abstractions.Entities.Attributes;
namespace KubeOps.Abstractions.Entities.Attributes;

/// <summary>
/// Defines a generic additional printer column.
Expand Down Expand Up @@ -40,11 +38,7 @@ public GenericAdditionalPrinterColumnAttribute(string jsonPath, string name, str
/// <summary>
/// Description for the column.
/// </summary>
#if NETSTANDARD
public string? Description { get; set; }
#else
public string? Description { get; init; }
#endif

/// <summary>
/// The type of the column.
Expand Down Expand Up @@ -104,11 +98,7 @@ public GenericAdditionalPrinterColumnAttribute(string jsonPath, string name, str
/// </item>
/// </list>
/// </summary>
#if NETSTANDARD
public string? Format { get; set; }
#else
public string? Format { get; init; }
#endif

/// <summary>
/// The priority of the additional printer column.
Expand All @@ -124,9 +114,5 @@ public GenericAdditionalPrinterColumnAttribute(string jsonPath, string name, str
/// </item>
/// </list>
/// </summary>
#if NETSTANDARD
public PrinterColumnPriority Priority { get; set; }
#else
public PrinterColumnPriority Priority { get; init; }
#endif
}
51 changes: 0 additions & 51 deletions src/KubeOps.Abstractions/Entities/EntityMetadata.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace KubeOps.Abstractions.Entities;

#if NET
/// <summary>
/// Metadata for a given entity.
/// </summary>
Expand All @@ -25,53 +24,3 @@ public record EntityMetadata(string Kind, string Version, string? Group = null,
/// </summary>
public string PluralName => Plural ?? $"{Kind.ToLower()}s";
}
#else
/// <summary>
/// Metadata for a given entity.
/// </summary>
public class EntityMetadata
{
public EntityMetadata(string kind, string version, string? group = null, string? plural = null)
{
Kind = kind;
Version = version;
Group = group;
Plural = plural;
}

/// <summary>
/// The kind of the entity (e.g. deployment).
/// </summary>
public string Kind { get; }

/// <summary>
/// Version (e.g. v1 or v2-alpha).
/// </summary>
public string Version { get; }

/// <summary>
/// The group in Kubernetes (e.g. "testing.dev").
/// </summary>
public string? Group { get; }

/// <summary>
/// An optional plural name. Defaults to the singular name with an added "s".
/// </summary>
public string? Plural { get; }

/// <summary>
/// Kind of the entity when used in a list.
/// </summary>
public string ListKind => $"{Kind}List";

/// <summary>
/// Name of the singular entity.
/// </summary>
public string SingularName => Kind.ToLower();

/// <summary>
/// Name of the plural entity.
/// </summary>
public string PluralName => Plural ?? $"{Kind.ToLower()}s";
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ public interface IEntityFinalizer<in TEntity>
/// </summary>
/// <param name="entity">The kubernetes entity that needs to be finalized.</param>
/// <returns>A task that resolves when the operation is done.</returns>
#if NETSTANDARD2_0
Task FinalizeAsync(TEntity entity);
#else
Task FinalizeAsync(TEntity entity) =>
Task.CompletedTask;
#endif
}
7 changes: 2 additions & 5 deletions src/KubeOps.Abstractions/KubeOps.Abstractions.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -14,11 +14,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="KubernetesClient.Models" Version="12.0.16"/>
<PackageReference Include="KubernetesClient" Version="12.1.1"/>
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="7.0.0"/>
</ItemGroup>




</Project>
4 changes: 0 additions & 4 deletions src/KubeOps.Abstractions/Rbac/EntityRbacAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,5 @@ public EntityRbacAttribute(params Type[] entities)
/// "verbs: ["get", "list", "watch"]".
/// </para>
/// </summary>
#if NETSTANDARD
public RbacVerb Verbs { get; set; }
#else
public RbacVerb Verbs { get; init; }
#endif
}
16 changes: 0 additions & 16 deletions src/KubeOps.Abstractions/Rbac/GenericRbacAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ public class GenericRbacAttribute : RbacAttribute
/// "apiGroups: ...".
/// </para>
/// </summary>
#if NETSTANDARD
public string[] Groups { get; set; } = { };
#else
public string[] Groups { get; init; } = Array.Empty<string>();
#endif

/// <summary>
/// <para>List of resources.</para>
Expand All @@ -31,20 +27,12 @@ public class GenericRbacAttribute : RbacAttribute
/// "resources: ["pods"]".
/// </para>
/// </summary>
#if NETSTANDARD
public string[] Resources { get; set; } = { };
#else
public string[] Resources { get; init; } = Array.Empty<string>();
#endif

/// <summary>
/// List of urls.
/// </summary>
#if NETSTANDARD
public string[] Urls { get; set; } = { };
#else
public string[] Urls { get; init; } = Array.Empty<string>();
#endif

/// <summary>
/// <para>Flags ("list") of allowed verbs.</para>
Expand All @@ -53,9 +41,5 @@ public class GenericRbacAttribute : RbacAttribute
/// "verbs: ["get", "list", "watch"]".
/// </para>
/// </summary>
#if NETSTANDARD
public RbacVerb Verbs { get; set; }
#else
public RbacVerb Verbs { get; init; }
#endif
}
1 change: 0 additions & 1 deletion src/KubeOps.Cli/KubeOps.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

<ItemGroup>
<PackageReference Include="BouncyCastle.Cryptography" Version="2.2.1" />
<PackageReference Include="KubernetesClient" Version="12.0.16"/>
<PackageReference Include="Microsoft.Build.Locator" Version="1.6.10" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.7.0"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.7.0" />
Expand Down
4 changes: 0 additions & 4 deletions src/KubeOps.KubernetesClient/KubeOps.KubernetesClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
</PackageDescription>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="KubernetesClient" Version="12.0.16"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\KubeOps.Abstractions\KubeOps.Abstractions.csproj"/>
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/KubeOps.Operator.Web/KubeOps.Operator.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

<ItemGroup>
<ProjectReference Include="..\KubeOps.Abstractions\KubeOps.Abstractions.csproj"/>
<ProjectReference Include="..\KubeOps.Generator\KubeOps.Generator.csproj" />
</ItemGroup>

</Project>
1 change: 0 additions & 1 deletion src/KubeOps.Operator/KubeOps.Operator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="KubernetesClient" Version="12.0.16"/>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1"/>
</ItemGroup>

Expand Down
6 changes: 0 additions & 6 deletions src/KubeOps.Transpiler/Crds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,7 @@ public static string PropertyName(PropertyInfo prop)
{ Name: { } attrName } => attrName,
};

#if NETSTANDARD2_0
return $"{name.Substring(0, 1).ToLowerInvariant()}{name.Substring(1)}";
#else
return $"{name[..1].ToLowerInvariant()}{name[1..]}";
#endif
}

private static Func<Type, Func<Type, V1JSONSchemaProps?>, V1JSONSchemaProps?> Mapper(
Expand Down Expand Up @@ -475,9 +471,7 @@ private static bool IsSimpleType(Type type) =>

private static bool IsGenericEnumerableType(
Type type,
#if NET
[NotNullWhen(true)]
#endif
out Type? closingType)
{
if (type.IsGenericType && typeof(IEnumerable<>).IsAssignableFrom(type.GetGenericTypeDefinition()))
Expand Down
3 changes: 1 addition & 2 deletions src/KubeOps.Transpiler/KubeOps.Transpiler.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -15,7 +15,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="KubernetesClient.Models" Version="12.0.16" />
<PackageReference Include="Namotion.Reflection" Version="3.0.0" />
</ItemGroup>

Expand Down
4 changes: 0 additions & 4 deletions src/KubeOps.Transpiler/Rbac.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ public static IEnumerable<V1PolicyRule> Transpile(IEnumerable<RbacAttribute> att
RbacVerb.None => Array.Empty<string>(),
_ when verbs.HasFlag(RbacVerb.All) => new[] { "*" },
_ =>
#if NETSTANDARD
Enum.GetValues(typeof(RbacVerb)).Cast<RbacVerb>()
#else
Enum.GetValues<RbacVerb>()
#endif
.Where(v => verbs.HasFlag(v) && v != RbacVerb.All && v != RbacVerb.None)
.Select(v => v.ToString().ToLowerInvariant())
.ToArray(),
Expand Down

0 comments on commit 1c870bf

Please sign in to comment.