8.0: API Group + v1.24 (#850)

* swagger 1.24

* trim converter

* api group

* before moving method

* grouped api for client

* fix classic build

* fix e2e

* move all code to v8

* fix vis to

* bump ver

* fix authtest filename
This commit is contained in:
Boshi Lian
2022-05-07 13:05:17 -07:00
committed by GitHub
parent 78bfa24157
commit 85755ccb3e
51 changed files with 2461 additions and 3335 deletions

View File

@@ -1,3 +1,3 @@
export KUBERNETES_BRANCH=v1.23.0 export KUBERNETES_BRANCH=v1.24.0
export CLIENT_VERSION=0.0.1 export CLIENT_VERSION=0.0.1
export PACKAGE_NAME=k8s export PACKAGE_NAME=k8s

View File

@@ -13,7 +13,7 @@ namespace attach
IKubernetes client = new Kubernetes(config); IKubernetes client = new Kubernetes(config);
Console.WriteLine("Starting Request!"); Console.WriteLine("Starting Request!");
var list = client.ListNamespacedPod("default"); var list = client.CoreV1.ListNamespacedPod("default");
var pod = list.Items[0]; var pod = list.Items[0];
await AttachToPod(client, pod).ConfigureAwait(false); await AttachToPod(client, pod).ConfigureAwait(false);
} }

View File

@@ -55,14 +55,14 @@ var request = new V1CertificateSigningRequest
} }
}; };
await client.CreateCertificateSigningRequestAsync(request); await client.CertificatesV1.CreateCertificateSigningRequestAsync(request);
var serializeOptions = new JsonSerializerOptions var serializeOptions = new JsonSerializerOptions
{ {
PropertyNamingPolicy = JsonNamingPolicy.CamelCase, PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = true WriteIndented = true
}; };
var readCert = await client.ReadCertificateSigningRequestAsync(name); var readCert = await client.CertificatesV1.ReadCertificateSigningRequestAsync(name);
var old = JsonSerializer.SerializeToDocument(readCert, serializeOptions); var old = JsonSerializer.SerializeToDocument(readCert, serializeOptions);
var replace = new List<V1CertificateSigningRequestCondition> var replace = new List<V1CertificateSigningRequestCondition>
@@ -74,4 +74,4 @@ readCert.Status.Conditions = replace;
var expected = JsonSerializer.SerializeToDocument(readCert, serializeOptions); var expected = JsonSerializer.SerializeToDocument(readCert, serializeOptions);
var patch = old.CreatePatch(expected); var patch = old.CreatePatch(expected);
await client.PatchCertificateSigningRequestApprovalAsync(new V1Patch(patch, V1Patch.PatchType.JsonPatch), name); await client.CertificatesV1.PatchCertificateSigningRequestApprovalAsync(new V1Patch(patch, V1Patch.PatchType.JsonPatch), name);

View File

