Skip to content

Commit

Permalink
Merge pull request #162 from tintoy/feature/update-k8s-swagger
Browse files Browse the repository at this point in the history
Update generated models from Kubernetes v1.31 API definitions
  • Loading branch information
tintoy authored Oct 1, 2024
2 parents 0e6efa6 + 527f300 commit 1e08492
Show file tree
Hide file tree
Showing 521 changed files with 97,946 additions and 662 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,24 @@ public static ICustomResourceDefinitionClientV1Beta1 CustomResourceDefinitionsV1
client => new CustomResourceDefinitionClientV1Beta1(client)
);
}

/// <summary>
/// Get the Kubernetes CustomResourceDefinitions (v1) resource client.
/// </summary>
/// <param name="kubeClient">
/// The Kubernetes API client.
/// </param>
/// <returns>
/// The resource client.
/// </returns>
public static ICustomResourceDefinitionClientV1 CustomResourceDefinitionsV1(this KubeApiClient kubeClient)
{
if (kubeClient == null)
throw new ArgumentNullException(nameof(kubeClient));

return kubeClient.ResourceClient(
client => new CustomResourceDefinitionClientV1(client)
);
}
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
using HTTPlease;
using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Threading;
using System.Net;

namespace KubeClient.ResourceClients
{
using Models;

/// <summary>
/// A client for the Kubernetes CustomResourceDefinitions (v1beta1) API.
/// </summary>
public class CustomResourceDefinitionClientV1Beta1
: KubeResourceClient, ICustomResourceDefinitionClientV1Beta1
{
/// <summary>
/// Create a new <see cref="CustomResourceDefinitionClientV1Beta1"/>.
/// </summary>
/// <param name="client">
/// The Kubernetes API client.
/// </param>
public CustomResourceDefinitionClientV1Beta1(IKubeApiClient client)
: base(client)
{
}

/// <summary>
/// Get the CustomResourceDefinition with the specified name.
/// </summary>
/// <param name="name">
/// The name of the CustomResourceDefinition to retrieve.
/// </param>
/// <param name="cancellationToken">
/// An optional <see cref="CancellationToken"/> that can be used to cancel the request.
/// </param>
/// <returns>
/// A <see cref="CustomResourceDefinitionV1Beta1"/> representing the current state for the CustomResourceDefinition, or <c>null</c> if no CustomResourceDefinition was found with the specified name and namespace.
/// </returns>
public async Task<CustomResourceDefinitionV1Beta1> Get(string name, CancellationToken cancellationToken = default)
{
if (String.IsNullOrWhiteSpace(name))
throw new ArgumentException("Argument cannot be null, empty, or entirely composed of whitespace: 'name'.", nameof(name));

return await GetSingleResource<CustomResourceDefinitionV1Beta1>(
Requests.ByName.WithTemplateParameters(new
{
Name = name
}),
cancellationToken: cancellationToken
);
}

/// <summary>
/// Get all CustomResourceDefinitions in the specified namespace, optionally matching a label selector.
/// </summary>
/// <param name="labelSelector">
/// An optional Kubernetes label selector expression used to filter the CustomResourceDefinitions.
/// </param>
/// <param name="cancellationToken">
/// An optional <see cref="CancellationToken"/> that can be used to cancel the request.
/// </param>
/// <returns>
/// A <see cref="CustomResourceDefinitionListV1Beta1"/> containing the jobs.
/// </returns>
public async Task<CustomResourceDefinitionListV1Beta1> List(string labelSelector = null, CancellationToken cancellationToken = default)
{
return await GetResourceList<CustomResourceDefinitionListV1Beta1>(
Requests.Collection.WithTemplateParameters(new
{
LabelSelector = labelSelector
}),
cancellationToken: cancellationToken
);
}

/// <summary>
/// Watch for events relating to a specific CustomResourceDefinition.
/// </summary>
/// <param name="name">
/// The name of the job to watch.
/// </param>
/// <returns>
/// An <see cref="IObservable{T}"/> representing the event stream.
/// </returns>
public IObservable<IResourceEventV1<CustomResourceDefinitionV1Beta1>> Watch(string name)
{
if (String.IsNullOrWhiteSpace(name))
throw new ArgumentException("Argument cannot be null, empty, or entirely composed of whitespace: 'name'.", nameof(name));

return ObserveEvents<CustomResourceDefinitionV1Beta1>(
Requests.WatchByName.WithTemplateParameters(new
{
Name = name
}),
operationDescription: $"watch v1beta1/CustomResourceDefintion '{name}'"
);
}

/// <summary>
/// Watch for events relating to CustomResourceDefinitions.
/// </summary>
/// <param name="labelSelector">
/// An optional Kubernetes label selector expression used to filter the CustomResourceDefinitions.
/// </param>
/// <returns>
/// An <see cref="IObservable{T}"/> representing the event stream.
/// </returns>
public IObservable<IResourceEventV1<CustomResourceDefinitionV1Beta1>> WatchAll(string labelSelector = null)
{
return ObserveEvents<CustomResourceDefinitionV1Beta1>(
Requests.WatchCollection.WithTemplateParameters(new
{
LabelSelector = labelSelector
}),
operationDescription: $"watch all v1beta1/CustomResourceDefintions with label selector '{labelSelector ?? "<none>"}'"
);
}

/// <summary>
/// Request creation of a <see cref="CustomResourceDefinitionV1Beta1"/>.
/// </summary>
/// <param name="newCustomResourceDefinition">
/// A <see cref="CustomResourceDefinitionV1Beta1"/> representing the CustomResourceDefinition to create.
/// </param>
/// <param name="cancellationToken">
/// An optional <see cref="CancellationToken"/> that can be used to cancel the request.
/// </param>
/// <returns>
/// A <see cref="CustomResourceDefinitionV1Beta1"/> representing the current state for the newly-created CustomResourceDefinition.
/// </returns>
public async Task<CustomResourceDefinitionV1Beta1> Create(CustomResourceDefinitionV1Beta1 newCustomResourceDefinition, CancellationToken cancellationToken = default)
{
if (newCustomResourceDefinition == null)
throw new ArgumentNullException(nameof(newCustomResourceDefinition));

return await Http
.PostAsJsonAsync(Requests.Collection,
postBody: newCustomResourceDefinition,
cancellationToken: cancellationToken
)
.ReadContentAsObjectV1Async<CustomResourceDefinitionV1Beta1>();
}

/// <summary>
/// Request deletion of the specified CustomResourceDefinition.
/// </summary>
/// <param name="name">
/// The name of the CustomResourceDefinition to delete.
/// </param>
/// <param name="propagationPolicy">
/// An optional <see cref="DeletePropagationPolicy"/> value indicating how child resources should be deleted (if at all).
/// </param>
/// <param name="cancellationToken">
/// An optional <see cref="CancellationToken"/> that can be used to cancel the request.
/// </param>
/// <returns>
/// A <see cref="CustomResourceDefinitionV1Beta1"/> representing the job's most recent state before it was deleted, if <paramref name="propagationPolicy"/> is <see cref="DeletePropagationPolicy.Foreground"/>; otherwise, a <see cref="StatusV1"/>.
/// </returns>
public Task<KubeResourceResultV1<CustomResourceDefinitionV1Beta1>> Delete(string name, DeletePropagationPolicy? propagationPolicy = null, CancellationToken cancellationToken = default)
{
return DeleteGlobalResource<CustomResourceDefinitionV1Beta1>(Requests.ByName, name, propagationPolicy, cancellationToken);
}

/// <summary>
/// Request templates for the CustomResourceDefinition (v1) API.
/// </summary>
static class Requests
{
/// <summary>
/// A collection-level CustomResourceDefinition (v1) request.
/// </summary>
public static readonly HttpRequest Collection = KubeRequest.Create("apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions?labelSelector={LabelSelector?}");

/// <summary>
/// A get-by-name CustomResourceDefinition (v1) request.
/// </summary>
public static readonly HttpRequest ByName = KubeRequest.Create("apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/{Name}");

/// <summary>
/// A collection-level CustomResourceDefinition watch (v1) request.
/// </summary>
public static readonly HttpRequest WatchCollection = KubeRequest.Create("/apis/apiextensions.k8s.io/v1beta1/watch/customresourcedefinitions?labelSelector={LabelSelector?}");

/// <summary>
/// A watch-by-name CustomResourceDefinition (v1) request.
/// </summary>
public static readonly HttpRequest WatchByName = KubeRequest.Create("/apis/apiextensions.k8s.io/v1beta1/watch/customresourcedefinitions/{Name}");
}
}

/// <summary>
/// Represents a client for the Kubernetes CustomResourceDefinitions (v1beta1) API.
/// </summary>
public interface ICustomResourceDefinitionClientV1Beta1
{
/// <summary>
/// Get the CustomResourceDefinition with the specified name.
/// </summary>
/// <param name="name">
/// The name of the CustomResourceDefinition to retrieve.
/// </param>
/// <param name="cancellationToken">
/// An optional <see cref="CancellationToken"/> that can be used to cancel the request.
/// </param>
/// <returns>
/// A <see cref="CustomResourceDefinitionV1Beta1"/> representing the current state for the CustomResourceDefinition, or <c>null</c> if no CustomResourceDefinition was found with the specified name and namespace.
/// </returns>
Task<CustomResourceDefinitionV1Beta1> Get(string name, CancellationToken cancellationToken = default);

/// <summary>
/// Get all CustomResourceDefinitions in the specified namespace, optionally matching a label selector.
/// </summary>
/// <param name="labelSelector">
/// An optional Kubernetes label selector expression used to filter the CustomResourceDefinitions.
/// </param>
/// <param name="cancellationToken">
/// An optional <see cref="CancellationToken"/> that can be used to cancel the request.
/// </param>
/// <returns>
/// A <see cref="CustomResourceDefinitionListV1Beta1"/> containing the jobs.
/// </returns>
Task<CustomResourceDefinitionListV1Beta1> List(string labelSelector = null, CancellationToken cancellationToken = default);

/// <summary>
/// Watch for events relating to a specific CustomResourceDefinition.
/// </summary>
/// <param name="name">
/// The name of the job to watch.
/// </param>
/// <returns>
/// An <see cref="IObservable{T}"/> representing the event stream.
/// </returns>
IObservable<IResourceEventV1<CustomResourceDefinitionV1Beta1>> Watch(string name);

/// <summary>
/// Watch for events relating to CustomResourceDefinitions.
/// </summary>
/// <param name="labelSelector">
/// An optional Kubernetes label selector expression used to filter the CustomResourceDefinitions.
/// </param>
/// <returns>
/// An <see cref="IObservable{T}"/> representing the event stream.
/// </returns>
IObservable<IResourceEventV1<CustomResourceDefinitionV1Beta1>> WatchAll(string labelSelector = null);

/// <summary>
/// Request creation of a <see cref="CustomResourceDefinitionV1Beta1"/>.
/// </summary>
/// <param name="newCustomResourceDefinition">
/// A <see cref="CustomResourceDefinitionV1Beta1"/> representing the CustomResourceDefinition to create.
/// </param>
/// <param name="cancellationToken">
/// An optional <see cref="CancellationToken"/> that can be used to cancel the request.
/// </param>
/// <returns>
/// A <see cref="CustomResourceDefinitionV1Beta1"/> representing the current state for the newly-created CustomResourceDefinition.
/// </returns>
Task<CustomResourceDefinitionV1Beta1> Create(CustomResourceDefinitionV1Beta1 newCustomResourceDefinition, CancellationToken cancellationToken = default);

/// <summary>
/// Request deletion of the specified CustomResourceDefinition.
/// </summary>
/// <param name="name">
/// The name of the CustomResourceDefinition to delete.
/// </param>
/// <param name="propagationPolicy">
/// A <see cref="DeletePropagationPolicy"/> indicating how child resources should be deleted (if at all).
/// </param>
/// <param name="cancellationToken">
/// An optional <see cref="CancellationToken"/> that can be used to cancel the request.
/// </param>
/// <returns>
/// A <see cref="CustomResourceDefinitionV1Beta1"/> representing the job's most recent state before it was deleted, if <paramref name="propagationPolicy"/> is <see cref="DeletePropagationPolicy.Foreground"/>; otherwise, a <see cref="StatusV1"/>.
/// </returns>
Task<KubeResourceResultV1<CustomResourceDefinitionV1Beta1>> Delete(string name, DeletePropagationPolicy? propagationPolicy = null, CancellationToken cancellationToken = default);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ protected KubeCustomResourceV1()
/// Generate a JSON schema for validating the specification model.
/// </summary>
/// <returns>
/// The configured <see cref="JSONSchemaPropsV1Beta1"/>.
/// The configured <see cref="JSONSchemaPropsV1"/>.
/// </returns>
public abstract JSONSchemaPropsV1Beta1 GenerateSpecificationSchema();
public abstract JSONSchemaPropsV1 GenerateSpecificationSchema();
}

/// <summary>
Expand Down Expand Up @@ -56,8 +56,8 @@ protected KubeCustomResourceV1()
/// Generate a JSON schema for validating the specification model.
/// </summary>
/// <returns>
/// The configured <see cref="JSONSchemaPropsV1Beta1"/>.
/// The configured <see cref="JSONSchemaPropsV1"/>.
/// </returns>
public override JSONSchemaPropsV1Beta1 GenerateSpecificationSchema() => SchemaGenerator.GenerateSchema(modelType: typeof(TSpecification));
public override JSONSchemaPropsV1 GenerateSpecificationSchema() => SchemaGeneratorV1.GenerateSchema(modelType: typeof(TSpecification));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using Newtonsoft.Json;

namespace KubeClient.Models
{
using Extensions.CustomResources;

/// <summary>
/// The base class for models representing Kubernetes Custom Resources (CRDs).
/// </summary>
public abstract class KubeCustomResourceV1Beta1
: KubeResourceV1
{
/// <summary>
/// Create a new <see cref="KubeCustomResourceV1Beta1"/>.
/// </summary>
protected KubeCustomResourceV1Beta1()
{
if (String.IsNullOrEmpty(Kind) || string.IsNullOrWhiteSpace(ApiVersion))
throw new KubeClientException($"Class '{GetType().Name}' derives from '{nameof(KubeCustomResourceV1Beta1)}' but is not decorated with the 'KubeResource' attribute.");
}

/// <summary>
/// Generate a JSON schema for validating the specification model.
/// </summary>
/// <returns>
/// The configured <see cref="JSONSchemaPropsV1Beta1"/>.
/// </returns>
public abstract JSONSchemaPropsV1Beta1 GenerateSpecificationSchema();
}

/// <summary>
/// The base class for models representing Kubernetes Custom Resource Definitions (CRDs).
/// </summary>
/// <typeparam name="TSpecification">
/// The type of model used to represent the resource specification.
/// </typeparam>
public abstract class KubeCustomResourceV1Beta1<TSpecification>
: KubeCustomResourceV1Beta1
where TSpecification : class
{
/// <summary>
/// Create a new <see cref="KubeCustomResourceV1Beta1{TSpec}"/>.
/// </summary>
protected KubeCustomResourceV1Beta1()
{
}

/// <summary>
/// The resource specification.
/// </summary>
[JsonProperty("spec", NullValueHandling = NullValueHandling.Ignore)]
public virtual TSpecification Specification { get; set; }

/// <summary>
/// Generate a JSON schema for validating the specification model.
/// </summary>
/// <returns>
/// The configured <see cref="JSONSchemaPropsV1Beta1"/>.
/// </returns>
public override JSONSchemaPropsV1Beta1 GenerateSpecificationSchema() => SchemaGeneratorV1Beta1.GenerateSchema(modelType: typeof(TSpecification));
}
}
Loading

0 comments on commit 1e08492

Please sign in to comment.