API v1.23.0 + system.text.json + remove WatchXXX API (#750)
* gen v1.23.0 * fix converter * bump ver * update readme runtime * fix warning * update dep ver * newtonjson -> system.text.json * generate for new json api * readme lf * dotnet fmt * dotnet fmt tests/ * dotnet fmt * Revert "dotnet fmt" This reverts commit e14c59076143fe2218ed899295a00762f0ea2bd6. * fix err introduce by dotnet fmt * fix test * remove deprecated /watch api * generate code after /watch removed * remove /watch related code * trim Microsoft.Rest.Serialization
This commit is contained in:
@@ -244,6 +244,8 @@ namespace k8s.Tests
|
||||
/// Tests a call to <see cref="ByteBuffer.Read(byte[], int, int)"/> when no data is available; and makes
|
||||
/// sure the call blocks until data is available.
|
||||
/// </summary>
|
||||
/// <returns><placeholder>A <see cref="Task"/> representing the asynchronous unit test.</placeholder></returns>
|
||||
/// <returns><placeholder>A <see cref="Task"/> representing the asynchronous unit test.</placeholder></returns>
|
||||
[Fact]
|
||||
public async Task ReadBlocksUntilDataAvailableTest()
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using System.Text.Json;
|
||||
using k8s.KubeConfigModels;
|
||||
using Xunit;
|
||||
|
||||
@@ -19,9 +19,9 @@ namespace k8s.Tests
|
||||
{ new Dictionary<string, string> { { "name", "testkey" }, { "value", "testvalue" } } },
|
||||
});
|
||||
|
||||
var actualExecInfo = JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(actual.StartInfo.EnvironmentVariables["KUBERNETES_EXEC_INFO"]);
|
||||
Assert.Equal("testingversion", actualExecInfo["apiVersion"]);
|
||||
Assert.Equal("ExecCredentials", actualExecInfo["kind"]);
|
||||
var actualExecInfo = JsonSerializer.Deserialize<IDictionary<string, dynamic>>(actual.StartInfo.EnvironmentVariables["KUBERNETES_EXEC_INFO"]);
|
||||
Assert.Equal("testingversion", actualExecInfo["apiVersion"].ToString());
|
||||
Assert.Equal("ExecCredentials", actualExecInfo["kind"].ToString());
|
||||
|
||||
Assert.Equal("command", actual.StartInfo.FileName);
|
||||
Assert.Equal("arg1 arg2", actual.StartInfo.Arguments);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using k8s.Models;
|
||||
using Newtonsoft.Json;
|
||||
using Xunit;
|
||||
|
||||
namespace k8s.Tests
|
||||
@@ -13,12 +12,12 @@ namespace k8s.Tests
|
||||
var v = 123;
|
||||
IntstrIntOrString intorstr = v;
|
||||
|
||||
Assert.Equal("123", JsonConvert.SerializeObject(intorstr));
|
||||
Assert.Equal("123", KubernetesJson.Serialize(intorstr));
|
||||
}
|
||||
|
||||
{
|
||||
IntstrIntOrString intorstr = "12%";
|
||||
Assert.Equal("\"12%\"", JsonConvert.SerializeObject(intorstr));
|
||||
Assert.Equal("\"12%\"", KubernetesJson.Serialize(intorstr));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,12 +25,12 @@ namespace k8s.Tests
|
||||
public void Deserialize()
|
||||
{
|
||||
{
|
||||
var v = JsonConvert.DeserializeObject<IntstrIntOrString>("1234");
|
||||
var v = KubernetesJson.Deserialize<IntstrIntOrString>("1234");
|
||||
Assert.Equal("1234", v.Value);
|
||||
}
|
||||
|
||||
{
|
||||
var v = JsonConvert.DeserializeObject<IntstrIntOrString>("\"12%\"");
|
||||
var v = KubernetesJson.Deserialize<IntstrIntOrString>("\"12%\"");
|
||||
Assert.Equal("12%", v.Value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<PropertyGroup>
|
||||
<IsPackable>false</IsPackable>
|
||||
<LangVersion>8</LangVersion>
|
||||
@@ -10,11 +10,11 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MartinCostello.Logging.XUnit" Version="0.2.0" />
|
||||
<PackageReference Include="FluentAssertions" Version="6.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
|
||||
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="13.2.47" />
|
||||
<PackageReference Include="System.Reactive" Version="5.0.0" />
|
||||
<PackageReference Include="Nito.AsyncEx" Version="5.1.2" />
|
||||
<PackageReference Include="Portable.BouncyCastle" Version="1.8.10"/>
|
||||
<PackageReference Include="Portable.BouncyCastle" Version="1.8.10" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -24,7 +24,7 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using k8s.LeaderElection;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Net.WebSockets;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace k8s.Tests.Mock.Server.Controllers
|
||||
@@ -43,6 +42,8 @@ namespace k8s.Tests.Mock.Server.Controllers
|
||||
/// <param name="podName">
|
||||
/// The target pod's name.
|
||||
/// </param>
|
||||
/// <returns><placeholder>A <see cref="Task"/> representing the asynchronous operation.</placeholder></returns>
|
||||
/// <returns><placeholder>A <see cref="Task"/> representing the asynchronous operation.</placeholder></returns>
|
||||
[Route("namespaces/{kubeNamespace}/pods/{podName}/exec")]
|
||||
public async Task<IActionResult> Exec(string kubeNamespace, string podName)
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.WebSockets;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace k8s.Tests.Mock.Server.Controllers
|
||||
@@ -47,6 +46,8 @@ namespace k8s.Tests.Mock.Server.Controllers
|
||||
/// <param name="ports">
|
||||
/// The port(s) to forward to the pod.
|
||||
/// </param>
|
||||
/// <returns><placeholder>A <see cref="Task"/> representing the asynchronous operation.</placeholder></returns>
|
||||
/// <returns><placeholder>A <see cref="Task"/> representing the asynchronous operation.</placeholder></returns>
|
||||
[Route("namespaces/{kubeNamespace}/pods/{podName}/portforward")]
|
||||
public async Task<IActionResult> Exec(string kubeNamespace, string podName, IEnumerable<string> ports)
|
||||
{
|
||||
|
||||
@@ -2,7 +2,6 @@ using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace k8s.Tests.Mock.Server
|
||||
{
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
using k8s.Models;
|
||||
using Microsoft.Rest;
|
||||
using Microsoft.Rest.Serialization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@@ -12,6 +11,7 @@ using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Net.WebSockets;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
@@ -43,6 +43,8 @@ namespace k8s.Tests
|
||||
/// <summary>
|
||||
/// Verify that the client can request execution of a command in a pod's default container, with only the STDOUT stream enabled.
|
||||
/// </summary>
|
||||
/// <returns><placeholder>A <see cref="Task"/> representing the asynchronous unit test.</placeholder></returns>
|
||||
/// <returns><placeholder>A <see cref="Task"/> representing the asynchronous unit test.</placeholder></returns>
|
||||
[Fact(DisplayName = "Can exec in pod's default container, STDOUT only")]
|
||||
public async Task ExecDefaultContainerStdOut()
|
||||
{
|
||||
@@ -302,7 +304,7 @@ namespace k8s.Tests
|
||||
},
|
||||
};
|
||||
|
||||
var processStatusJson = Encoding.UTF8.GetBytes(SafeJsonConvert.SerializeObject(processStatus));
|
||||
var processStatusJson = JsonSerializer.SerializeToUtf8Bytes(processStatus);
|
||||
var handler = new ExecAsyncCallback((stdIn, stdOut, stdError) => Task.CompletedTask);
|
||||
|
||||
using (MemoryStream stdIn = new MemoryStream())
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using k8s.Models;
|
||||
using Newtonsoft.Json;
|
||||
using Xunit;
|
||||
using static k8s.Models.ResourceQuantity.SuffixFormat;
|
||||
|
||||
@@ -12,7 +11,7 @@ namespace k8s.Tests
|
||||
public void Deserialize()
|
||||
{
|
||||
{
|
||||
var q = JsonConvert.DeserializeObject<ResourceQuantity>("\"12k\"");
|
||||
var q = KubernetesJson.Deserialize<ResourceQuantity>("\"12k\"");
|
||||
Assert.Equal(new ResourceQuantity(12000, 0, DecimalSI), q);
|
||||
}
|
||||
}
|
||||
@@ -205,7 +204,7 @@ namespace k8s.Tests
|
||||
{
|
||||
{
|
||||
ResourceQuantity quantity = 12000;
|
||||
Assert.Equal("\"12e3\"", JsonConvert.SerializeObject(quantity));
|
||||
Assert.Equal("\"12e3\"", KubernetesJson.Serialize(quantity));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using k8s.Models;
|
||||
using k8s.Tests.Mock;
|
||||
using k8s.Util.Common.Generic;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Nito.AsyncEx;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace k8s.Tests.Util
|
||||
{
|
||||
|
||||
@@ -301,7 +301,7 @@ namespace k8s.Tests.Util.Informer.Cache
|
||||
},
|
||||
};
|
||||
var cache = new Cache<V1Pod>();
|
||||
var defaultReturnValue = Caches.DeletionHandlingMetaNamespaceKeyFunc<V1Pod>(pod);
|
||||
var defaultReturnValue = Caches.DeletionHandlingMetaNamespaceKeyFunc(pod);
|
||||
|
||||
var funcReturnValue = cache.KeyFunc(pod);
|
||||
|
||||
|
||||
@@ -4,8 +4,6 @@ using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using k8s.Models;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Nito.AsyncEx;
|
||||
|
||||
namespace k8s.Tests.Util
|
||||
@@ -84,10 +82,8 @@ namespace k8s.Tests.Util
|
||||
|
||||
private static string BuildWatchEventStreamLine(WatchEventType eventType)
|
||||
{
|
||||
var corev1PodList = JsonConvert.DeserializeObject<V1PodList>(MockPodResponse);
|
||||
return JsonConvert.SerializeObject(
|
||||
new Watcher<V1Pod>.WatchEvent { Type = eventType, Object = corev1PodList.Items.First() },
|
||||
new StringEnumConverter());
|
||||
var corev1PodList = KubernetesJson.Deserialize<V1PodList>(MockPodResponse);
|
||||
return KubernetesJson.Serialize(new Watcher<V1Pod>.WatchEvent { Type = eventType, Object = corev1PodList.Items.First() });
|
||||
}
|
||||
|
||||
private async Task WriteStreamLine(HttpContext httpContext, string reponseLine)
|
||||
@@ -157,8 +153,8 @@ namespace k8s.Tests.Util
|
||||
await WriteStreamLine(httpContext, MockPodResponse).ConfigureAwait(false);
|
||||
break;
|
||||
case MockKubeServerFlags.GetPod:
|
||||
var corev1PodList = JsonConvert.DeserializeObject<V1PodList>(MockPodResponse);
|
||||
await WriteStreamLine(httpContext, JsonConvert.SerializeObject(corev1PodList.Items.First())).ConfigureAwait(false);
|
||||
var corev1PodList = KubernetesJson.Deserialize<V1PodList>(MockPodResponse);
|
||||
await WriteStreamLine(httpContext, KubernetesJson.Serialize(corev1PodList.Items.First())).ConfigureAwait(false);
|
||||
break;
|
||||
case MockKubeServerFlags.Throw500:
|
||||
return false;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using k8s.Models;
|
||||
using k8s.Tests.Mock;
|
||||
using Newtonsoft.Json;
|
||||
using System.Text.Json;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace k8s.Tests
|
||||
{
|
||||
var v1Status = new V1Status { Message = "test message", Status = "test status" };
|
||||
|
||||
using (var server = new MockKubeApiServer(testOutput, resp: JsonConvert.SerializeObject(v1Status)))
|
||||
using (var server = new MockKubeApiServer(testOutput, resp: JsonSerializer.Serialize(v1Status)))
|
||||
{
|
||||
var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() });
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace k8s.Tests
|
||||
Status = new V1NamespaceStatus() { Phase = "test termating" },
|
||||
};
|
||||
|
||||
using (var server = new MockKubeApiServer(testOutput, resp: JsonConvert.SerializeObject(corev1Namespace)))
|
||||
using (var server = new MockKubeApiServer(testOutput, resp: KubernetesJson.Serialize(corev1Namespace)))
|
||||
{
|
||||
var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() });
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using k8s.Models;
|
||||
using Xunit;
|
||||
using FluentAssertions;
|
||||
using k8s.Versioning;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
@@ -12,8 +10,6 @@ using System.Threading.Tasks;
|
||||
using k8s.Models;
|
||||
using k8s.Tests.Mock;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Nito.AsyncEx;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
@@ -38,10 +34,8 @@ namespace k8s.Tests
|
||||
|
||||
private static string BuildWatchEventStreamLine(WatchEventType eventType)
|
||||
{
|
||||
var corev1PodList = JsonConvert.DeserializeObject<V1PodList>(MockKubeApiServer.MockPodResponse);
|
||||
return JsonConvert.SerializeObject(
|
||||
new Watcher<V1Pod>.WatchEvent { Type = eventType, Object = corev1PodList.Items.First() },
|
||||
new StringEnumConverter());
|
||||
var corev1PodList = KubernetesJson.Deserialize<V1PodList>(MockKubeApiServer.MockPodResponse);
|
||||
return KubernetesJson.Serialize(new Watcher<V1Pod>.WatchEvent { Type = eventType, Object = corev1PodList.Items.First() });
|
||||
}
|
||||
|
||||
private static async Task WriteStreamLine(HttpContext httpContext, string reponseLine)
|
||||
@@ -60,7 +54,7 @@ namespace k8s.Tests
|
||||
var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() });
|
||||
|
||||
// did not pass watch param
|
||||
var listTask = client.ListNamespacedPodWithHttpMessagesAsync("default");
|
||||
var listTask = client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true);
|
||||
var onErrorCalled = false;
|
||||
|
||||
using (listTask.Watch<V1Pod, V1PodList>((type, item) => { }, e => { onErrorCalled = true; }))
|
||||
@@ -508,9 +502,7 @@ namespace k8s.Tests
|
||||
var events = new HashSet<WatchEventType>();
|
||||
var errors = 0;
|
||||
|
||||
var watcher = await client.WatchNamespacedPodAsync(
|
||||
"myPod",
|
||||
"default",
|
||||
var watcher = client.ListNamespacedPodWithHttpMessagesAsync("default", fieldSelector: $"metadata.name=${"myPod"}", watch: true).Watch<V1Pod, V1PodList>(
|
||||
onEvent:
|
||||
(type, item) =>
|
||||
{
|
||||
@@ -527,7 +519,7 @@ namespace k8s.Tests
|
||||
errors += 1;
|
||||
eventsReceived.Signal();
|
||||
},
|
||||
onClosed: connectionClosed.Set).ConfigureAwait(false);
|
||||
onClosed: connectionClosed.Set);
|
||||
|
||||
// wait server yields all events
|
||||
await Task.WhenAny(eventsReceived.WaitAsync(), Task.Delay(TestTimeout)).ConfigureAwait(false);
|
||||
@@ -611,9 +603,7 @@ namespace k8s.Tests
|
||||
var events = new HashSet<WatchEventType>();
|
||||
var errors = 0;
|
||||
|
||||
var watcher = await client.WatchNamespacedPodAsync(
|
||||
"myPod",
|
||||
"default",
|
||||
var watcher = client.ListNamespacedPodWithHttpMessagesAsync("default", fieldSelector: $"metadata.name=${"myPod"}", watch: true).Watch<V1Pod, V1PodList>(
|
||||
onEvent:
|
||||
(type, item) =>
|
||||
{
|
||||
@@ -629,7 +619,7 @@ namespace k8s.Tests
|
||||
|
||||
errors += 1;
|
||||
eventsReceived.Signal();
|
||||
}).ConfigureAwait(false);
|
||||
});
|
||||
|
||||
// wait server yields all events
|
||||
await Task.WhenAny(eventsReceived.WaitAsync(), Task.Delay(TestTimeout)).ConfigureAwait(false);
|
||||
|
||||
Reference in New Issue
Block a user