@@ -31,7 +31,7 @@ namespace customResource
try try
{ {
Console.WriteLine("creating CR {0}", myCr.Metadata.Name); Console.WriteLine("creating CR {0}", myCr.Metadata.Name);
var response = await client.CreateNamespacedCustomObjectWithHttpMessagesAsync( var response = await client.CustomObjects.CreateNamespacedCustomObjectWithHttpMessagesAsync(
myCr, myCr,
myCRD.Group, myCRD.Version, myCRD.Group, myCRD.Version,
myCr.Metadata.NamespaceProperty ?? "default", myCr.Metadata.NamespaceProperty ?? "default",
@@ -66,7 +66,7 @@ namespace customResource
var crPatch = new V1Patch(patch, V1Patch.PatchType.JsonPatch); var crPatch = new V1Patch(patch, V1Patch.PatchType.JsonPatch);
try try
{ {
var patchResponse = await client.PatchNamespacedCustomObjectAsync( var patchResponse = await client.CustomObjects.PatchNamespacedCustomObjectAsync(
crPatch, crPatch,
myCRD.Group, myCRD.Group,
myCRD.Version, myCRD.Version,

View File

@@ -13,7 +13,7 @@ namespace exec
IKubernetes client = new Kubernetes(config); IKubernetes client = new Kubernetes(config);
Console.WriteLine("Starting Request!"); Console.WriteLine("Starting Request!");
var list = client.ListNamespacedPod("default"); var list = client.CoreV1.ListNamespacedPod("default");
var pod = list.Items[0]; var pod = list.Items[0];
await ExecInPod(client, pod).ConfigureAwait(false); await ExecInPod(client, pod).ConfigureAwait(false);
} }

View File

@@ -12,7 +12,7 @@ namespace simple
IKubernetes client = new Kubernetes(config); IKubernetes client = new Kubernetes(config);
Console.WriteLine("Starting Request!"); Console.WriteLine("Starting Request!");
var list = client.ListNamespacedService("default"); var list = client.CoreV1.ListNamespacedService("default");
foreach (var item in list.Items) foreach (var item in list.Items)
{ {
Console.WriteLine("Pods for service: " + item.Metadata.Name); Console.WriteLine("Pods for service: " + item.Metadata.Name);
@@ -30,7 +30,7 @@ namespace simple
var labelStr = string.Join(",", labels.ToArray()); var labelStr = string.Join(",", labels.ToArray());
Console.WriteLine(labelStr); Console.WriteLine(labelStr);
var podList = client.ListNamespacedPod("default", labelSelector: labelStr); var podList = client.CoreV1.ListNamespacedPod("default", labelSelector: labelStr);
foreach (var pod in podList.Items) foreach (var pod in podList.Items)
{ {
Console.WriteLine(pod.Metadata.Name); Console.WriteLine(pod.Metadata.Name);

View File

@@ -12,7 +12,7 @@ namespace logs
IKubernetes client = new Kubernetes(config); IKubernetes client = new Kubernetes(config);
Console.WriteLine("Starting Request!"); Console.WriteLine("Starting Request!");
var list = client.ListNamespacedPod("default"); var list = client.CoreV1.ListNamespacedPod("default");
if (list.Items.Count == 0) if (list.Items.Count == 0)
{ {
Console.WriteLine("No pods!"); Console.WriteLine("No pods!");
@@ -21,7 +21,7 @@ namespace logs
var pod = list.Items[0]; var pod = list.Items[0];
var response = await client.ReadNamespacedPodLogWithHttpMessagesAsync( var response = await client.CoreV1.ReadNamespacedPodLogWithHttpMessagesAsync(
pod.Metadata.Name, pod.Metadata.Name,
pod.Metadata.NamespaceProperty, follow: true).ConfigureAwait(false); pod.Metadata.NamespaceProperty, follow: true).ConfigureAwait(false);
var stream = response.Body; var stream = response.Body;

View File

@@ -10,7 +10,7 @@ namespace @namespace
{ {
private static void ListNamespaces(IKubernetes client) private static void ListNamespaces(IKubernetes client)
{ {
var list = client.ListNamespace(); var list = client.CoreV1.ListNamespace();
foreach (var item in list.Items) foreach (var item in list.Items)
{ {
Console.WriteLine(item.Metadata.Name); Console.WriteLine(item.Metadata.Name);
@@ -29,7 +29,7 @@ namespace @namespace
await Task.Delay(delayMillis).ConfigureAwait(false); await Task.Delay(delayMillis).ConfigureAwait(false);
try try
{ {
await client.ReadNamespaceAsync(name).ConfigureAwait(false); await client.CoreV1.ReadNamespaceAsync(name).ConfigureAwait(false);
} }
catch (AggregateException ex) catch (AggregateException ex)
{ {
@@ -73,12 +73,12 @@ namespace @namespace
var ns = new V1Namespace { Metadata = new V1ObjectMeta { Name = "test" } }; var ns = new V1Namespace { Metadata = new V1ObjectMeta { Name = "test" } };
var result = client.CreateNamespace(ns); var result = client.CoreV1.CreateNamespace(ns);
Console.WriteLine(result); Console.WriteLine(result);
ListNamespaces(client); ListNamespaces(client);
var status = client.DeleteNamespace(ns.Metadata.Name, new V1DeleteOptions()); var status = client.CoreV1.DeleteNamespace(ns.Metadata.Name, new V1DeleteOptions());
if (status.HasObject) if (status.HasObject)
{ {

View File

@@ -13,7 +13,7 @@ namespace patch
IKubernetes client = new Kubernetes(config); IKubernetes client = new Kubernetes(config);
Console.WriteLine("Starting Request!"); Console.WriteLine("Starting Request!");
var pod = client.ListNamespacedPod("default").Items.First(); var pod = client.CoreV1.ListNamespacedPod("default").Items.First();
var name = pod.Metadata.Name; var name = pod.Metadata.Name;
PrintLabels(pod); PrintLabels(pod);
@@ -26,8 +26,8 @@ namespace patch
} }
}"; }";
client.PatchNamespacedPod(new V1Patch(patchStr, V1Patch.PatchType.MergePatch), name, "default"); client.CoreV1.PatchNamespacedPod(new V1Patch(patchStr, V1Patch.PatchType.MergePatch), name, "default");
PrintLabels(client.ReadNamespacedPod(name, "default")); PrintLabels(client.CoreV1.ReadNamespacedPod(name, "default"));
} }
private static void PrintLabels(V1Pod pod) private static void PrintLabels(V1Pod pod)

View File

@@ -16,7 +16,7 @@ namespace portforward
IKubernetes client = new Kubernetes(config); IKubernetes client = new Kubernetes(config);
Console.WriteLine("Starting port forward!"); Console.WriteLine("Starting port forward!");
var list = client.ListNamespacedPod("default"); var list = client.CoreV1.ListNamespacedPod("default");
var pod = list.Items[0]; var pod = list.Items[0];
await Forward(client, pod); await Forward(client, pod);
} }

View File

@@ -21,9 +21,9 @@ namespace prom
Console.WriteLine("Making requests!"); Console.WriteLine("Making requests!");
while (true) while (true)
{ {
client.ListNamespacedPod("default"); client.CoreV1.ListNamespacedPod("default");
client.ListNode(); client.CoreV1.ListNode();
client.ListNamespacedDeployment("default"); client.AppsV1.ListNamespacedDeployment("default");
Thread.Sleep(1000); Thread.Sleep(1000);
} }
} }

View File

@@ -13,7 +13,7 @@ double ConvertToUnixTimestamp(DateTime date)
async Task RestartDaemonSetAsync(string name, string @namespace, IKubernetes client) async Task RestartDaemonSetAsync(string name, string @namespace, IKubernetes client)
{ {
var daemonSet = await client.ReadNamespacedDaemonSetAsync(name, @namespace); var daemonSet = await client.AppsV1.ReadNamespacedDaemonSetAsync(name, @namespace);
var options = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, WriteIndented = true }; var options = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, WriteIndented = true };
var old = JsonSerializer.SerializeToDocument(daemonSet, options); var old = JsonSerializer.SerializeToDocument(daemonSet, options);
@@ -27,12 +27,12 @@ async Task RestartDaemonSetAsync(string name, string @namespace, IKubernetes cli
var expected = JsonSerializer.SerializeToDocument(daemonSet); var expected = JsonSerializer.SerializeToDocument(daemonSet);
var patch = old.CreatePatch(expected); var patch = old.CreatePatch(expected);
await client.PatchNamespacedDaemonSetAsync(new V1Patch(patch, V1Patch.PatchType.JsonPatch), name, @namespace); await client.AppsV1.PatchNamespacedDaemonSetAsync(new V1Patch(patch, V1Patch.PatchType.JsonPatch), name, @namespace);
} }
async Task RestartDeploymentAsync(string name, string @namespace, IKubernetes client) async Task RestartDeploymentAsync(string name, string @namespace, IKubernetes client)
{ {
var deployment = await client.ReadNamespacedDeploymentAsync(name, @namespace); var deployment = await client.AppsV1.ReadNamespacedDeploymentAsync(name, @namespace);
var options = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, WriteIndented = true }; var options = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, WriteIndented = true };
var old = JsonSerializer.SerializeToDocument(deployment, options); var old = JsonSerializer.SerializeToDocument(deployment, options);
@@ -46,12 +46,12 @@ async Task RestartDeploymentAsync(string name, string @namespace, IKubernetes cl
var expected = JsonSerializer.SerializeToDocument(deployment); var expected = JsonSerializer.SerializeToDocument(deployment);
var patch = old.CreatePatch(expected); var patch = old.CreatePatch(expected);
await client.PatchNamespacedDeploymentAsync(new V1Patch(patch, V1Patch.PatchType.JsonPatch), name, @namespace); await client.AppsV1.PatchNamespacedDeploymentAsync(new V1Patch(patch, V1Patch.PatchType.JsonPatch), name, @namespace);
} }
async Task RestartStatefulSetAsync(string name, string @namespace, IKubernetes client) async Task RestartStatefulSetAsync(string name, string @namespace, IKubernetes client)
{ {
var deployment = await client.ReadNamespacedStatefulSetAsync(name, @namespace); var deployment = await client.AppsV1.ReadNamespacedStatefulSetAsync(name, @namespace);
var options = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, WriteIndented = true }; var options = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, WriteIndented = true };
var old = JsonSerializer.SerializeToDocument(deployment, options); var old = JsonSerializer.SerializeToDocument(deployment, options);
@@ -65,7 +65,7 @@ async Task RestartStatefulSetAsync(string name, string @namespace, IKubernetes c
var expected = JsonSerializer.SerializeToDocument(deployment); var expected = JsonSerializer.SerializeToDocument(deployment);
var patch = old.CreatePatch(expected); var patch = old.CreatePatch(expected);
await client.PatchNamespacedStatefulSetAsync(new V1Patch(patch, V1Patch.PatchType.JsonPatch), name, @namespace); await client.AppsV1.PatchNamespacedStatefulSetAsync(new V1Patch(patch, V1Patch.PatchType.JsonPatch), name, @namespace);
} }
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile(); var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();

View File

@@ -11,7 +11,7 @@ namespace simple
IKubernetes client = new Kubernetes(config); IKubernetes client = new Kubernetes(config);
Console.WriteLine("Starting Request!"); Console.WriteLine("Starting Request!");
var list = client.ListNamespacedPod("default"); var list = client.CoreV1.ListNamespacedPod("default");
foreach (var item in list.Items) foreach (var item in list.Items)
{ {
Console.WriteLine(item.Metadata.Name); Console.WriteLine(item.Metadata.Name);

View File

@@ -14,7 +14,7 @@ namespace watch
IKubernetes client = new Kubernetes(config); IKubernetes client = new Kubernetes(config);
var podlistResp = client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true); var podlistResp = client.CoreV1.ListNamespacedPodWithHttpMessagesAsync("default", watch: true);
// C# 8 required https://docs.microsoft.com/en-us/archive/msdn-magazine/2019/november/csharp-iterating-with-async-enumerables-in-csharp-8 // C# 8 required https://docs.microsoft.com/en-us/archive/msdn-magazine/2019/november/csharp-iterating-with-async-enumerables-in-csharp-8
await foreach (var (type, item) in podlistResp.WatchAsync<V1Pod, V1PodList>()) await foreach (var (type, item) in podlistResp.WatchAsync<V1Pod, V1PodList>())
{ {
@@ -30,7 +30,7 @@ namespace watch
private static void WatchUsingCallback(IKubernetes client) private static void WatchUsingCallback(IKubernetes client)
{ {
var podlistResp = client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true); var podlistResp = client.CoreV1.ListNamespacedPodWithHttpMessagesAsync("default", watch: true);
using (podlistResp.Watch<V1Pod, V1PodList>((type, item) => using (podlistResp.Watch<V1Pod, V1PodList>((type, item) =>
{ {
Console.WriteLine("==on watch event=="); Console.WriteLine("==on watch event==");

View File

@@ -1,120 +1,54 @@
using System.Net.Http; using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using k8s.Autorest;
using k8s.Models;
using System.Net.Http.Headers; using System.Net.Http.Headers;
namespace k8s;
namespace k8s public abstract partial class AbstractKubernetes
{ {
public abstract partial class AbstractKubernetes
public virtual TimeSpan HttpClientTimeout { get; set; } = TimeSpan.FromSeconds(100);
protected internal virtual MediaTypeHeaderValue GetHeader(object body)
{ {
private static class HttpMethods if (body == null)
{ {
public static readonly HttpMethod Delete = HttpMethod.Delete; throw new ArgumentNullException(nameof(body));
public static readonly HttpMethod Get = HttpMethod.Get;
public static readonly HttpMethod Head = HttpMethod.Head;
public static readonly HttpMethod Options = HttpMethod.Options;
public static readonly HttpMethod Post = HttpMethod.Post;
public static readonly HttpMethod Put = HttpMethod.Put;
public static readonly HttpMethod Trace = HttpMethod.Trace;
public static readonly HttpMethod Patch = new HttpMethod("Patch");
} }
private sealed class QueryBuilder if (body is V1Patch patch)
{ {
private List<string> parameters = new List<string>(); return GetHeader(patch);
public void Append(string key, params object[] values)
{
foreach (var value in values)
{
switch (value)
{
case int intval:
parameters.Add($"{key}={intval}");
break;
case string strval:
parameters.Add($"{key}={Uri.EscapeDataString(strval)}");
break;
case bool boolval:
parameters.Add($"{key}={(boolval ? "true" : "false")}");
break;
default:
// null
break;
}
}
}
public override string ToString()
{
if (parameters.Count > 0)
{
return "?" + string.Join("&", parameters);
}
return "";
}
} }
private Task<HttpResponseMessage> SendRequest<T>(T body, HttpRequestMessage httpRequest, CancellationToken cancellationToken) return MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
{
if (body != null)
{
var requestContent = KubernetesJson.Serialize(body);
httpRequest.Content = new StringContent(requestContent, System.Text.Encoding.UTF8);
httpRequest.Content.Headers.ContentType = GetHeader(body);
return SendRequestRaw(requestContent, httpRequest, cancellationToken);
}
return SendRequestRaw("", httpRequest, cancellationToken);
}
public virtual TimeSpan HttpClientTimeout { get; set; } = TimeSpan.FromSeconds(100);
protected virtual MediaTypeHeaderValue GetHeader(object body)
{
if (body == null)
{
throw new ArgumentNullException(nameof(body));
}
if (body is V1Patch patch)
{
return GetHeader(patch);
}
return MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
}
private MediaTypeHeaderValue GetHeader(V1Patch body)
{
if (body == null)
{
throw new ArgumentNullException(nameof(body));
}
switch (body.Type)
{
case V1Patch.PatchType.JsonPatch:
return MediaTypeHeaderValue.Parse("application/json-patch+json; charset=utf-8");
case V1Patch.PatchType.MergePatch:
return MediaTypeHeaderValue.Parse("application/merge-patch+json; charset=utf-8");
case V1Patch.PatchType.StrategicMergePatch:
return MediaTypeHeaderValue.Parse("application/strategic-merge-patch+json; charset=utf-8");
case V1Patch.PatchType.ApplyPatch:
return MediaTypeHeaderValue.Parse("application/apply-patch+yaml; charset=utf-8");
default:
throw new ArgumentOutOfRangeException(nameof(body.Type), "");
}
}
protected abstract Task<HttpOperationResponse<T>> CreateResultAsync<T>(HttpRequestMessage httpRequest, HttpResponseMessage httpResponse, bool? watch, CancellationToken cancellationToken);
protected abstract HttpRequestMessage CreateRequest(string relativeUri, HttpMethod method, IReadOnlyDictionary<string, IReadOnlyList<string>> customHeaders);
protected abstract Task<HttpResponseMessage> SendRequestRaw(string requestContent, HttpRequestMessage httpRequest, CancellationToken cancellationToken);
} }
private MediaTypeHeaderValue GetHeader(V1Patch body)
{
if (body == null)
{
throw new ArgumentNullException(nameof(body));
}
switch (body.Type)
{
case V1Patch.PatchType.JsonPatch:
return MediaTypeHeaderValue.Parse("application/json-patch+json; charset=utf-8");
case V1Patch.PatchType.MergePatch:
return MediaTypeHeaderValue.Parse("application/merge-patch+json; charset=utf-8");
case V1Patch.PatchType.StrategicMergePatch:
return MediaTypeHeaderValue.Parse("application/strategic-merge-patch+json; charset=utf-8");
case V1Patch.PatchType.ApplyPatch:
return MediaTypeHeaderValue.Parse("application/apply-patch+yaml; charset=utf-8");
default:
throw new ArgumentOutOfRangeException(nameof(body.Type), "");
}
}
protected internal abstract Task<HttpOperationResponse<T>> CreateResultAsync<T>(HttpRequestMessage httpRequest, HttpResponseMessage httpResponse, bool? watch, CancellationToken cancellationToken);
protected internal abstract HttpRequestMessage CreateRequest(string relativeUri, HttpMethod method, IReadOnlyDictionary<string, IReadOnlyList<string>> customHeaders);
protected internal abstract Task<HttpResponseMessage> SendRequestRaw(string requestContent, HttpRequestMessage httpRequest, CancellationToken cancellationToken);
} }

View File

@@ -1,5 +1,5 @@
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("KubernetesClient")] [assembly: InternalsVisibleTo("KubernetesClient")]
[assembly: InternalsVisibleTo("KubernetesClient.VanillaRest")] [assembly: InternalsVisibleTo("KubernetesClient.Classic")]
[assembly: InternalsVisibleTo("KubernetesClient.Tests")] [assembly: InternalsVisibleTo("KubernetesClient.Tests")]

View File

@@ -5,8 +5,6 @@ using System.Globalization;
using System.Net.Http; using System.Net.Http;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace k8s.Autorest namespace k8s.Autorest
{ {

View File

@@ -2,8 +2,6 @@
// Licensed under the MIT License. See License.txt in the project root for license information. // Licensed under the MIT License. See License.txt in the project root for license information.
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
#pragma warning disable SA1606 #pragma warning disable SA1606
#pragma warning disable SA1614 #pragma warning disable SA1614

View File

@@ -2,8 +2,6 @@
// Licensed under the MIT License. See License.txt in the project root for license information. // Licensed under the MIT License. See License.txt in the project root for license information.
using System.Net.Http; using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
namespace k8s.Autorest namespace k8s.Autorest
{ {

View File

@@ -2,8 +2,6 @@
// Licensed under the MIT License. See License.txt in the project root for license information. // Licensed under the MIT License. See License.txt in the project root for license information.
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
namespace k8s.Autorest namespace k8s.Autorest
{ {

View File

@@ -2,8 +2,6 @@
// Licensed under the MIT License. See License.txt in the project root for license information. // Licensed under the MIT License. See License.txt in the project root for license information.
using System.Net.Http; using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
namespace k8s.Autorest namespace k8s.Autorest
{ {

View File

@@ -1,3 +1,8 @@
global using System; global using System;
global using System.Collections.Generic; global using System.Collections.Generic;
global using System.Linq; global using System.Linq;
global using k8s.Autorest;
global using k8s.Models;
global using System.IO;
global using System.Threading;
global using System.Threading.Tasks;

View File

@@ -0,0 +1,15 @@
using System.Net.Http;
namespace k8s;
internal static class HttpMethods
{
public static readonly HttpMethod Delete = HttpMethod.Delete;
public static readonly HttpMethod Get = HttpMethod.Get;
public static readonly HttpMethod Head = HttpMethod.Head;
public static readonly HttpMethod Options = HttpMethod.Options;
public static readonly HttpMethod Post = HttpMethod.Post;
public static readonly HttpMethod Put = HttpMethod.Put;
public static readonly HttpMethod Trace = HttpMethod.Trace;
public static readonly HttpMethod Patch = new HttpMethod("Patch");
}

View File

@@ -0,0 +1,43 @@
using System.Net.Http;
namespace k8s;
internal class Operations
{
private readonly AbstractKubernetes kubernetes;
public TimeSpan HttpClientTimeout => kubernetes.HttpClientTimeout;
public Operations(AbstractKubernetes kubernetes)
{
this.kubernetes = kubernetes;
}
protected Task<HttpResponseMessage> SendRequest<T>(T body, HttpRequestMessage httpRequest, CancellationToken cancellationToken)
{
if (body != null)
{
var requestContent = KubernetesJson.Serialize(body);
httpRequest.Content = new StringContent(requestContent, System.Text.Encoding.UTF8);
httpRequest.Content.Headers.ContentType = kubernetes.GetHeader(body);
return SendRequestRaw(requestContent, httpRequest, cancellationToken);
}
return SendRequestRaw("", httpRequest, cancellationToken);
}
internal Task<HttpOperationResponse<T>> CreateResultAsync<T>(HttpRequestMessage httpRequest, HttpResponseMessage httpResponse, bool? watch, CancellationToken cancellationToken)
{
return kubernetes.CreateResultAsync<T>(httpRequest, httpResponse, watch, cancellationToken);
}
internal HttpRequestMessage CreateRequest(string relativeUri, HttpMethod method, IReadOnlyDictionary<string, IReadOnlyList<string>> customHeaders)
{
return kubernetes.CreateRequest(relativeUri, method, customHeaders);
}
internal Task<HttpResponseMessage> SendRequestRaw(string requestContent, HttpRequestMessage httpRequest, CancellationToken cancellationToken)
{
return kubernetes.SendRequestRaw(requestContent, httpRequest, cancellationToken);
}
}

View File

@@ -0,0 +1,38 @@
namespace k8s;
internal sealed class QueryBuilder
{
private List<string> parameters = new List<string>();
public void Append(string key, params object[] values)
{
foreach (var value in values)
{
switch (value)
{
case int intval:
parameters.Add($"{key}={intval}");
break;
case string strval:
parameters.Add($"{key}={Uri.EscapeDataString(strval)}");
break;
case bool boolval:
parameters.Add($"{key}={(boolval ? "true" : "false")}");
break;
default:
// null
break;
}
}
}
public override string ToString()
{
if (parameters.Count > 0)
{
return "?" + string.Join("&", parameters);
}
return "";
}
}

View File

@@ -17,7 +17,7 @@ public partial class AsyncKubectl
public async Task<KubernetesSDKVersion> Version(CancellationToken cancellationToken = default) public async Task<KubernetesSDKVersion> Version(CancellationToken cancellationToken = default)
{ {
var serverVersion = await client.GetCodeAsync(cancellationToken).ConfigureAwait(false); var serverVersion = await client.Version.GetCodeAsync(cancellationToken).ConfigureAwait(false);
return new KubernetesSDKVersion { ServerVersion = serverVersion }; return new KubernetesSDKVersion { ServerVersion = serverVersion };
} }
} }

View File

@@ -1,5 +1,6 @@
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("KubernetesClient")] [assembly: InternalsVisibleTo("KubernetesClient")]
[assembly: InternalsVisibleTo("KubernetesClient.Classic")]
[assembly: InternalsVisibleTo("KubernetesClient.Basic")] [assembly: InternalsVisibleTo("KubernetesClient.Basic")]
[assembly: InternalsVisibleTo("KubernetesClient.Tests")] [assembly: InternalsVisibleTo("KubernetesClient.Tests")]

View File

@@ -140,21 +140,11 @@ namespace k8s.Versioning
.ForMember(dest => dest.User, opt => opt.Ignore()) .ForMember(dest => dest.User, opt => opt.Ignore())
.ReverseMap(); .ReverseMap();
cfg.CreateMap<V1alpha1RuntimeClass, V1RuntimeClass>()
.ForMember(dest => dest.Handler, opt => opt.MapFrom(src => src.Spec.RuntimeHandler))
.ForMember(dest => dest.Overhead, opt => opt.MapFrom(src => src.Spec.Overhead))
.ForMember(dest => dest.Scheduling, opt => opt.MapFrom(src => src.Spec.Scheduling))
.ReverseMap();
cfg.CreateMap<V1beta1RuntimeClass, V1RuntimeClass>() cfg.CreateMap<V1beta1RuntimeClass, V1RuntimeClass>()
.ForMember(dest => dest.Handler, opt => opt.MapFrom(src => src.Handler)) .ForMember(dest => dest.Handler, opt => opt.MapFrom(src => src.Handler))
.ForMember(dest => dest.Overhead, opt => opt.MapFrom(src => src.Overhead)) .ForMember(dest => dest.Overhead, opt => opt.MapFrom(src => src.Overhead))
.ForMember(dest => dest.Scheduling, opt => opt.MapFrom(src => src.Scheduling)) .ForMember(dest => dest.Scheduling, opt => opt.MapFrom(src => src.Scheduling))
.ReverseMap(); .ReverseMap();
cfg.CreateMap<V1alpha1RuntimeClass, V1beta1RuntimeClass>()
.ForMember(dest => dest.Handler, opt => opt.MapFrom(src => src.Spec.RuntimeHandler))
.ForMember(dest => dest.Overhead, opt => opt.MapFrom(src => src.Spec.Overhead))
.ForMember(dest => dest.Scheduling, opt => opt.MapFrom(src => src.Spec.Scheduling))
.ReverseMap();
cfg.CreateMap<V2beta1ResourceMetricStatus, V2beta2MetricValueStatus>() cfg.CreateMap<V2beta1ResourceMetricStatus, V2beta2MetricValueStatus>()
.ForMember(dest => dest.AverageValue, opt => opt.MapFrom(src => src.CurrentAverageValue)) .ForMember(dest => dest.AverageValue, opt => opt.MapFrom(src => src.CurrentAverageValue))
.ForMember(dest => dest.AverageUtilization, opt => opt.MapFrom(src => src.CurrentAverageUtilization)) .ForMember(dest => dest.AverageUtilization, opt => opt.MapFrom(src => src.CurrentAverageUtilization))

View File

@@ -33,56 +33,56 @@ namespace k8s
public async Task<T> CreateAsync<T>(T obj, CancellationToken cancel = default) public async Task<T> CreateAsync<T>(T obj, CancellationToken cancel = default)
where T : IKubernetesObject where T : IKubernetesObject
{ {
var resp = await kubernetes.CreateClusterCustomObjectWithHttpMessagesAsync(obj, group, version, plural, cancellationToken: cancel).ConfigureAwait(false); var resp = await kubernetes.CustomObjects.CreateClusterCustomObjectWithHttpMessagesAsync(obj, group, version, plural, cancellationToken: cancel).ConfigureAwait(false);
return KubernetesJson.Deserialize<T>(resp.Body.ToString()); return KubernetesJson.Deserialize<T>(resp.Body.ToString());
} }
public async Task<T> CreateNamespacedAsync<T>(T obj, string ns, CancellationToken cancel = default) public async Task<T> CreateNamespacedAsync<T>(T obj, string ns, CancellationToken cancel = default)
where T : IKubernetesObject where T : IKubernetesObject
{ {
var resp = await kubernetes.CreateNamespacedCustomObjectWithHttpMessagesAsync(obj, group, version, ns, plural, cancellationToken: cancel).ConfigureAwait(false); var resp = await kubernetes.CustomObjects.CreateNamespacedCustomObjectWithHttpMessagesAsync(obj, group, version, ns, plural, cancellationToken: cancel).ConfigureAwait(false);
return KubernetesJson.Deserialize<T>(resp.Body.ToString()); return KubernetesJson.Deserialize<T>(resp.Body.ToString());
} }
public async Task<T> ListAsync<T>(CancellationToken cancel = default) public async Task<T> ListAsync<T>(CancellationToken cancel = default)
where T : IKubernetesObject where T : IKubernetesObject
{ {
var resp = await kubernetes.ListClusterCustomObjectWithHttpMessagesAsync(group, version, plural, cancellationToken: cancel).ConfigureAwait(false); var resp = await kubernetes.CustomObjects.ListClusterCustomObjectWithHttpMessagesAsync(group, version, plural, cancellationToken: cancel).ConfigureAwait(false);
return KubernetesJson.Deserialize<T>(resp.Body.ToString()); return KubernetesJson.Deserialize<T>(resp.Body.ToString());
} }
public async Task<T> ListNamespacedAsync<T>(string ns, CancellationToken cancel = default) public async Task<T> ListNamespacedAsync<T>(string ns, CancellationToken cancel = default)
where T : IKubernetesObject where T : IKubernetesObject
{ {
var resp = await kubernetes.ListNamespacedCustomObjectWithHttpMessagesAsync(group, version, ns, plural, cancellationToken: cancel).ConfigureAwait(false); var resp = await kubernetes.CustomObjects.ListNamespacedCustomObjectWithHttpMessagesAsync(group, version, ns, plural, cancellationToken: cancel).ConfigureAwait(false);
return KubernetesJson.Deserialize<T>(resp.Body.ToString()); return KubernetesJson.Deserialize<T>(resp.Body.ToString());
} }
public async Task<T> ReadNamespacedAsync<T>(string ns, string name, CancellationToken cancel = default) public async Task<T> ReadNamespacedAsync<T>(string ns, string name, CancellationToken cancel = default)
where T : IKubernetesObject where T : IKubernetesObject
{ {
var resp = await kubernetes.GetNamespacedCustomObjectWithHttpMessagesAsync(group, version, ns, plural, name, cancellationToken: cancel).ConfigureAwait(false); var resp = await kubernetes.CustomObjects.GetNamespacedCustomObjectWithHttpMessagesAsync(group, version, ns, plural, name, cancellationToken: cancel).ConfigureAwait(false);
return KubernetesJson.Deserialize<T>(resp.Body.ToString()); return KubernetesJson.Deserialize<T>(resp.Body.ToString());
} }
public async Task<T> ReadAsync<T>(string name, CancellationToken cancel = default) public async Task<T> ReadAsync<T>(string name, CancellationToken cancel = default)
where T : IKubernetesObject where T : IKubernetesObject
{ {
var resp = await kubernetes.GetClusterCustomObjectWithHttpMessagesAsync(group, version, plural, name, cancellationToken: cancel).ConfigureAwait(false); var resp = await kubernetes.CustomObjects.GetClusterCustomObjectWithHttpMessagesAsync(group, version, plural, name, cancellationToken: cancel).ConfigureAwait(false);
return KubernetesJson.Deserialize<T>(resp.Body.ToString()); return KubernetesJson.Deserialize<T>(resp.Body.ToString());
} }
public async Task<T> DeleteAsync<T>(string name, CancellationToken cancel = default) public async Task<T> DeleteAsync<T>(string name, CancellationToken cancel = default)
where T : IKubernetesObject where T : IKubernetesObject
{ {
var resp = await kubernetes.DeleteClusterCustomObjectWithHttpMessagesAsync(group, version, plural, name, cancellationToken: cancel).ConfigureAwait(false); var resp = await kubernetes.CustomObjects.DeleteClusterCustomObjectWithHttpMessagesAsync(group, version, plural, name, cancellationToken: cancel).ConfigureAwait(false);
return KubernetesJson.Deserialize<T>(resp.Body.ToString()); return KubernetesJson.Deserialize<T>(resp.Body.ToString());
} }
public async Task<T> DeleteNamespacedAsync<T>(string ns, string name, CancellationToken cancel = default) public async Task<T> DeleteNamespacedAsync<T>(string ns, string name, CancellationToken cancel = default)
where T : IKubernetesObject where T : IKubernetesObject
{ {
var resp = await kubernetes.DeleteNamespacedCustomObjectWithHttpMessagesAsync(group, version, ns, plural, name, cancellationToken: cancel).ConfigureAwait(false); var resp = await kubernetes.CustomObjects.DeleteNamespacedCustomObjectWithHttpMessagesAsync(group, version, ns, plural, name, cancellationToken: cancel).ConfigureAwait(false);
return KubernetesJson.Deserialize<T>(resp.Body.ToString()); return KubernetesJson.Deserialize<T>(resp.Body.ToString());
} }

View File

@@ -55,7 +55,7 @@ namespace k8s
BaseUri = new Uri("http://localhost"); BaseUri = new Uri("http://localhost");
} }
protected override async Task<HttpOperationResponse<T>> CreateResultAsync<T>(HttpRequestMessage httpRequest, HttpResponseMessage httpResponse, bool? watch, CancellationToken cancellationToken) protected internal override async Task<HttpOperationResponse<T>> CreateResultAsync<T>(HttpRequestMessage httpRequest, HttpResponseMessage httpResponse, bool? watch, CancellationToken cancellationToken)
{ {
if (httpRequest == null) if (httpRequest == null)
{ {
@@ -99,7 +99,7 @@ namespace k8s
return result; return result;
} }
protected override HttpRequestMessage CreateRequest(string relativeUri, HttpMethod method, IReadOnlyDictionary<string, IReadOnlyList<string>> customHeaders) protected internal override HttpRequestMessage CreateRequest(string relativeUri, HttpMethod method, IReadOnlyDictionary<string, IReadOnlyList<string>> customHeaders)
{ {
var httpRequest = new HttpRequestMessage(); var httpRequest = new HttpRequestMessage();
httpRequest.Method = method; httpRequest.Method = method;
@@ -120,7 +120,7 @@ namespace k8s
return httpRequest; return httpRequest;
} }
protected override async Task<HttpResponseMessage> SendRequestRaw(string requestContent, HttpRequestMessage httpRequest, CancellationToken cancellationToken) protected internal override async Task<HttpResponseMessage> SendRequestRaw(string requestContent, HttpRequestMessage httpRequest, CancellationToken cancellationToken)
{ {
if (httpRequest == null) if (httpRequest == null)
{ {

View File

@@ -15,7 +15,7 @@ namespace k8s
/// <returns>the metrics <see cref="PodMetricsList"/></returns> /// <returns>the metrics <see cref="PodMetricsList"/></returns>
public static async Task<NodeMetricsList> GetKubernetesNodesMetricsAsync(this IKubernetes kubernetes) public static async Task<NodeMetricsList> GetKubernetesNodesMetricsAsync(this IKubernetes kubernetes)
{ {
var customObject = (JsonElement)await kubernetes.GetClusterCustomObjectAsync("metrics.k8s.io", "v1beta1", "nodes", string.Empty).ConfigureAwait(false); var customObject = (JsonElement)await kubernetes.CustomObjects.GetClusterCustomObjectAsync("metrics.k8s.io", "v1beta1", "nodes", string.Empty).ConfigureAwait(false);
return customObject.Deserialize<NodeMetricsList>(); return customObject.Deserialize<NodeMetricsList>();
} }
@@ -26,7 +26,7 @@ namespace k8s
/// <returns>the metrics <see cref="PodMetricsList"/></returns> /// <returns>the metrics <see cref="PodMetricsList"/></returns>
public static async Task<PodMetricsList> GetKubernetesPodsMetricsAsync(this IKubernetes kubernetes) public static async Task<PodMetricsList> GetKubernetesPodsMetricsAsync(this IKubernetes kubernetes)
{ {
var customObject = (JsonElement)await kubernetes.GetClusterCustomObjectAsync("metrics.k8s.io", "v1beta1", "pods", string.Empty).ConfigureAwait(false); var customObject = (JsonElement)await kubernetes.CustomObjects.GetClusterCustomObjectAsync("metrics.k8s.io", "v1beta1", "pods", string.Empty).ConfigureAwait(false);
return customObject.Deserialize<PodMetricsList>(); return customObject.Deserialize<PodMetricsList>();
} }
@@ -38,7 +38,7 @@ namespace k8s
/// <returns>the metrics <see cref="PodMetricsList"/></returns> /// <returns>the metrics <see cref="PodMetricsList"/></returns>
public static async Task<PodMetricsList> GetKubernetesPodsMetricsByNamespaceAsync(this IKubernetes kubernetes, string namespaceParameter) public static async Task<PodMetricsList> GetKubernetesPodsMetricsByNamespaceAsync(this IKubernetes kubernetes, string namespaceParameter)
{ {
var customObject = (JsonElement)await kubernetes.GetNamespacedCustomObjectAsync("metrics.k8s.io", "v1beta1", namespaceParameter, "pods", string.Empty).ConfigureAwait(false); var customObject = (JsonElement)await kubernetes.CustomObjects.GetNamespacedCustomObjectAsync("metrics.k8s.io", "v1beta1", namespaceParameter, "pods", string.Empty).ConfigureAwait(false);
return customObject.Deserialize<PodMetricsList>(); return customObject.Deserialize<PodMetricsList>();
} }
} }

View File

@@ -15,21 +15,21 @@ namespace k8s.LeaderElection.ResourceLock
string namespaceParameter, string namespaceParameter,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
return client.ReadNamespacedConfigMapAsync(name, namespaceParameter, cancellationToken: cancellationToken); return client.CoreV1.ReadNamespacedConfigMapAsync(name, namespaceParameter, cancellationToken: cancellationToken);
} }
protected override Task<V1ConfigMap> CreateMetaObjectAsync(IKubernetes client, V1ConfigMap obj, protected override Task<V1ConfigMap> CreateMetaObjectAsync(IKubernetes client, V1ConfigMap obj,
string namespaceParameter, string namespaceParameter,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
return client.CreateNamespacedConfigMapAsync(obj, namespaceParameter, cancellationToken: cancellationToken); return client.CoreV1.CreateNamespacedConfigMapAsync(obj, namespaceParameter, cancellationToken: cancellationToken);
} }
protected override Task<V1ConfigMap> ReplaceMetaObjectAsync(IKubernetes client, V1ConfigMap obj, string name, protected override Task<V1ConfigMap> ReplaceMetaObjectAsync(IKubernetes client, V1ConfigMap obj, string name,
string namespaceParameter, string namespaceParameter,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
return client.ReplaceNamespacedConfigMapAsync(obj, name, namespaceParameter, return client.CoreV1.ReplaceNamespacedConfigMapAsync(obj, name, namespaceParameter,
cancellationToken: cancellationToken); cancellationToken: cancellationToken);
} }
} }

View File

@@ -13,19 +13,19 @@ namespace k8s.LeaderElection.ResourceLock
protected override Task<V1Endpoints> ReadMetaObjectAsync(IKubernetes client, string name, string namespaceParameter, CancellationToken cancellationToken) protected override Task<V1Endpoints> ReadMetaObjectAsync(IKubernetes client, string name, string namespaceParameter, CancellationToken cancellationToken)
{ {
return client.ReadNamespacedEndpointsAsync(name, namespaceParameter, cancellationToken: cancellationToken); return client.CoreV1.ReadNamespacedEndpointsAsync(name, namespaceParameter, cancellationToken: cancellationToken);
} }
protected override Task<V1Endpoints> CreateMetaObjectAsync(IKubernetes client, V1Endpoints obj, string namespaceParameter, protected override Task<V1Endpoints> CreateMetaObjectAsync(IKubernetes client, V1Endpoints obj, string namespaceParameter,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
return client.CreateNamespacedEndpointsAsync(obj, namespaceParameter, cancellationToken: cancellationToken); return client.CoreV1.CreateNamespacedEndpointsAsync(obj, namespaceParameter, cancellationToken: cancellationToken);
} }
protected override Task<V1Endpoints> ReplaceMetaObjectAsync(IKubernetes client, V1Endpoints obj, string name, string namespaceParameter, protected override Task<V1Endpoints> ReplaceMetaObjectAsync(IKubernetes client, V1Endpoints obj, string name, string namespaceParameter,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
return client.ReplaceNamespacedEndpointsAsync(obj, name, namespaceParameter, cancellationToken: cancellationToken); return client.CoreV1.ReplaceNamespacedEndpointsAsync(obj, name, namespaceParameter, cancellationToken: cancellationToken);
} }
} }
} }

View File

@@ -14,7 +14,7 @@ namespace k8s.LeaderElection.ResourceLock
protected override Task<V1Lease> ReadMetaObjectAsync(IKubernetes client, string name, string namespaceParameter, protected override Task<V1Lease> ReadMetaObjectAsync(IKubernetes client, string name, string namespaceParameter,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
return client.ReadNamespacedLeaseAsync(name, namespaceParameter, cancellationToken: cancellationToken); return client.CoordinationV1.ReadNamespacedLeaseAsync(name, namespaceParameter, cancellationToken: cancellationToken);
} }
protected override LeaderElectionRecord GetLeaderElectionRecord(V1Lease obj) protected override LeaderElectionRecord GetLeaderElectionRecord(V1Lease obj)
@@ -61,13 +61,13 @@ namespace k8s.LeaderElection.ResourceLock
protected override Task<V1Lease> CreateMetaObjectAsync(IKubernetes client, V1Lease obj, string namespaceParameter, protected override Task<V1Lease> CreateMetaObjectAsync(IKubernetes client, V1Lease obj, string namespaceParameter,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
return client.CreateNamespacedLeaseAsync(obj, namespaceParameter, cancellationToken: cancellationToken); return client.CoordinationV1.CreateNamespacedLeaseAsync(obj, namespaceParameter, cancellationToken: cancellationToken);
} }
protected override Task<V1Lease> ReplaceMetaObjectAsync(IKubernetes client, V1Lease obj, string name, string namespaceParameter, protected override Task<V1Lease> ReplaceMetaObjectAsync(IKubernetes client, V1Lease obj, string name, string namespaceParameter,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
return client.ReplaceNamespacedLeaseAsync(obj, name, namespaceParameter, cancellationToken: cancellationToken); return client.CoordinationV1.ReplaceNamespacedLeaseAsync(obj, name, namespaceParameter, cancellationToken: cancellationToken);
} }
} }
} }

View File

@@ -229,7 +229,7 @@ namespace k8s.Util.Common.Generic
throw new ArgumentNullException(nameof(name)); throw new ArgumentNullException(nameof(name));
} }
var resp = await _client.GetClusterCustomObjectWithHttpMessagesAsync(group: _apiGroup, plural: _resourcePlural, version: _apiVersion, name: name, cancellationToken: cancellationToken) var resp = await _client.CustomObjects.GetClusterCustomObjectWithHttpMessagesAsync(group: _apiGroup, plural: _resourcePlural, version: _apiVersion, name: name, cancellationToken: cancellationToken)
.ConfigureAwait(false); .ConfigureAwait(false);
return KubernetesJson.Deserialize<T>(resp.Body.ToString()); return KubernetesJson.Deserialize<T>(resp.Body.ToString());
} }
@@ -256,7 +256,7 @@ namespace k8s.Util.Common.Generic
throw new ArgumentNullException(nameof(namespaceProperty)); throw new ArgumentNullException(nameof(namespaceProperty));
} }
var resp = await _client.GetNamespacedCustomObjectWithHttpMessagesAsync(group: _apiGroup, plural: _resourcePlural, version: _apiVersion, name: name, namespaceParameter: namespaceProperty, var resp = await _client.CustomObjects.GetNamespacedCustomObjectWithHttpMessagesAsync(group: _apiGroup, plural: _resourcePlural, version: _apiVersion, name: name, namespaceParameter: namespaceProperty,
cancellationToken: cancellationToken).ConfigureAwait(false); cancellationToken: cancellationToken).ConfigureAwait(false);
return KubernetesJson.Deserialize<T>(resp.Body.ToString()); return KubernetesJson.Deserialize<T>(resp.Body.ToString());
} }
@@ -276,7 +276,7 @@ namespace k8s.Util.Common.Generic
throw new ArgumentNullException(nameof(listOptions)); throw new ArgumentNullException(nameof(listOptions));
} }
var resp = await _client.ListClusterCustomObjectWithHttpMessagesAsync(group: _apiGroup, plural: _resourcePlural, version: _apiVersion, resourceVersion: listOptions.ResourceVersion, var resp = await _client.CustomObjects.ListClusterCustomObjectWithHttpMessagesAsync(group: _apiGroup, plural: _resourcePlural, version: _apiVersion, resourceVersion: listOptions.ResourceVersion,
continueParameter: listOptions.Continue, fieldSelector: listOptions.FieldSelector, labelSelector: listOptions.LabelSelector, limit: listOptions.Limit, continueParameter: listOptions.Continue, fieldSelector: listOptions.FieldSelector, labelSelector: listOptions.LabelSelector, limit: listOptions.Limit,
timeoutSeconds: listOptions.TimeoutSeconds, cancellationToken: cancellationToken).ConfigureAwait(false); timeoutSeconds: listOptions.TimeoutSeconds, cancellationToken: cancellationToken).ConfigureAwait(false);
return KubernetesJson.Deserialize<T>(resp.Body.ToString()); return KubernetesJson.Deserialize<T>(resp.Body.ToString());
@@ -303,7 +303,7 @@ namespace k8s.Util.Common.Generic
throw new ArgumentNullException(nameof(namespaceProperty)); throw new ArgumentNullException(nameof(namespaceProperty));
} }
var resp = await _client.ListNamespacedCustomObjectWithHttpMessagesAsync(group: _apiGroup, plural: _resourcePlural, version: _apiVersion, resourceVersion: listOptions.ResourceVersion, var resp = await _client.CustomObjects.ListNamespacedCustomObjectWithHttpMessagesAsync(group: _apiGroup, plural: _resourcePlural, version: _apiVersion, resourceVersion: listOptions.ResourceVersion,
continueParameter: listOptions.Continue, fieldSelector: listOptions.FieldSelector, labelSelector: listOptions.LabelSelector, limit: listOptions.Limit, continueParameter: listOptions.Continue, fieldSelector: listOptions.FieldSelector, labelSelector: listOptions.LabelSelector, limit: listOptions.Limit,
timeoutSeconds: listOptions.TimeoutSeconds, namespaceParameter: namespaceProperty, cancellationToken: cancellationToken).ConfigureAwait(false); timeoutSeconds: listOptions.TimeoutSeconds, namespaceParameter: namespaceProperty, cancellationToken: cancellationToken).ConfigureAwait(false);
@@ -339,7 +339,7 @@ namespace k8s.Util.Common.Generic
return await CreateAsync(objectMeta.NamespaceProperty, obj, createOptions, cancellationToken).ConfigureAwait(false); return await CreateAsync(objectMeta.NamespaceProperty, obj, createOptions, cancellationToken).ConfigureAwait(false);
} }
var resp = await _client.CreateClusterCustomObjectWithHttpMessagesAsync(body: obj, group: _apiGroup, plural: _resourcePlural, version: _apiVersion, dryRun: createOptions.DryRun, var resp = await _client.CustomObjects.CreateClusterCustomObjectWithHttpMessagesAsync(body: obj, group: _apiGroup, plural: _resourcePlural, version: _apiVersion, dryRun: createOptions.DryRun,
fieldManager: createOptions.FieldManager, cancellationToken: cancellationToken).ConfigureAwait(false); fieldManager: createOptions.FieldManager, cancellationToken: cancellationToken).ConfigureAwait(false);
return KubernetesJson.Deserialize<T>(resp.Body.ToString()); return KubernetesJson.Deserialize<T>(resp.Body.ToString());
@@ -367,7 +367,7 @@ namespace k8s.Util.Common.Generic
throw new ArgumentNullException(nameof(createOptions)); throw new ArgumentNullException(nameof(createOptions));
} }
var resp = await _client.CreateNamespacedCustomObjectWithHttpMessagesAsync(body: obj, group: _apiGroup, plural: _resourcePlural, version: _apiVersion, var resp = await _client.CustomObjects.CreateNamespacedCustomObjectWithHttpMessagesAsync(body: obj, group: _apiGroup, plural: _resourcePlural, version: _apiVersion,
namespaceParameter: namespaceProperty, dryRun: createOptions.DryRun, fieldManager: createOptions.FieldManager, cancellationToken: cancellationToken).ConfigureAwait(false); namespaceParameter: namespaceProperty, dryRun: createOptions.DryRun, fieldManager: createOptions.FieldManager, cancellationToken: cancellationToken).ConfigureAwait(false);
return KubernetesJson.Deserialize<T>(resp.Body.ToString()); return KubernetesJson.Deserialize<T>(resp.Body.ToString());
@@ -400,13 +400,13 @@ namespace k8s.Util.Common.Generic
HttpOperationResponse<object> resp; HttpOperationResponse<object> resp;
if (isNamespaced) if (isNamespaced)
{ {
resp = await _client.ReplaceNamespacedCustomObjectWithHttpMessagesAsync(body: obj, name: objectMeta.Name, group: _apiGroup, plural: _resourcePlural, version: _apiVersion, resp = await _client.CustomObjects.ReplaceNamespacedCustomObjectWithHttpMessagesAsync(body: obj, name: objectMeta.Name, group: _apiGroup, plural: _resourcePlural, version: _apiVersion,
namespaceParameter: objectMeta.NamespaceProperty, dryRun: updateOptions.DryRun, fieldManager: updateOptions.FieldManager, cancellationToken: cancellationToken) namespaceParameter: objectMeta.NamespaceProperty, dryRun: updateOptions.DryRun, fieldManager: updateOptions.FieldManager, cancellationToken: cancellationToken)
.ConfigureAwait(false); .ConfigureAwait(false);
} }
else else
{ {
resp = await _client.ReplaceClusterCustomObjectWithHttpMessagesAsync(body: obj, name: objectMeta.Name, group: _apiGroup ?? obj.ApiGroup(), plural: _resourcePlural, resp = await _client.CustomObjects.ReplaceClusterCustomObjectWithHttpMessagesAsync(body: obj, name: objectMeta.Name, group: _apiGroup ?? obj.ApiGroup(), plural: _resourcePlural,
version: _apiVersion, dryRun: updateOptions.DryRun, fieldManager: updateOptions.FieldManager, cancellationToken: cancellationToken).ConfigureAwait(false); version: _apiVersion, dryRun: updateOptions.DryRun, fieldManager: updateOptions.FieldManager, cancellationToken: cancellationToken).ConfigureAwait(false);
} }
@@ -455,13 +455,13 @@ namespace k8s.Util.Common.Generic
var isNamespaced = !string.IsNullOrEmpty(objectMeta.NamespaceProperty); var isNamespaced = !string.IsNullOrEmpty(objectMeta.NamespaceProperty);
if (isNamespaced) if (isNamespaced)
{ {
resp = await _client.PatchNamespacedCustomObjectStatusWithHttpMessagesAsync(body: obj, group: _apiGroup, version: _apiVersion, namespaceParameter: objectMeta.NamespaceProperty, resp = await _client.CustomObjects.PatchNamespacedCustomObjectStatusWithHttpMessagesAsync(body: obj, group: _apiGroup, version: _apiVersion, namespaceParameter: objectMeta.NamespaceProperty,
plural: _resourcePlural, name: objectMeta.Name, dryRun: updateOptions.DryRun, fieldManager: updateOptions.FieldManager, force: updateOptions.Force, plural: _resourcePlural, name: objectMeta.Name, dryRun: updateOptions.DryRun, fieldManager: updateOptions.FieldManager, force: updateOptions.Force,
cancellationToken: cancellationToken).ConfigureAwait(false); cancellationToken: cancellationToken).ConfigureAwait(false);
} }
else else
{ {
resp = await _client.PatchClusterCustomObjectStatusWithHttpMessagesAsync(body: obj, group: _apiGroup, version: _apiVersion, plural: _resourcePlural, name: objectMeta.Name, resp = await _client.CustomObjects.PatchClusterCustomObjectStatusWithHttpMessagesAsync(body: obj, group: _apiGroup, version: _apiVersion, plural: _resourcePlural, name: objectMeta.Name,
dryRun: updateOptions.DryRun, fieldManager: updateOptions.FieldManager, force: updateOptions.Force, cancellationToken: cancellationToken).ConfigureAwait(false); dryRun: updateOptions.DryRun, fieldManager: updateOptions.FieldManager, force: updateOptions.Force, cancellationToken: cancellationToken).ConfigureAwait(false);
} }
@@ -495,7 +495,7 @@ namespace k8s.Util.Common.Generic
throw new ArgumentNullException(nameof(name)); throw new ArgumentNullException(nameof(name));
} }
var resp = await _client.PatchClusterCustomObjectWithHttpMessagesAsync(body: obj, group: _apiGroup, version: _apiVersion, plural: _resourcePlural, name: name, dryRun: patchOptions.DryRun, var resp = await _client.CustomObjects.PatchClusterCustomObjectWithHttpMessagesAsync(body: obj, group: _apiGroup, version: _apiVersion, plural: _resourcePlural, name: name, dryRun: patchOptions.DryRun,
fieldManager: patchOptions.FieldManager, force: patchOptions.Force, cancellationToken: cancellationToken).ConfigureAwait(false); fieldManager: patchOptions.FieldManager, force: patchOptions.Force, cancellationToken: cancellationToken).ConfigureAwait(false);
return KubernetesJson.Deserialize<T>(resp.Body.ToString()); return KubernetesJson.Deserialize<T>(resp.Body.ToString());
} }
@@ -533,7 +533,7 @@ namespace k8s.Util.Common.Generic
throw new ArgumentNullException(nameof(patchOptions)); throw new ArgumentNullException(nameof(patchOptions));
} }
var resp = await _client.PatchNamespacedCustomObjectWithHttpMessagesAsync(body: obj, group: _apiGroup, version: _apiVersion, namespaceParameter: namespaceProperty, plural: _resourcePlural, var resp = await _client.CustomObjects.PatchNamespacedCustomObjectWithHttpMessagesAsync(body: obj, group: _apiGroup, version: _apiVersion, namespaceParameter: namespaceProperty, plural: _resourcePlural,
name: name, dryRun: patchOptions.DryRun, fieldManager: patchOptions.FieldManager, force: patchOptions.Force, cancellationToken: cancellationToken).ConfigureAwait(false); name: name, dryRun: patchOptions.DryRun, fieldManager: patchOptions.FieldManager, force: patchOptions.Force, cancellationToken: cancellationToken).ConfigureAwait(false);
return KubernetesJson.Deserialize<T>(resp.Body.ToString()); return KubernetesJson.Deserialize<T>(resp.Body.ToString());
} }
@@ -554,7 +554,7 @@ namespace k8s.Util.Common.Generic
throw new ArgumentNullException(nameof(name)); throw new ArgumentNullException(nameof(name));
} }
var resp = await _client.DeleteClusterCustomObjectWithHttpMessagesAsync( var resp = await _client.CustomObjects.DeleteClusterCustomObjectWithHttpMessagesAsync(
group: _apiGroup, version: _apiVersion, plural: _resourcePlural, name: name, body: deleteOptions, cancellationToken: cancellationToken).ConfigureAwait(false); group: _apiGroup, version: _apiVersion, plural: _resourcePlural, name: name, body: deleteOptions, cancellationToken: cancellationToken).ConfigureAwait(false);
return KubernetesJson.Deserialize<T>(resp.Body.ToString()); return KubernetesJson.Deserialize<T>(resp.Body.ToString());
} }
@@ -581,7 +581,7 @@ namespace k8s.Util.Common.Generic
throw new ArgumentNullException(nameof(name)); throw new ArgumentNullException(nameof(name));
} }
var resp = await _client.DeleteNamespacedCustomObjectWithHttpMessagesAsync(group: _apiGroup, version: _apiVersion, namespaceParameter: namespaceProperty, plural: _resourcePlural, var resp = await _client.CustomObjects.DeleteNamespacedCustomObjectWithHttpMessagesAsync(group: _apiGroup, version: _apiVersion, namespaceParameter: namespaceProperty, plural: _resourcePlural,
name: name, body: deleteOptions, cancellationToken: cancellationToken).ConfigureAwait(false); name: name, body: deleteOptions, cancellationToken: cancellationToken).ConfigureAwait(false);
return KubernetesJson.Deserialize<T>(resp.Body.ToString()); return KubernetesJson.Deserialize<T>(resp.Body.ToString());
} }
@@ -605,7 +605,7 @@ namespace k8s.Util.Common.Generic
throw new ArgumentNullException(nameof(listOptions)); throw new ArgumentNullException(nameof(listOptions));
} }
var resp = _client.ListClusterCustomObjectWithHttpMessagesAsync(group: _apiGroup, version: _apiVersion, plural: _resourcePlural, continueParameter: listOptions.Continue, var resp = _client.CustomObjects.ListClusterCustomObjectWithHttpMessagesAsync(group: _apiGroup, version: _apiVersion, plural: _resourcePlural, continueParameter: listOptions.Continue,
fieldSelector: listOptions.FieldSelector, labelSelector: listOptions.LabelSelector, limit: listOptions.Limit, resourceVersion: listOptions.ResourceVersion, fieldSelector: listOptions.FieldSelector, labelSelector: listOptions.LabelSelector, limit: listOptions.Limit, resourceVersion: listOptions.ResourceVersion,
timeoutSeconds: listOptions.TimeoutSeconds, watch: true, cancellationToken: cancellationToken); timeoutSeconds: listOptions.TimeoutSeconds, watch: true, cancellationToken: cancellationToken);
@@ -637,7 +637,7 @@ namespace k8s.Util.Common.Generic
throw new ArgumentNullException(nameof(namespaceProperty)); throw new ArgumentNullException(nameof(namespaceProperty));
} }
var resp = _client.ListNamespacedCustomObjectWithHttpMessagesAsync(group: _apiGroup, version: _apiVersion, namespaceParameter: namespaceProperty, plural: _resourcePlural, var resp = _client.CustomObjects.ListNamespacedCustomObjectWithHttpMessagesAsync(group: _apiGroup, version: _apiVersion, namespaceParameter: namespaceProperty, plural: _resourcePlural,
continueParameter: listOptions.Continue, fieldSelector: listOptions.FieldSelector, labelSelector: listOptions.LabelSelector, limit: listOptions.Limit, continueParameter: listOptions.Continue, fieldSelector: listOptions.FieldSelector, labelSelector: listOptions.LabelSelector, limit: listOptions.Limit,
resourceVersion: listOptions.ResourceVersion, timeoutSeconds: listOptions.TimeoutSeconds, watch: true, cancellationToken: cancellationToken); resourceVersion: listOptions.ResourceVersion, timeoutSeconds: listOptions.TimeoutSeconds, watch: true, cancellationToken: cancellationToken);

View File

@@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using CaseExtensions;
using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis;
using NSwag; using NSwag;
@@ -11,19 +12,6 @@ namespace LibKubernetesGenerator
{ {
var data = swagger.Operations var data = swagger.Operations
.Where(o => o.Method != OpenApiOperationMethod.Options) .Where(o => o.Method != OpenApiOperationMethod.Options)
.GroupBy(o => o.Operation.OperationId)
.Select(g =>
{
var gs = g.ToArray();
for (var i = 1; i < g.Count(); i++)
{
gs[i].Operation.OperationId += i;
}
return gs;
})
.SelectMany(g => g)
.Select(o => .Select(o =>
{ {
var ps = o.Operation.ActualParameters.OrderBy(p => !p.IsRequired).ToArray(); var ps = o.Operation.ActualParameters.OrderBy(p => !p.IsRequired).ToArray();
@@ -54,9 +42,22 @@ namespace LibKubernetesGenerator
}) })
.ToArray(); .ToArray();
context.RenderToContext("IKubernetes.cs.template", data, "IKubernetes.g.cs"); var groups = new List<string>();
context.RenderToContext("Kubernetes.cs.template", data, "Kubernetes.g.cs");
context.RenderToContext("KubernetesExtensions.cs.template", data, "KubernetesExtensions.g.cs"); foreach (var grouped in data.GroupBy(d => d.Operation.Tags.First()))
{
var name = grouped.Key.ToPascalCase();
groups.Add(name);
var apis = grouped.ToArray();
var gctx = new { name, apis };
context.RenderToContext($"IOperations.cs.template", gctx, $"I{name}Operations.g.cs");
context.RenderToContext("Operations.cs.template", gctx, $"{name}Operations.g.cs");
context.RenderToContext("OperationsExtensions.cs.template", gctx, $"{name}OperationsExtensions.g.cs");
}
context.RenderToContext($"IBasicKubernetes.cs.template", groups, $"IBasicKubernetes.g.cs");
context.RenderToContext($"AbstractKubernetes.cs.template", groups, $"AbstractKubernetes.g.cs");
} }
} }
} }

View File

@@ -0,0 +1,16 @@
// <auto-generated>
// Code generated by https://github.com/kubernetes-client/csharp/tree/master/src/LibKubernetesGenerator
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.
// </auto-generated>
namespace k8s;
/// <summary>
/// </summary>
public abstract partial class AbstractKubernetes
{
{{#.}}
public I{{.}}Operations {{.}} => new {{.}}Operations(this);
{{/.}}
}

View File

@@ -0,0 +1,16 @@
// <auto-generated>
// Code generated by https://github.com/kubernetes-client/csharp/tree/master/src/LibKubernetesGenerator
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.
// </auto-generated>
namespace k8s;
/// <summary>
/// </summary>
public partial interface IBasicKubernetes
{
{{#.}}
I{{.}}Operations {{.}} { get; }
{{/.}}
}

View File

@@ -1,46 +0,0 @@
// <auto-generated>
// Code generated by https://github.com/kubernetes-client/csharp/tree/master/src/LibKubernetesGenerator
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.
// </auto-generated>
namespace k8s
{
using k8s.Autorest;
using Models;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
/// <summary>
/// </summary>
public partial interface IBasicKubernetes
{
{{#.}}
/// <summary>
/// {{ToXmlDoc operation.description}}
/// </summary>
{{#operation.parameters}}
/// <param name="{{GetDotNetName .}}">
/// {{ToXmlDoc description}}
/// </param>
{{/operation.parameters}}
/// <param name="customHeaders">
/// The headers that will be added to request.
/// </param>
/// <param name="cancellationToken">
/// A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation.
/// </param>
Task<HttpOperationResponse{{GetReturnType operation "<>"}}> {{GetMethodName operation "WithHttpMessagesAsync"}}(
{{#operation.parameters}}
{{GetDotNetType .}} {{GetDotNetName . "true"}},
{{/operation.parameters}}
IReadOnlyDictionary<string, IReadOnlyList<string>> customHeaders = null,
CancellationToken cancellationToken = default);
{{/.}}
}
}

View File

@@ -0,0 +1,36 @@
// <auto-generated>
// Code generated by https://github.com/kubernetes-client/csharp/tree/master/src/LibKubernetesGenerator
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.
// </auto-generated>
namespace k8s;
/// <summary>
/// </summary>
public partial interface I{{name}}Operations
{
{{#apis}}
/// <summary>
/// {{ToXmlDoc operation.description}}
/// </summary>
{{#operation.parameters}}
/// <param name="{{GetDotNetName .}}">
/// {{ToXmlDoc description}}
/// </param>
{{/operation.parameters}}
/// <param name="customHeaders">
/// The headers that will be added to request.
/// </param>
/// <param name="cancellationToken">
/// A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation.
/// </param>
Task<HttpOperationResponse{{GetReturnType operation "<>"}}> {{GetMethodName operation "WithHttpMessagesAsync"}}(
{{#operation.parameters}}
{{GetDotNetType .}} {{GetDotNetName . "true"}},
{{/operation.parameters}}
IReadOnlyDictionary<string, IReadOnlyList<string>> customHeaders = null,
CancellationToken cancellationToken = default);
{{/apis}}
}

View File

@@ -1,96 +0,0 @@
// <auto-generated>
// Code generated by https://github.com/kubernetes-client/csharp/tree/master/src/LibKubernetesGenerator
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.
// </auto-generated>
namespace k8s
{
using k8s.Autorest;
using Models;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
public partial class AbstractKubernetes : IBasicKubernetes
{
{{#.}}
/// <inheritdoc/>
public async Task<HttpOperationResponse{{GetReturnType operation "<>"}}> {{GetMethodName operation "WithHttpMessagesAsync"}}(
{{#operation.parameters}}
{{GetDotNetType .}} {{GetDotNetName . "true"}},
{{/operation.parameters}}
IReadOnlyDictionary<string, IReadOnlyList<string>> customHeaders = null,
CancellationToken cancellationToken = default(CancellationToken))
{
var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
cts.CancelAfter(HttpClientTimeout);
{{#IfParamContains operation "watch"}}
if (watch == true)
{
cts.CancelAfter(Timeout.InfiniteTimeSpan);
}
{{/IfParamContains operation "watch"}}
cancellationToken = cts.Token;
{{#operation.parameters}}
{{#isRequired}}
if ({{GetDotNetName name}} == null)
{
throw new ArgumentNullException("{{GetDotNetName name}}");
}
{{/isRequired}}
{{/operation.parameters}}
// Construct URL
var url = $"{{ToInterpolationPathString path}}";
{{#IfGroupPathParamContainsGroup path}}
url = url.Replace("apis//", "api/");
{{/IfGroupPathParamContainsGroup}}
{{#IfListNotEmpty operation.parameters}}
var q = new QueryBuilder();
{{#operation.parameters}}
{{#IfKindIs . "query"}}
q.Append("{{name}}", {{GetDotNetName name}});
{{/IfKindIs . "query"}}
{{/operation.parameters}}
url += q.ToString();
{{/IfListNotEmpty operation.parameters}}
// Create HTTP transport
var httpRequest = CreateRequest(url, HttpMethods.{{Method}}, customHeaders);
{{#IfParamContains operation "body"}}
var httpResponse = await SendRequest(body, httpRequest, cancellationToken);
{{/IfParamContains operation "body"}}
{{#IfParamDoesNotContain operation "body"}}
var httpResponse = await SendRequestRaw("", httpRequest, cancellationToken);
{{/IfParamDoesNotContain operation "body"}}
// Create Result
{{#IfReturnType operation "void"}}
HttpOperationResponse result = new HttpOperationResponse() { Request = httpRequest, Response = httpResponse };
{{/IfReturnType operation "void"}}
{{#IfReturnType operation "obj"}}
var result = await CreateResultAsync{{GetReturnType operation "<>"}}(httpRequest,
httpResponse,
{{#IfParamContains operation "watch"}}
watch,
{{/IfParamContains operation "watch"}}
{{#IfParamDoesNotContain operation "watch"}}
false,
{{/IfParamDoesNotContain operation "watch"}}
cancellationToken);
{{/IfReturnType operation "obj"}}
{{#IfReturnType operation "stream"}}
var result = new HttpOperationResponse{{GetReturnType operation "<>"}}() {
Request = httpRequest,
Response = httpResponse,
Body = await httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false) };
{{/IfReturnType operation "stream"}}
return result;
}
{{/.}}
}
}

View File

@@ -1,102 +0,0 @@
// <auto-generated>
// Code generated by https://github.com/kubernetes-client/csharp/tree/master/src/LibKubernetesGenerator
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.
// </auto-generated>
namespace k8s
{
using Models;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
/// <summary>
/// Extension methods for Kubernetes.
/// </summary>
public static partial class KubernetesExtensions
{
{{#.}}
/// <summary>
/// {{ToXmlDoc operation.description}}
/// </summary>
/// <param name='operations'>
/// The operations group for this extension method.
/// </param>
{{#operation.parameters}}
/// <param name="{{GetDotNetName .}}">
/// {{ToXmlDoc description}}
/// </param>
{{/operation.parameters}}
public static {{GetReturnType operation "void"}} {{GetMethodName operation ""}}(
this IBasicKubernetes operations
{{#operation.parameters}}
,{{GetDotNetType .}} {{GetDotNetName . "true"}}
{{/operation.parameters}}
)
{
{{GetReturnType operation "return"}} operations.{{GetMethodName operation "Async"}}(
{{#operation.parameters}}
{{GetDotNetName .}},
{{/operation.parameters}}
CancellationToken.None
).GetAwaiter().GetResult();
}
/// <summary>
/// {{ToXmlDoc operation.description}}
/// </summary>
/// <param name='operations'>
/// The operations group for this extension method.
/// </param>
{{#operation.parameters}}
/// <param name="{{GetDotNetName .}}">
/// {{ToXmlDoc description}}
/// </param>
{{/operation.parameters}}
/// <param name="cancellationToken">
/// A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation.
/// </param>
public static async Task{{GetReturnType operation "<>"}} {{GetMethodName operation "Async"}}(
this IBasicKubernetes operations,
{{#operation.parameters}}
{{GetDotNetType .}} {{GetDotNetName . "true"}},
{{/operation.parameters}}
CancellationToken cancellationToken = default(CancellationToken))
{
{{#IfReturnType operation "stream"}}
var _result = await operations.{{GetMethodName operation "WithHttpMessagesAsync"}}(
{{#operation.parameters}}
{{GetDotNetName .}},
{{/operation.parameters}}
null,
cancellationToken);
_result.Request.Dispose();
{{GetReturnType operation "_result.Body"}};
{{/IfReturnType operation "stream"}}
{{#IfReturnType operation "obj"}}
using (var _result = await operations.{{GetMethodName operation "WithHttpMessagesAsync"}}(
{{#operation.parameters}}
{{GetDotNetName .}},
{{/operation.parameters}}
null,
cancellationToken).ConfigureAwait(false))
{
{{GetReturnType operation "_result.Body"}};
}
{{/IfReturnType operation "obj"}}
{{#IfReturnType operation "void"}}
using (var _result = await operations.{{GetMethodName operation "WithHttpMessagesAsync"}}(
{{#operation.parameters}}
{{GetDotNetName .}},
{{/operation.parameters}}
null,
cancellationToken).ConfigureAwait(false))
{
}
{{/IfReturnType operation "void"}}
}
{{/.}}
}
}

View File

@@ -0,0 +1,92 @@
// <auto-generated>
// Code generated by https://github.com/kubernetes-client/csharp/tree/master/src/LibKubernetesGenerator
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.
// </auto-generated>
namespace k8s;
internal partial class {{name}}Operations : Operations, I{{name}}Operations
{
public {{name}}Operations(AbstractKubernetes kubernetes) : base(kubernetes)
{
}
{{#apis}}
/// <inheritdoc/>
public async Task<HttpOperationResponse{{GetReturnType operation "<>"}}> {{GetMethodName operation "WithHttpMessagesAsync"}}(
{{#operation.parameters}}
{{GetDotNetType .}} {{GetDotNetName . "true"}},
{{/operation.parameters}}
IReadOnlyDictionary<string, IReadOnlyList<string>> customHeaders = null,
CancellationToken cancellationToken = default(CancellationToken))
{
var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
cts.CancelAfter(HttpClientTimeout);
{{#IfParamContains operation "watch"}}
if (watch == true)
{
cts.CancelAfter(Timeout.InfiniteTimeSpan);
}
{{/IfParamContains operation "watch"}}
cancellationToken = cts.Token;
{{#operation.parameters}}
{{#isRequired}}
if ({{GetDotNetName name}} == null)
{
throw new ArgumentNullException("{{GetDotNetName name}}");
}
{{/isRequired}}
{{/operation.parameters}}
// Construct URL
var url = $"{{ToInterpolationPathString path}}";
{{#IfGroupPathParamContainsGroup path}}
url = url.Replace("apis//", "api/");
{{/IfGroupPathParamContainsGroup}}
{{#IfListNotEmpty operation.parameters}}
var q = new QueryBuilder();
{{#operation.parameters}}
{{#IfKindIs . "query"}}
q.Append("{{name}}", {{GetDotNetName name}});
{{/IfKindIs . "query"}}
{{/operation.parameters}}
url += q.ToString();
{{/IfListNotEmpty operation.parameters}}
// Create HTTP transport
var httpRequest = CreateRequest(url, HttpMethods.{{Method}}, customHeaders);
{{#IfParamContains operation "body"}}
var httpResponse = await SendRequest(body, httpRequest, cancellationToken);
{{/IfParamContains operation "body"}}
{{#IfParamDoesNotContain operation "body"}}
var httpResponse = await SendRequestRaw("", httpRequest, cancellationToken);
{{/IfParamDoesNotContain operation "body"}}
// Create Result
{{#IfReturnType operation "void"}}
HttpOperationResponse result = new HttpOperationResponse() { Request = httpRequest, Response = httpResponse };
{{/IfReturnType operation "void"}}
{{#IfReturnType operation "obj"}}
var result = await CreateResultAsync{{GetReturnType operation "<>"}}(httpRequest,
httpResponse,
{{#IfParamContains operation "watch"}}
watch,
{{/IfParamContains operation "watch"}}
{{#IfParamDoesNotContain operation "watch"}}
false,
{{/IfParamDoesNotContain operation "watch"}}
cancellationToken);
{{/IfReturnType operation "obj"}}
{{#IfReturnType operation "stream"}}
var result = new HttpOperationResponse{{GetReturnType operation "<>"}}() {
Request = httpRequest,
Response = httpResponse,
Body = await httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false) };
{{/IfReturnType operation "stream"}}
return result;
}
{{/apis}}
}

View File

@@ -0,0 +1,96 @@
// <auto-generated>
// Code generated by https://github.com/kubernetes-client/csharp/tree/master/src/LibKubernetesGenerator
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.
// </auto-generated>
namespace k8s;
/// <summary>
/// Extension methods for Kubernetes.
/// </summary>
public static partial class {{name}}OperationsExtensions
{
{{#apis}}
/// <summary>
/// {{ToXmlDoc operation.description}}
/// </summary>
/// <param name='operations'>
/// The operations group for this extension method.
/// </param>
{{#operation.parameters}}
/// <param name="{{GetDotNetName .}}">
/// {{ToXmlDoc description}}
/// </param>
{{/operation.parameters}}
public static {{GetReturnType operation "void"}} {{GetMethodName operation ""}}(
this I{{name}}Operations operations
{{#operation.parameters}}
,{{GetDotNetType .}} {{GetDotNetName . "true"}}
{{/operation.parameters}}
)
{
{{GetReturnType operation "return"}} operations.{{GetMethodName operation "Async"}}(
{{#operation.parameters}}
{{GetDotNetName .}},
{{/operation.parameters}}
CancellationToken.None
).GetAwaiter().GetResult();
}
/// <summary>
/// {{ToXmlDoc operation.description}}
/// </summary>
/// <param name='operations'>
/// The operations group for this extension method.
/// </param>
{{#operation.parameters}}
/// <param name="{{GetDotNetName .}}">
/// {{ToXmlDoc description}}
/// </param>
{{/operation.parameters}}
/// <param name="cancellationToken">
/// A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation.
/// </param>
public static async Task{{GetReturnType operation "<>"}} {{GetMethodName operation "Async"}}(
this I{{name}}Operations operations,
{{#operation.parameters}}
{{GetDotNetType .}} {{GetDotNetName . "true"}},
{{/operation.parameters}}
CancellationToken cancellationToken = default(CancellationToken))
{
{{#IfReturnType operation "stream"}}
var _result = await operations.{{GetMethodName operation "WithHttpMessagesAsync"}}(
{{#operation.parameters}}
{{GetDotNetName .}},
{{/operation.parameters}}
null,
cancellationToken);
_result.Request.Dispose();
{{GetReturnType operation "_result.Body"}};
{{/IfReturnType operation "stream"}}
{{#IfReturnType operation "obj"}}
using (var _result = await operations.{{GetMethodName operation "WithHttpMessagesAsync"}}(
{{#operation.parameters}}
{{GetDotNetName .}},
{{/operation.parameters}}
null,
cancellationToken).ConfigureAwait(false))
{
{{GetReturnType operation "_result.Body"}};
}
{{/IfReturnType operation "obj"}}
{{#IfReturnType operation "void"}}
using (var _result = await operations.{{GetMethodName operation "WithHttpMessagesAsync"}}(
{{#operation.parameters}}
{{GetDotNetName .}},
{{/operation.parameters}}
null,
cancellationToken).ConfigureAwait(false))
{
}
{{/IfReturnType operation "void"}}
}
{{/apis}}
}

File diff suppressed because it is too large Load Diff

View File

@@ -29,12 +29,12 @@ namespace k8s.E2E
void Cleanup() void Cleanup()
{ {
var pods = client.ListNamespacedPod(namespaceParameter); var pods = client.CoreV1.ListNamespacedPod(namespaceParameter);
while (pods.Items.Any(p => p.Metadata.Name == podName)) while (pods.Items.Any(p => p.Metadata.Name == podName))
{ {
try try
{ {
client.DeleteNamespacedPod(podName, namespaceParameter); client.CoreV1.DeleteNamespacedPod(podName, namespaceParameter);
} }
catch (HttpOperationException e) catch (HttpOperationException e)
{ {
@@ -50,7 +50,7 @@ namespace k8s.E2E
{ {
Cleanup(); Cleanup();
client.CreateNamespacedPod( client.CoreV1.CreateNamespacedPod(
new V1Pod() new V1Pod()
{ {
Metadata = new V1ObjectMeta { Name = podName, }, Metadata = new V1ObjectMeta { Name = podName, },
@@ -61,7 +61,7 @@ namespace k8s.E2E
}, },
namespaceParameter); namespaceParameter);
var pods = client.ListNamespacedPod(namespaceParameter); var pods = client.CoreV1.ListNamespacedPod(namespaceParameter);
Assert.Contains(pods.Items, p => p.Metadata.Name == podName); Assert.Contains(pods.Items, p => p.Metadata.Name == podName);
} }
finally finally
@@ -80,12 +80,12 @@ namespace k8s.E2E
void Cleanup() void Cleanup()
{ {
var pods = client.ListNamespacedPod(namespaceParameter); var pods = client.CoreV1.ListNamespacedPod(namespaceParameter);
while (pods.Items.Any(p => p.Metadata.Name == podName)) while (pods.Items.Any(p => p.Metadata.Name == podName))
{ {
try try
{ {
client.DeleteNamespacedPod(podName, namespaceParameter); client.CoreV1.DeleteNamespacedPod(podName, namespaceParameter);
} }
catch (HttpOperationException e) catch (HttpOperationException e)
{ {
@@ -102,7 +102,7 @@ namespace k8s.E2E
{ {
Cleanup(); Cleanup();
client.CreateNamespacedPod( client.CoreV1.CreateNamespacedPod(
new V1Pod() new V1Pod()
{ {
Metadata = new V1ObjectMeta { Name = podName, Labels = new Dictionary<string, string> { { "place", "holder" }, }, }, Metadata = new V1ObjectMeta { Name = podName, Labels = new Dictionary<string, string> { { "place", "holder" }, }, },
@@ -115,7 +115,7 @@ namespace k8s.E2E
// patch // patch
{ {
var pod = client.ListNamespacedPod(namespaceParameter).Items.First(p => p.Metadata.Name == podName); var pod = client.CoreV1.ListNamespacedPod(namespaceParameter).Items.First(p => p.Metadata.Name == podName);
var old = JsonSerializer.SerializeToDocument(pod); var old = JsonSerializer.SerializeToDocument(pod);
var newlabels = new Dictionary<string, string>(pod.Metadata.Labels) { ["test"] = "test-jsonpatch" }; var newlabels = new Dictionary<string, string>(pod.Metadata.Labels) { ["test"] = "test-jsonpatch" };
@@ -123,12 +123,12 @@ namespace k8s.E2E
var expected = JsonSerializer.SerializeToDocument(pod); var expected = JsonSerializer.SerializeToDocument(pod);
var patch = old.CreatePatch(expected); var patch = old.CreatePatch(expected);
client.PatchNamespacedPod(new V1Patch(patch, V1Patch.PatchType.JsonPatch), pod.Metadata.Name, "default"); client.CoreV1.PatchNamespacedPod(new V1Patch(patch, V1Patch.PatchType.JsonPatch), pod.Metadata.Name, "default");
} }
// refresh // refresh
{ {
var pod = client.ListNamespacedPod(namespaceParameter).Items.First(p => p.Metadata.Name == podName); var pod = client.CoreV1.ListNamespacedPod(namespaceParameter).Items.First(p => p.Metadata.Name == podName);
Assert.Equal("test-jsonpatch", pod.Labels()["test"]); Assert.Equal("test-jsonpatch", pod.Labels()["test"]);
} }
} }
@@ -138,7 +138,7 @@ namespace k8s.E2E
} }
{ {
client.CreateNamespacedPod( client.CoreV1.CreateNamespacedPod(
new V1Pod() new V1Pod()
{ {
Metadata = new V1ObjectMeta { Name = podName, Labels = new Dictionary<string, string> { { "place", "holder" }, }, }, Metadata = new V1ObjectMeta { Name = podName, Labels = new Dictionary<string, string> { { "place", "holder" }, }, },
@@ -150,7 +150,7 @@ namespace k8s.E2E
namespaceParameter); namespaceParameter);
var pod = client.ListNamespacedPod(namespaceParameter).Items.First(p => p.Metadata.Name == podName); var pod = client.CoreV1.ListNamespacedPod(namespaceParameter).Items.First(p => p.Metadata.Name == podName);
var patchStr = @" var patchStr = @"
{ {
@@ -161,12 +161,12 @@ namespace k8s.E2E
} }
}"; }";
client.PatchNamespacedPod(new V1Patch(patchStr, V1Patch.PatchType.MergePatch), pod.Metadata.Name, "default"); client.CoreV1.PatchNamespacedPod(new V1Patch(patchStr, V1Patch.PatchType.MergePatch), pod.Metadata.Name, "default");
Assert.False(pod.Labels().ContainsKey("test")); Assert.False(pod.Labels().ContainsKey("test"));
// refresh // refresh
pod = client.ListNamespacedPod(namespaceParameter).Items.First(p => p.Metadata.Name == podName); pod = client.CoreV1.ListNamespacedPod(namespaceParameter).Items.First(p => p.Metadata.Name == podName);
Assert.Equal("test-mergepatch", pod.Labels()["test"]); Assert.Equal("test-mergepatch", pod.Labels()["test"]);
} }
@@ -182,7 +182,7 @@ namespace k8s.E2E
{ {
var kubernetes = CreateClient(); var kubernetes = CreateClient();
var job = await kubernetes.CreateNamespacedJobAsync( var job = await kubernetes.BatchV1.CreateNamespacedJobAsync(
new V1Job() new V1Job()
{ {
ApiVersion = "batch/v1", ApiVersion = "batch/v1",
@@ -219,7 +219,7 @@ namespace k8s.E2E
var started = new AsyncManualResetEvent(); var started = new AsyncManualResetEvent();
var connectionClosed = new AsyncManualResetEvent(); var connectionClosed = new AsyncManualResetEvent();
var watcher = kubernetes.ListNamespacedJobWithHttpMessagesAsync( var watcher = kubernetes.BatchV1.ListNamespacedJobWithHttpMessagesAsync(
job.Metadata.NamespaceProperty, job.Metadata.NamespaceProperty,
fieldSelector: $"metadata.name={job.Metadata.Name}", fieldSelector: $"metadata.name={job.Metadata.Name}",
resourceVersion: job.Metadata.ResourceVersion, resourceVersion: job.Metadata.ResourceVersion,
@@ -239,7 +239,7 @@ namespace k8s.E2E
await Task.WhenAny(connectionClosed.WaitAsync(), Task.Delay(TimeSpan.FromMinutes(3))).ConfigureAwait(false); await Task.WhenAny(connectionClosed.WaitAsync(), Task.Delay(TimeSpan.FromMinutes(3))).ConfigureAwait(false);
Assert.True(connectionClosed.IsSet); Assert.True(connectionClosed.IsSet);
var st = await kubernetes.DeleteNamespacedJobAsync( var st = await kubernetes.BatchV1.DeleteNamespacedJobAsync(
job.Metadata.Name, job.Metadata.Name,
job.Metadata.NamespaceProperty, job.Metadata.NamespaceProperty,
new V1DeleteOptions() { PropagationPolicy = "Foreground" }).ConfigureAwait(false); new V1DeleteOptions() { PropagationPolicy = "Foreground" }).ConfigureAwait(false);
@@ -253,7 +253,7 @@ namespace k8s.E2E
void Cleanup() void Cleanup()
{ {
var endpoints = client.ListNamespacedEndpoints(namespaceParameter); var endpoints = client.CoreV1.ListNamespacedEndpoints(namespaceParameter);
void DeleteEndpoints(string name) void DeleteEndpoints(string name)
{ {
@@ -261,7 +261,7 @@ namespace k8s.E2E
{ {
try try
{ {
client.DeleteNamespacedEndpoints(name, namespaceParameter); client.CoreV1.DeleteNamespacedEndpoints(name, namespaceParameter);
} }
catch (HttpOperationException e) catch (HttpOperationException e)
{ {
@@ -351,12 +351,12 @@ namespace k8s.E2E
void Cleanup() void Cleanup()
{ {
var pods = client.ListNamespacedPod(namespaceParameter); var pods = client.CoreV1.ListNamespacedPod(namespaceParameter);
while (pods.Items.Any(p => p.Metadata.Name == podName)) while (pods.Items.Any(p => p.Metadata.Name == podName))
{ {
try try
{ {
client.DeleteNamespacedPod(podName, namespaceParameter); client.CoreV1.DeleteNamespacedPod(podName, namespaceParameter);
} }
catch (HttpOperationException e) catch (HttpOperationException e)
{ {
@@ -372,7 +372,7 @@ namespace k8s.E2E
{ {
Cleanup(); Cleanup();
client.CreateNamespacedPod( client.CoreV1.CreateNamespacedPod(
new V1Pod() new V1Pod()
{ {
Metadata = new V1ObjectMeta { Name = podName, }, Metadata = new V1ObjectMeta { Name = podName, },
@@ -397,7 +397,7 @@ namespace k8s.E2E
async Task<V1Pod> Pod() async Task<V1Pod> Pod()
{ {
var pods = client.ListNamespacedPod(namespaceParameter); var pods = client.CoreV1.ListNamespacedPod(namespaceParameter);
var pod = pods.Items.First(); var pod = pods.Items.First();
while (pod.Status.Phase != "Running") while (pod.Status.Phase != "Running")
{ {
@@ -409,7 +409,7 @@ namespace k8s.E2E
} }
var pod = await Pod().ConfigureAwait(false); var pod = await Pod().ConfigureAwait(false);
var stream = client.ReadNamespacedPodLog(pod.Metadata.Name, pod.Metadata.NamespaceProperty, follow: true); var stream = client.CoreV1.ReadNamespacedPodLog(pod.Metadata.Name, pod.Metadata.NamespaceProperty, follow: true);
using var reader = new StreamReader(stream); using var reader = new StreamReader(stream);
var copytask = Task.Run(() => var copytask = Task.Run(() =>
@@ -445,7 +445,7 @@ namespace k8s.E2E
{ {
var kubernetes = CreateClient(); var kubernetes = CreateClient();
await kubernetes.CreateNamespacedEventAsync( await kubernetes.CoreV1.CreateNamespacedEventAsync(
new Corev1Event( new Corev1Event(
new V1ObjectReference( new V1ObjectReference(
"v1alpha1", "v1alpha1",
@@ -480,12 +480,12 @@ namespace k8s.E2E
void Cleanup() void Cleanup()
{ {
var pods = client.ListNamespacedPod(namespaceParameter); var pods = client.CoreV1.ListNamespacedPod(namespaceParameter);
while (pods.Items.Any(p => p.Metadata.Name == podName)) while (pods.Items.Any(p => p.Metadata.Name == podName))
{ {
try try
{ {
client.DeleteNamespacedPod(podName, namespaceParameter); client.CoreV1.DeleteNamespacedPod(podName, namespaceParameter);
} }
catch (HttpOperationException e) catch (HttpOperationException e)
{ {

View File

@@ -74,7 +74,7 @@ public class BasicTests
}); });
var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Addr }); var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Addr });
var pod = await client.ReadNamespacedPodAsync("pod", "default").ConfigureAwait(false); var pod = await client.CoreV1.ReadNamespacedPodAsync("pod", "default").ConfigureAwait(false);
Assert.Equal("pod0", pod.Metadata.Name); Assert.Equal("pod0", pod.Metadata.Name);
} }

View File

@@ -36,7 +36,7 @@ namespace k8s.Tests
private static HttpOperationResponse<V1PodList> ExecuteListPods(IKubernetes client) private static HttpOperationResponse<V1PodList> ExecuteListPods(IKubernetes client)
{ {
return client.ListNamespacedPodWithHttpMessagesAsync("default").Result; return client.CoreV1.ListNamespacedPodWithHttpMessagesAsync("default").Result;
} }
[Fact] [Fact]

View File

@@ -24,7 +24,7 @@ namespace k8s.Tests
{ {
var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() }); var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() });
var status = client.DeleteNamespace("test", new V1DeleteOptions()); var status = client.CoreV1.DeleteNamespace("test", new V1DeleteOptions());
Assert.False(status.HasObject); Assert.False(status.HasObject);
Assert.Equal(v1Status.Message, status.Message); Assert.Equal(v1Status.Message, status.Message);
@@ -45,7 +45,7 @@ namespace k8s.Tests
{ {
var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() }); var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() });
var status = client.DeleteNamespace("test", new V1DeleteOptions()); var status = client.CoreV1.DeleteNamespace("test", new V1DeleteOptions());
Assert.True(status.HasObject); Assert.True(status.HasObject);

View File

@@ -54,7 +54,7 @@ namespace k8s.Tests
var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() }); var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() });
// did not pass watch param // did not pass watch param
var listTask = client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true); var listTask = client.CoreV1.ListNamespacedPodWithHttpMessagesAsync("default", watch: true);
var onErrorCalled = false; var onErrorCalled = false;
using (listTask.Watch<V1Pod, V1PodList>((type, item) => { }, e => { onErrorCalled = true; })) using (listTask.Watch<V1Pod, V1PodList>((type, item) => { }, e => { onErrorCalled = true; }))
@@ -68,7 +68,7 @@ namespace k8s.Tests
// server did not response line by line // server did not response line by line
await Assert.ThrowsAnyAsync<Exception>(() => await Assert.ThrowsAnyAsync<Exception>(() =>
{ {
return client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true); return client.CoreV1.ListNamespacedPodWithHttpMessagesAsync("default", watch: true);
// this line did not throw // this line did not throw
// listTask.Watch<Corev1Pod>((type, item) => { }); // listTask.Watch<Corev1Pod>((type, item) => { });
@@ -93,7 +93,7 @@ namespace k8s.Tests
var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() }); var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() });
var listTask = client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true); var listTask = client.CoreV1.ListNamespacedPodWithHttpMessagesAsync("default", watch: true);
using (listTask.Watch<V1Pod, V1PodList>((type, item) => { eventsReceived.Set(); })) using (listTask.Watch<V1Pod, V1PodList>((type, item) => { eventsReceived.Set(); }))
{ {
// here watcher is ready to use, but http server has not responsed yet. // here watcher is ready to use, but http server has not responsed yet.
@@ -134,7 +134,7 @@ namespace k8s.Tests
{ {
var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() }); var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() });
var listTask = await client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true).ConfigureAwait(false); var listTask = await client.CoreV1.ListNamespacedPodWithHttpMessagesAsync("default", watch: true).ConfigureAwait(false);
var events = new HashSet<WatchEventType>(); var events = new HashSet<WatchEventType>();
var errors = 0; var errors = 0;
@@ -195,7 +195,7 @@ namespace k8s.Tests
{ {
var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() }); var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() });
var listTask = await client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true).ConfigureAwait(false); var listTask = await client.CoreV1.ListNamespacedPodWithHttpMessagesAsync("default", watch: true).ConfigureAwait(false);
var events = new HashSet<WatchEventType>(); var events = new HashSet<WatchEventType>();
@@ -255,7 +255,7 @@ namespace k8s.Tests
{ {
var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() }); var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() });
var listTask = await client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true).ConfigureAwait(false); var listTask = await client.CoreV1.ListNamespacedPodWithHttpMessagesAsync("default", watch: true).ConfigureAwait(false);
var events = new HashSet<WatchEventType>(); var events = new HashSet<WatchEventType>();
var errors = 0; var errors = 0;
@@ -324,7 +324,7 @@ namespace k8s.Tests
{ {
var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() }); var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() });
var listTask = await client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true).ConfigureAwait(false); var listTask = await client.CoreV1.ListNamespacedPodWithHttpMessagesAsync("default", watch: true).ConfigureAwait(false);
var events = new HashSet<WatchEventType>(); var events = new HashSet<WatchEventType>();
var errors = 0; var errors = 0;
@@ -386,7 +386,7 @@ namespace k8s.Tests
{ {
var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() }); var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() });
var listTask = await client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true).ConfigureAwait(false); var listTask = await client.CoreV1.ListNamespacedPodWithHttpMessagesAsync("default", watch: true).ConfigureAwait(false);
waitForException.Set(); waitForException.Set();
Watcher<V1Pod> watcher; Watcher<V1Pod> watcher;
@@ -451,7 +451,7 @@ namespace k8s.Tests
Assert.False(handler1.Called); Assert.False(handler1.Called);
Assert.False(handler2.Called); Assert.False(handler2.Called);
var listTask = await client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true).ConfigureAwait(false); var listTask = await client.CoreV1.ListNamespacedPodWithHttpMessagesAsync("default", watch: true).ConfigureAwait(false);
var events = new HashSet<WatchEventType>(); var events = new HashSet<WatchEventType>();
@@ -502,7 +502,7 @@ namespace k8s.Tests
var events = new HashSet<WatchEventType>(); var events = new HashSet<WatchEventType>();
var errors = 0; var errors = 0;
var watcher = client.ListNamespacedPodWithHttpMessagesAsync("default", fieldSelector: $"metadata.name=${"myPod"}", watch: true).Watch<V1Pod, V1PodList>( var watcher = client.CoreV1.ListNamespacedPodWithHttpMessagesAsync("default", fieldSelector: $"metadata.name=${"myPod"}", watch: true).Watch<V1Pod, V1PodList>(
onEvent: onEvent:
(type, item) => (type, item) =>
{ {
@@ -563,7 +563,7 @@ namespace k8s.Tests
Host = server.Uri.ToString(), Host = server.Uri.ToString(),
HttpClientTimeout = TimeSpan.FromSeconds(5), HttpClientTimeout = TimeSpan.FromSeconds(5),
}); });
await client.ListNamespacedPodWithHttpMessagesAsync("default").ConfigureAwait(false); await client.CoreV1.ListNamespacedPodWithHttpMessagesAsync("default").ConfigureAwait(false);
}).ConfigureAwait(false); }).ConfigureAwait(false);
// cts // cts
@@ -575,7 +575,7 @@ namespace k8s.Tests
{ {
Host = server.Uri.ToString(), Host = server.Uri.ToString(),
}); });
await client.ListNamespacedPodWithHttpMessagesAsync("default", cancellationToken: cts.Token).ConfigureAwait(false); await client.CoreV1.ListNamespacedPodWithHttpMessagesAsync("default", cancellationToken: cts.Token).ConfigureAwait(false);
}).ConfigureAwait(false); }).ConfigureAwait(false);
} }
@@ -603,7 +603,7 @@ namespace k8s.Tests
var events = new HashSet<WatchEventType>(); var events = new HashSet<WatchEventType>();
var errors = 0; var errors = 0;
var watcher = client.ListNamespacedPodWithHttpMessagesAsync("default", fieldSelector: $"metadata.name=${"myPod"}", watch: true).Watch<V1Pod, V1PodList>( var watcher = client.CoreV1.ListNamespacedPodWithHttpMessagesAsync("default", fieldSelector: $"metadata.name=${"myPod"}", watch: true).Watch<V1Pod, V1PodList>(
onEvent: onEvent:
(type, item) => (type, item) =>
{ {
@@ -662,7 +662,7 @@ namespace k8s.Tests
await Assert.ThrowsAnyAsync<OperationCanceledException>(async () => await Assert.ThrowsAnyAsync<OperationCanceledException>(async () =>
{ {
await client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true, await client.CoreV1.ListNamespacedPodWithHttpMessagesAsync("default", watch: true,
cancellationToken: cts.Token).ConfigureAwait(false); cancellationToken: cts.Token).ConfigureAwait(false);
}).ConfigureAwait(false); }).ConfigureAwait(false);
} }
@@ -736,7 +736,7 @@ namespace k8s.Tests
var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() }, h); var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() }, h);
Assert.Null(h.Version); Assert.Null(h.Version);
await client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true).ConfigureAwait(false); await client.CoreV1.ListNamespacedPodWithHttpMessagesAsync("default", watch: true).ConfigureAwait(false);
Assert.Equal(HttpVersion.Version20, h.Version); Assert.Equal(HttpVersion.Version20, h.Version);
} }
} }

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "7.2", "version": "8.0",
"publicReleaseRefSpec": [ "publicReleaseRefSpec": [
"^refs/heads/master$", "^refs/heads/master$",
"^refs/tags/v\\d+\\.\\d+\\.\\d+" "^refs/tags/v\\d+\\.\\d+\\.\\d+"