diff --git a/src/KubernetesClient.Util/KubernetesClient.Util.csproj b/src/KubernetesClient.Util/KubernetesClient.Util.csproj
deleted file mode 100644
index febeee354..000000000
--- a/src/KubernetesClient.Util/KubernetesClient.Util.csproj
+++ /dev/null
@@ -1,42 +0,0 @@
-
-
-
- 9.0
- The Kubernetes Project Authors
- 2017 The Kubernetes Project Authors
- Supprting utilities for the kubernetes open source container orchestrator client library.
-
- Apache-2.0
- https://github.com/kubernetes-client/csharp
- https://raw.githubusercontent.com/kubernetes/kubernetes/master/logo/logo.png
- kubernetes;docker;containers;
-
- netstandard2.1;net5.0
- k8s.Util
- true
- true
-
-
- true
-
-
- true
- snupkg
- true
- $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/KubernetesClient/KubernetesClient.csproj b/src/KubernetesClient/KubernetesClient.csproj
index f75a5a8e7..e93e33241 100644
--- a/src/KubernetesClient/KubernetesClient.csproj
+++ b/src/KubernetesClient/KubernetesClient.csproj
@@ -5,13 +5,6 @@
k8s
-
-
-
-
-
-
-
diff --git a/src/KubernetesClient/Util/Common/BadNotificationException.cs b/src/KubernetesClient/Util/Common/BadNotificationException.cs
deleted file mode 100644
index aa5a5b58e..000000000
--- a/src/KubernetesClient/Util/Common/BadNotificationException.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-namespace k8s.Util.Common
-{
- public class BadNotificationException : Exception
- {
- public BadNotificationException()
- {
- }
-
- public BadNotificationException(string message)
- : base(message)
- {
- }
- }
-}
diff --git a/src/KubernetesClient/Util/Common/CallGeneratorParams.cs b/src/KubernetesClient/Util/Common/CallGeneratorParams.cs
deleted file mode 100644
index fbdc6ac2d..000000000
--- a/src/KubernetesClient/Util/Common/CallGeneratorParams.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-namespace k8s.Util.Common
-{
- public class CallGeneratorParams
- {
- public bool Watch { get; }
- public string ResourceVersion { get; }
- public int? TimeoutSeconds { get; }
-
- public CallGeneratorParams(bool watch, string resourceVersion, int? timeoutSeconds)
- {
- Watch = watch;
- ResourceVersion = resourceVersion;
- TimeoutSeconds = timeoutSeconds;
- }
- }
-}
diff --git a/src/KubernetesClient/Util/Common/CollectionsExtensions.cs b/src/KubernetesClient/Util/Common/CollectionsExtensions.cs
deleted file mode 100644
index 6e1b7a51a..000000000
--- a/src/KubernetesClient/Util/Common/CollectionsExtensions.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-namespace k8s.Util.Common
-{
- internal static class CollectionsExtensions
- {
- public static void AddRange(this HashSet hashSet, ICollection items)
- {
- if (items == null || hashSet == null)
- {
- return;
- }
-
- foreach (var item in items)
- {
- hashSet.Add(item);
- }
- }
-
- internal static TValue ComputeIfAbsent(this IDictionary dictionary, TKey key, Func mappingFunction)
- {
- if (dictionary is null)
- {
- throw new ArgumentNullException(nameof(dictionary));
- }
-
- if (dictionary.TryGetValue(key, out var value))
- {
- return value;
- }
-
- if (mappingFunction == null)
- {
- throw new ArgumentNullException(nameof(mappingFunction));
- }
-
- var newKey = mappingFunction(key);
- dictionary[key] = newKey;
- return newKey;
- }
- }
-}
diff --git a/src/KubernetesClient/Util/Common/Config.cs b/src/KubernetesClient/Util/Common/Config.cs
deleted file mode 100644
index f4609d841..000000000
--- a/src/KubernetesClient/Util/Common/Config.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-namespace k8s.Util.Common
-{
- public static class Config
- {
- public static string ServiceAccountCaPath => KubernetesClientConfiguration.ServiceAccountPath + "/ca.crt";
- public static string ServiceAccountTokenPath => KubernetesClientConfiguration.ServiceAccountPath + "/token";
- public static string ServiceAccountNamespacePath => KubernetesClientConfiguration.ServiceAccountPath + "/namespace";
- public static string EnvKubeconfig => "KUBECONFIG";
- public static string EnvServiceHost => "KUBERNETES_SERVICE_HOST";
- public static string EnvServicePort => "KUBERNETES_SERVICE_PORT";
-
- // The last resort host to try
- public static string DefaultFallbackHost => "http://localhost:8080";
- }
-}
diff --git a/src/KubernetesClient/Util/Common/Generic/GenericKubernetesApi.cs b/src/KubernetesClient/Util/Common/Generic/GenericKubernetesApi.cs
deleted file mode 100644
index a9e6ebb7d..000000000
--- a/src/KubernetesClient/Util/Common/Generic/GenericKubernetesApi.cs
+++ /dev/null
@@ -1,647 +0,0 @@
-using System.Threading;
-using System.Threading.Tasks;
-using k8s.Models;
-using k8s.Util.Common.Generic.Options;
-using k8s.Autorest;
-
-namespace k8s.Util.Common.Generic
-{
- ///
- ///
- /// The Generic kubernetes api provides a unified client interface for not only the non-core-group
- /// built-in resources from kubernetes but also the custom-resources models meet the following
- /// requirements:
- ///
- /// 1. there's a `V1ObjectMeta` field in the model along with its getter/setter. 2. there's a
- /// `V1ListMeta` field in the list model along with its getter/setter. - supports Json
- /// serialization/deserialization. 3. the generic kubernetes api covers all the basic operations over
- /// the custom resources including {get, list, watch, create, update, patch, delete}.
- ///
- /// - For kubernetes-defined failures, the server will return a {@link V1Status} with 4xx/5xx
- /// code. The status object will be nested in {@link KubernetesApiResponse#getStatus()} - For the
- /// other unknown reason (including network, JVM..), throws an unchecked exception.
- ///
- public class GenericKubernetesApi
- {
- private readonly string _apiGroup;
- private readonly string _apiVersion;
- private readonly string _resourcePlural;
- private readonly IKubernetes _client;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// the api group">
- /// the api version">
- /// the resource plural, e.g. "jobs"">
- /// optional client">
- public GenericKubernetesApi(string apiGroup = default, string apiVersion = default, string resourcePlural = default, IKubernetes apiClient = default)
- {
- _apiGroup = apiGroup ?? throw new ArgumentNullException(nameof(apiGroup));
- _apiVersion = apiVersion ?? throw new ArgumentNullException(nameof(apiVersion));
- _resourcePlural = resourcePlural ?? throw new ArgumentNullException(nameof(resourcePlural));
- _client = apiClient ?? new Kubernetes(KubernetesClientConfiguration.BuildDefaultConfig());
- }
-
- ///
- /// Get kubernetes object.
- ///
- /// the object type
- /// the object name
- /// the token
- /// The object
- public Task GetAsync(string name, CancellationToken cancellationToken = default)
- where T : class, IKubernetesObject
- {
- return GetAsync(name, new GetOptions(), cancellationToken);
- }
-
- ///
- /// Get kubernetes object under the namespaceProperty.
- ///
- /// the object type
- /// the namespaceProperty
- /// the name
- /// the token
- /// the kubernetes object
- public Task GetAsync(string namespaceProperty, string name, CancellationToken cancellationToken = default)
- where T : class, IKubernetesObject
- {
- return GetAsync(namespaceProperty, name, new GetOptions(), cancellationToken);
- }
-
- ///
- /// List kubernetes object cluster-scoped.
- ///
- /// the object type
- /// the token
- /// the kubernetes object
- public Task ListAsync(CancellationToken cancellationToken = default)
- where T : class, IKubernetesObject
- {
- return ListAsync(new ListOptions(), cancellationToken);
- }
-
- ///
- /// List kubernetes object under the namespaceProperty.
- ///
- /// the object type
- /// the namespace
- /// the token
- /// the kubernetes object
- public Task ListAsync(string namespaceProperty, CancellationToken cancellationToken = default)
- where T : class, IKubernetesObject
- {
- return ListAsync(namespaceProperty, new ListOptions(), cancellationToken);
- }
-
- ///
- /// Create kubernetes object, if the namespaceProperty in the object is present, it will send a
- /// namespaceProperty-scoped requests, vice versa.
- ///
- /// the object type
- /// the object
- /// the token
- /// the kubernetes object
- public Task CreateAsync(T obj, CancellationToken cancellationToken = default)
- where T : class, IKubernetesObject
- {
- return CreateAsync(obj, new CreateOptions(), cancellationToken);
- }
-
- ///
- /// Create kubernetes object, if the namespaceProperty in the object is present, it will send a
- /// namespaceProperty-scoped requests, vice versa.
- ///
- /// the object
- /// the token
- /// the object type
- /// the kubernetes object
- public Task UpdateAsync(T obj, CancellationToken cancellationToken = default)
- where T : class, IKubernetesObject
- {
- return UpdateAsync(obj, new UpdateOptions(), cancellationToken);
- }
-
- ///
- /// Patch kubernetes object.
- ///
- /// the name
- /// the string patch content
- /// the token
- /// the object type
- /// the kubernetes object
- public Task PatchAsync(string name, object patch, CancellationToken cancellationToken = default)
- where T : class, IKubernetesObject
- {
- return PatchAsync(name, patch, new PatchOptions(), cancellationToken);
- }
-
- ///
- /// Patch kubernetes object under the namespaceProperty.
- ///
- /// the namespaceProperty
- /// the name
- /// the string patch content
- /// the token
- /// the object type
- /// the kubernetes object
- public Task PatchAsync(string namespaceProperty, string name, object patch, CancellationToken cancellationToken = default)
- where T : class, IKubernetesObject
- {
- return PatchAsync(namespaceProperty, name, patch, new PatchOptions(), cancellationToken);
- }
-
- ///
- /// Delete kubernetes object.
- ///
- /// the name
- /// the token
- /// the object type
- /// the kubernetes object
- public Task DeleteAsync(string name, CancellationToken cancellationToken = default)
- where T : class, IKubernetesObject
- {
- return DeleteAsync(name, new V1DeleteOptions(), cancellationToken);
- }
-
- ///
- /// Delete kubernetes object under the namespaceProperty.
- ///
- /// the namespaceProperty
- /// the name
- /// the token
- /// the object type
- /// the kubernetes object
- public Task DeleteAsync(string namespaceProperty, string name, CancellationToken cancellationToken = default)
- where T : class, IKubernetesObject
- {
- return DeleteAsync(namespaceProperty, name, new V1DeleteOptions(), cancellationToken);
- }
-
- ///
- /// Creates a cluster-scoped Watch on the resource.
- ///
- /// action on event
- /// action on error
- /// action on closed
- /// the token
- /// the object type
- /// the watchable
- public Watcher Watch(Action onEvent, Action onError = default, Action onClosed = default, CancellationToken cancellationToken = default)
- where T : class, IKubernetesObject
- {
- return Watch(new ListOptions(), onEvent, onError, onClosed, cancellationToken);
- }
-
- ///
- /// Creates a namespaceProperty-scoped Watch on the resource.
- ///
- /// the object type
- /// the namespaceProperty
- /// action on event
- /// action on error
- /// action on closed
- /// the token
- /// the watchable
- public Watcher Watch(string namespaceProperty, Action onEvent, Action onError = default, Action onClosed = default,
- CancellationToken cancellationToken = default)
- where T : class, IKubernetesObject
- {
- return Watch(namespaceProperty, new ListOptions(), onEvent, onError, onClosed, cancellationToken);
- }
-
- // TODO(yue9944882): watch one resource?
-
- ///
- /// Get kubernetes object.
- ///
- /// the object type
- /// the name
- /// the get options
- /// the token
- /// the kubernetes object
- public async Task GetAsync(string name, GetOptions getOptions, CancellationToken cancellationToken = default)
- where T : class, IKubernetesObject
- {
- if (string.IsNullOrEmpty(name))
- {
- throw new ArgumentNullException(nameof(name));
- }
-
- var resp = await _client.CustomObjects.GetClusterCustomObjectWithHttpMessagesAsync(group: _apiGroup, plural: _resourcePlural, version: _apiVersion, name: name, cancellationToken: cancellationToken)
- .ConfigureAwait(false);
- return KubernetesJson.Deserialize(resp.Body.ToString());
- }
-
- ///
- /// Get kubernetes object.
- ///
- /// the object type
- /// the namespaceProperty
- /// the name
- /// the get options
- /// the token
- /// the kubernetes object
- public async Task GetAsync(string namespaceProperty, string name, GetOptions getOptions, CancellationToken cancellationToken = default)
- where T : class, IKubernetesObject
- {
- if (string.IsNullOrEmpty(name))
- {
- throw new ArgumentNullException(nameof(name));
- }
-
- if (string.IsNullOrEmpty(namespaceProperty))
- {
- throw new ArgumentNullException(nameof(namespaceProperty));
- }
-
- var resp = await _client.CustomObjects.GetNamespacedCustomObjectWithHttpMessagesAsync(group: _apiGroup, plural: _resourcePlural, version: _apiVersion, name: name, namespaceParameter: namespaceProperty,
- cancellationToken: cancellationToken).ConfigureAwait(false);
- return KubernetesJson.Deserialize(resp.Body.ToString());
- }
-
- ///
- /// List kubernetes object.
- ///
- /// the object type
- /// the list options
- /// the token
- /// the kubernetes object
- public async Task ListAsync(ListOptions listOptions, CancellationToken cancellationToken = default)
- where T : class, IKubernetesObject
- {
- if (listOptions == null)
- {
- throw new ArgumentNullException(nameof(listOptions));
- }
-
- 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,
- timeoutSeconds: listOptions.TimeoutSeconds, cancellationToken: cancellationToken).ConfigureAwait(false);
- return KubernetesJson.Deserialize(resp.Body.ToString());
- }
-
- ///
- /// List kubernetes object.
- ///
- /// the object type
- /// the namespaceProperty
- /// the list options
- /// the token
- /// the kubernetes object
- public async Task ListAsync(string namespaceProperty, ListOptions listOptions, CancellationToken cancellationToken = default)
- where T : class, IKubernetesObject
- {
- if (listOptions == null)
- {
- throw new ArgumentNullException(nameof(listOptions));
- }
-
- if (string.IsNullOrEmpty(namespaceProperty))
- {
- throw new ArgumentNullException(nameof(namespaceProperty));
- }
-
- 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,
- timeoutSeconds: listOptions.TimeoutSeconds, namespaceParameter: namespaceProperty, cancellationToken: cancellationToken).ConfigureAwait(false);
-
- return KubernetesJson.Deserialize(resp.Body.ToString());
- }
-
- ///
- /// Create kubernetes object.
- ///
- /// the object type
- /// the object
- /// the create options
- /// the token
- /// the kubernetes object
- public async Task CreateAsync(T obj, CreateOptions createOptions, CancellationToken cancellationToken = default)
- where T : class, IKubernetesObject
- {
- if (obj == null)
- {
- throw new ArgumentNullException(nameof(obj));
- }
-
- if (createOptions == null)
- {
- throw new ArgumentNullException(nameof(createOptions));
- }
-
- V1ObjectMeta objectMeta = obj.Metadata;
-
- var isNamespaced = !string.IsNullOrEmpty(objectMeta.NamespaceProperty);
- if (isNamespaced)
- {
- return await CreateAsync(objectMeta.NamespaceProperty, obj, createOptions, cancellationToken).ConfigureAwait(false);
- }
-
- var resp = await _client.CustomObjects.CreateClusterCustomObjectWithHttpMessagesAsync(body: obj, group: _apiGroup, plural: _resourcePlural, version: _apiVersion, dryRun: createOptions.DryRun,
- fieldManager: createOptions.FieldManager, cancellationToken: cancellationToken).ConfigureAwait(false);
-
- return KubernetesJson.Deserialize(resp.Body.ToString());
- }
-
- ///
- /// Create namespaced kubernetes object.
- ///
- /// the object type
- /// the namespace
- /// the object
- /// the create options
- /// the token
- /// the kubernetes object
- public async Task CreateAsync(string namespaceProperty, T obj, CreateOptions createOptions, CancellationToken cancellationToken = default)
- where T : class, IKubernetesObject
- {
- if (obj == null)
- {
- throw new ArgumentNullException(nameof(obj));
- }
-
- if (createOptions == null)
- {
- throw new ArgumentNullException(nameof(createOptions));
- }
-
- 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);
-
- return KubernetesJson.Deserialize(resp.Body.ToString());
- }
-
- ///
- /// Update kubernetes object.
- ///
- /// the object type
- /// the object
- /// the update options
- /// the token
- /// the kubernetes object
- public async Task UpdateAsync(T obj, UpdateOptions updateOptions, CancellationToken cancellationToken = default)
- where T : class, IKubernetesObject
- {
- if (obj == null)
- {
- throw new ArgumentNullException(nameof(obj));
- }
-
- if (updateOptions == null)
- {
- throw new ArgumentNullException(nameof(updateOptions));
- }
-
- V1ObjectMeta objectMeta = obj.Metadata;
-
- var isNamespaced = !string.IsNullOrEmpty(objectMeta.NamespaceProperty);
- HttpOperationResponse
-
-
-
-
-
-
-
diff --git a/tests/KubernetesClient.Tests/Util/Common/Generic/GenericKubernetesApiTest.cs b/tests/KubernetesClient.Tests/Util/Common/Generic/GenericKubernetesApiTest.cs
deleted file mode 100644
index 3475de856..000000000
--- a/tests/KubernetesClient.Tests/Util/Common/Generic/GenericKubernetesApiTest.cs
+++ /dev/null
@@ -1,109 +0,0 @@
-using System.Linq;
-using System.Threading;
-using System.Threading.Tasks;
-using FluentAssertions;
-using k8s.Models;
-using k8s.Tests.Mock;
-using k8s.Util.Common;
-using Xunit;
-using Xunit.Abstractions;
-
-namespace k8s.Tests.Util.Common.Generic
-{
- public class GenericKubernetesApiTest
- {
- private readonly ITestOutputHelper _outputHelper;
-
- public GenericKubernetesApiTest(ITestOutputHelper outputHelper)
- {
- _outputHelper = outputHelper;
- }
-
- [Fact(DisplayName = "Create constructor success")]
- public void CreateConstSuccess()
- {
- using var server = new MockKubeApiServer(_outputHelper);
- var genericApi = Helpers.BuildGenericApi(server.Uri);
- genericApi.Should().NotBeNull();
- }
-
- [Fact(DisplayName = "Get namespaced object success")]
- public async Task GetNamespacedObject()
- {
- var serverOptions = new MockKubeApiServerOptions(MockKubeServerFlags.GetPod);
- using var server = new MockKubeApiServer(_outputHelper, serverOptions.ShouldNext);
- var podName = "nginx-1493591563-xb2v4";
- var genericApi = Helpers.BuildGenericApi(server.Uri);
-
- var resp = await genericApi.GetAsync(Namespaces.NamespaceDefault, podName).ConfigureAwait(false);
-
- resp.Should().NotBeNull();
- resp.Metadata.Name.Should().Be(podName);
- resp.Metadata.NamespaceProperty.Should().Be(Namespaces.NamespaceDefault);
- }
-
- [Fact(DisplayName = "List namespaced object success")]
- public async Task ListNamespacedObject()
- {
- var serverOptions = new MockKubeApiServerOptions(MockKubeServerFlags.ListPods);
- using var server = new MockKubeApiServer(_outputHelper, serverOptions.ShouldNext);
- var genericApi = Helpers.BuildGenericApi(server.Uri);
-
- var resp = await genericApi.ListAsync(Namespaces.NamespaceDefault).ConfigureAwait(false);
-
- resp.Should().NotBeNull();
- resp.Items.Should().NotBeNull();
- }
-
- [Fact(DisplayName = "Patch namespaced object success")]
- public async Task PatchNamespacedObject()
- {
- using var server = new MockKubeApiServer(_outputHelper);
- var podName = "nginx-1493591563-xb2v4";
- var genericApi = Helpers.BuildGenericApi(server.Uri);
-
- var resp = await genericApi.PatchAsync(Namespaces.NamespaceDefault, podName).ConfigureAwait(false);
-
- resp.Should().NotBeNull();
- }
-
- [Fact(DisplayName = "Update object success")]
- public async Task UpdateObject()
- {
- using var server = new MockKubeApiServer(_outputHelper);
- var pod = Helpers.CreatePods(1).First();
- var genericApi = Helpers.BuildGenericApi(server.Uri);
-
- var resp = await genericApi.UpdateAsync(pod).ConfigureAwait(false);
-
- resp.Should().NotBeNull();
- }
-
- [Fact(DisplayName = "Delete namespaced object success")]
- public async Task DeleteNamespacedObject()
- {
- using var server = new MockKubeApiServer(_outputHelper);
- var podName = "nginx-1493591563-xb2v4";
- var genericApi = Helpers.BuildGenericApi(server.Uri);
-
- var resp = await genericApi.DeleteAsync(Namespaces.NamespaceDefault, podName).ConfigureAwait(false);
-
- resp.Should().NotBeNull();
- }
-
- [Fact(DisplayName = "Watch namespaced object success")]
- public void WatchNamespacedObject()
- {
- using var cts = new CancellationTokenSource();
- var serverOptions = new MockKubeApiServerOptions(MockKubeServerFlags.ModifiedPod);
- using var server = new MockKubeApiServer(_outputHelper, serverOptions.ShouldNext);
- var genericApi = Helpers.BuildGenericApi(server.Uri);
-
- using var resp = genericApi.Watch(Namespaces.NamespaceDefault, (actionType, pod) => { }, exception => { }, () => { }, cts.Token);
-
- resp.Should().NotBeNull();
- cts.CancelAfter(1000);
- serverOptions.ServerShutdown?.Set();
- }
- }
-}
diff --git a/tests/KubernetesClient.Tests/Util/Helpers.cs b/tests/KubernetesClient.Tests/Util/Helpers.cs
deleted file mode 100644
index 87a972131..000000000
--- a/tests/KubernetesClient.Tests/Util/Helpers.cs
+++ /dev/null
@@ -1,67 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading;
-using k8s.Models;
-using k8s.Util.Common.Generic;
-
-namespace k8s.Tests.Util
-{
- internal static class Helpers
- {
- public static IEnumerable CreatePods(int cnt)
- {
- var pods = new List();
- for (var i = 0; i < cnt; i++)
- {
- pods.Add(new V1Pod()
- {
- ApiVersion = "Pod/V1",
- Kind = "Pod",
- Metadata = new V1ObjectMeta()
- {
- Name = Guid.NewGuid().ToString(),
- NamespaceProperty = "the-namespace",
- ResourceVersion = DateTime.Now.Ticks.ToString(),
- },
- });
- }
-
- return pods;
- }
-
- public static V1PodList CreatePodList(int cnt)
- {
- return new V1PodList()
- {
- ApiVersion = "Pod/V1",
- Kind = "Pod",
- Metadata = new V1ListMeta()
- {
- ResourceVersion = DateTime.Now.Ticks.ToString(),
- },
- Items = CreatePods(cnt).ToList(),
- };
- }
-
- public static Kubernetes BuildApiClient(Uri hostAddress)
- {
- return new Kubernetes(new KubernetesClientConfiguration { Host = hostAddress.ToString() })
- {
- HttpClient =
- {
- Timeout = Timeout.InfiniteTimeSpan,
- },
- };
- }
-
- public static GenericKubernetesApi BuildGenericApi(Uri hostAddress)
- {
- return new GenericKubernetesApi(
- apiGroup: "pod",
- apiVersion: "v1",
- resourcePlural: "pods",
- apiClient: BuildApiClient(hostAddress));
- }
- }
-}
diff --git a/tests/KubernetesClient.Tests/Util/Informer/Cache/CacheTest.cs b/tests/KubernetesClient.Tests/Util/Informer/Cache/CacheTest.cs
deleted file mode 100644
index d97d647e3..000000000
--- a/tests/KubernetesClient.Tests/Util/Informer/Cache/CacheTest.cs
+++ /dev/null
@@ -1,335 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using FluentAssertions;
-using k8s.Models;
-using k8s.Util.Informer.Cache;
-using Xunit;
-
-namespace k8s.Tests.Util.Informer.Cache
-{
- public class CacheTest
- {
- [Fact(DisplayName = "Create default cache success")]
- public void CreateCacheSuccess()
- {
- var cache = new Cache();
- cache.Should().NotBeNull();
- cache.GetIndexers().ContainsKey(Caches.NamespaceIndex).Should().BeTrue();
- }
-
- [Fact(DisplayName = "Add cache item success")]
- public void AddCacheItemSuccess()
- {
- var aPod = Helpers.CreatePods(1).First();
- var cache = new Cache();
-
- cache.Add(aPod);
-
- cache.Get(aPod).Equals(aPod).Should().BeTrue();
- }
-
- [Fact(DisplayName = "Update cache item success")]
- public void UpdateCacheItemSuccess()
- {
- var aPod = Helpers.CreatePods(1).First();
-
- var cache = new Cache();
-
- cache.Add(aPod);
- aPod.Kind = "another-kind";
- cache.Update(aPod);
-
- cache.Get(aPod).Kind.Equals(aPod.Kind).Should().BeTrue();
- }
-
- [Fact(DisplayName = "Delete cache item success")]
- public void DeleteCacheItemSuccess()
- {
- var aPod = Helpers.CreatePods(1).First();
-
- var cache = new Cache();
-
- cache.Add(aPod);
- cache.Delete(aPod);
-
- // Todo: check indices for removed item
- cache.Get(aPod).Should().BeNull();
- }
-
- [Fact(DisplayName = "Replace cache items success")]
- public void ReplaceCacheItemsSuccess()
- {
- var pods = Helpers.CreatePods(3);
- var aPod = pods.First();
- var anotherPod = pods.Skip(1).First();
- var yetAnotherPod = pods.Skip(2).First();
-
- var cache = new Cache();
-
- cache.Add(aPod);
- cache.Replace(new[] { anotherPod, yetAnotherPod });
-
- // Todo: check indices for replaced items
- cache.Get(anotherPod).Should().NotBeNull();
- cache.Get(yetAnotherPod).Should().NotBeNull();
- }
-
- [Fact(DisplayName = "List item keys success")]
- public void ListItemKeysSuccess()
- {
- var pods = Helpers.CreatePods(3);
- var aPod = pods.First();
- var anotherPod = pods.Skip(1).First();
- var cache = new Cache();
-
- cache.Add(aPod);
- cache.Add(anotherPod);
-
- var keys = cache.ListKeys();
-
- keys.Should().Contain($"{aPod.Metadata.NamespaceProperty}/{aPod.Metadata.Name}");
- keys.Should().Contain($"{anotherPod.Metadata.NamespaceProperty}/{anotherPod.Metadata.Name}");
- }
-
- [Fact(DisplayName = "Get item doesn't exist")]
- public void GetItemNotExist()
- {
- var aPod = Helpers.CreatePods(1).First();
- var cache = new Cache();
-
- var item = cache.Get(aPod);
- item.Should().BeNull();
- }
-
- [Fact(DisplayName = "Get item success")]
- public void GetItemSuccess()
- {
- var aPod = Helpers.CreatePods(1).First();
- var cache = new Cache();
-
- cache.Add(aPod);
- var item = cache.Get(aPod);
- item.Equals(aPod).Should().BeTrue();
- }
-
- [Fact(DisplayName = "List items success")]
- public void ListItemSuccess()
- {
- var pods = Helpers.CreatePods(3);
- var aPod = pods.First();
- var anotherPod = pods.Skip(1).First();
- var yetAnotherPod = pods.Skip(2).First();
-
- var cache = new Cache();
-
- cache.Add(aPod);
- cache.Add(anotherPod);
- cache.Add(yetAnotherPod);
-
- var items = cache.List();
- items.Should().HaveCount(3);
- items.Should().Contain(aPod);
- items.Should().Contain(anotherPod);
- items.Should().Contain(yetAnotherPod);
- }
-
- [Fact(DisplayName = "Get item by key success")]
- public void GetItemByKeySuccess()
- {
- var pod = Helpers.CreatePods(1).First();
- var cache = new Cache();
-
- cache.Add(pod);
- var item = cache.GetByKey($"{pod.Metadata.NamespaceProperty}/{pod.Metadata.Name}");
- item.Should().NotBeNull();
- }
-
- [Fact(DisplayName = "Index items no index")]
- public void IndexItemsNoIndex()
- {
- var pod = Helpers.CreatePods(1).First();
-
- var cache = new Cache();
-
- cache.Add(pod);
-
- Assert.Throws(() => { cache.Index("asdf", pod); });
- }
-
- [Fact(DisplayName = "Index items success")]
- public void IndexItemsSuccess()
- {
- var pod = Helpers.CreatePods(1).First();
-
- var cache = new Cache();
-
- cache.Add(pod);
-
- var items = cache.Index("namespace", pod);
-
- items.Should().Contain(pod);
- }
-
- [Fact(DisplayName = "Get index keys no index")]
- public void GetIndexKeysNoIndex()
- {
- var cache = new Cache();
-
- Assert.Throws(() => { cache.IndexKeys("a", "b"); });
- }
-
- [Fact(DisplayName = "Get index keys no indice item")]
- public void GetIndexKeysNoIndiceItem()
- {
- var cache = new Cache();
-
- Assert.Throws(() => { cache.IndexKeys("namespace", "b"); });
- }
-
- [Fact(DisplayName = "Get index keys success")]
- public void GetIndexKeysSuccess()
- {
- var pod = Helpers.CreatePods(1).First();
-
- var cache = new Cache();
-
- cache.Add(pod);
- var keys = cache.IndexKeys("namespace", pod.Metadata.NamespaceProperty);
-
- keys.Should().NotBeNull();
- keys.Should().Contain(Caches.MetaNamespaceKeyFunc(pod));
- }
-
- [Fact(DisplayName = "List by index no index")]
- public void ListByIndexNoIndex()
- {
- var cache = new Cache();
-
- Assert.Throws(() => { cache.ByIndex("a", "b"); });
- }
-
- [Fact(DisplayName = "List by index no indice item")]
- public void ListByIndexNoIndiceItem()
- {
- var cache = new Cache();
-
- Assert.Throws(() => { cache.ByIndex("namespace", "b"); });
- }
-
- [Fact(DisplayName = "List by index success")]
- public void ListByIndexSuccess()
- {
- var pod = Helpers.CreatePods(1).First();
-
- var cache = new Cache();
-
- cache.Add(pod);
- var items = cache.ByIndex("namespace", pod.Metadata.NamespaceProperty);
-
- items.Should().Contain(pod);
- }
-
- /* Add Indexers */
- [Fact(DisplayName = "Add null indexers")]
- public void AddNullIndexers()
- {
- var cache = new Cache();
- Assert.Throws(() => { cache.AddIndexers(null); });
- }
-
- [Fact(DisplayName = "Add indexers with conflict")]
- public void AddIndexersConflict()
- {
- var cache = new Cache();
- Dictionary>> initialIndexers = new Dictionary>>()
- {
- { "1", pod => new List() },
- { "2", pod => new List() },
- };
- Dictionary>> conflictIndexers = new Dictionary>>()
- {
- { "1", pod => new List() },
- };
-
- cache.AddIndexers(initialIndexers);
- Assert.Throws(() => { cache.AddIndexers(conflictIndexers); });
- }
-
- [Fact(DisplayName = "Add indexers success")]
- public void AddIndexersSuccess()
- {
- var cache = new Cache();
- Dictionary>> indexers = new Dictionary>>()
- {
- { "2", pod => new List() { pod.Name() } },
- { "3", pod => new List() { pod.Name() } },
- };
-
- cache.AddIndexers(indexers);
-
- var savedIndexers = cache.GetIndexers();
- savedIndexers.Should().HaveCount(indexers.Count + 1); // blank cache constructor will add a default index
- savedIndexers.Should().Contain(indexers);
-
- // Todo: check indicies collection for new indexname keys
- }
-
- /* Add Index Function */
- [Fact(DisplayName = "Add index function success")]
- public void AddIndexFuncSuccess()
- {
- var cache = new Cache();
- cache.AddIndexFunc("1", pod => new List() { pod.Name() });
-
- var savedIndexers = cache.GetIndexers();
- savedIndexers.Should().HaveCount(2);
-
- // Todo: check indicies collection for new indexname keys
- }
-
- /* Get Key Function */
- [Fact(DisplayName = "Get default key function success")]
- public void GetDefaultKeyFuncSuccess()
- {
- var pod = new V1Pod()
- {
- Metadata = new V1ObjectMeta()
- {
- Name = "a-name",
- NamespaceProperty = "the-namespace",
- },
- };
- var cache = new Cache();
- var defaultReturnValue = Caches.DeletionHandlingMetaNamespaceKeyFunc(pod);
-
- var funcReturnValue = cache.KeyFunc(pod);
-
- Assert.True(defaultReturnValue.Equals(funcReturnValue));
- }
-
- /* Set Key Function */
- [Fact(DisplayName = "Set key function success")]
- public void SetKeyFuncSuccess()
- {
- var aPod = new V1Pod()
- {
- Kind = "some-kind",
- Metadata = new V1ObjectMeta()
- {
- Name = "a-name",
- NamespaceProperty = "the-namespace",
- },
- };
- var cache = new Cache();
- var newFunc = new Func, string>((pod) => pod.Kind);
- var defaultReturnValue = newFunc(aPod);
-
- cache.SetKeyFunc(newFunc);
-
- var funcReturnValue = cache.KeyFunc(aPod);
-
- Assert.True(defaultReturnValue.Equals(funcReturnValue));
- }
- }
-}
diff --git a/tests/KubernetesClient.Tests/Util/Informer/Cache/CachesTest.cs b/tests/KubernetesClient.Tests/Util/Informer/Cache/CachesTest.cs
deleted file mode 100644
index 312a75b1b..000000000
--- a/tests/KubernetesClient.Tests/Util/Informer/Cache/CachesTest.cs
+++ /dev/null
@@ -1,60 +0,0 @@
-using System;
-using System.Linq;
-using FluentAssertions;
-using k8s.Models;
-using Xunit;
-using k8s.Util.Informer.Cache;
-
-namespace k8s.Tests.Util.Informer.Cache
-{
- public class CachesTest
- {
- [Fact(DisplayName = "Check for default DeletedFinalStateUnknown")]
- public void CheckDefaultDeletedFinalStateUnknown()
- {
- var aPod = Helpers.CreatePods(1).First();
- Caches.DeletionHandlingMetaNamespaceKeyFunc(aPod).Should().Be($"{aPod.Metadata.NamespaceProperty}/{aPod.Metadata.Name}");
- }
-
- [Fact(DisplayName = "Check for obj DeletedFinalStateUnknown")]
- public void CheckObjDeletedFinalStateUnknown()
- {
- var aPod = Helpers.CreatePods(1).First();
- var key = "a-key";
- var deletedPod = new DeletedFinalStateUnknown(key, aPod);
-
- var returnKey = Caches.DeletionHandlingMetaNamespaceKeyFunc(deletedPod);
-
- // returnKey.Should().Be(key);
- }
-
- [Fact(DisplayName = "Get default namespace key null")]
- public void GetDefaultNamespaceKeyNull()
- {
- Assert.Throws(() => { Caches.MetaNamespaceKeyFunc(null); });
- }
-
- [Fact(DisplayName = "Get default namespace key success")]
- public void GetDefaultNamespaceKeySuccess()
- {
- var aPod = Helpers.CreatePods(1).First();
- Caches.MetaNamespaceKeyFunc(aPod).Should().Be($"{aPod.Metadata.NamespaceProperty}/{aPod.Metadata.Name}");
- }
-
- [Fact(DisplayName = "Get default namespace index null")]
- public void GetDefaultNamespaceIndexNull()
- {
- Assert.Throws(() => { Caches.MetaNamespaceIndexFunc(null); });
- }
-
- [Fact(DisplayName = "Get default namespace index success")]
- public void GetDefaultNamespaceIndexSuccess()
- {
- var aPod = Helpers.CreatePods(1).First();
- var indexes = Caches.MetaNamespaceIndexFunc(aPod);
-
- indexes.Should().NotBeNull();
- indexes.Should().Contain(aPod.Metadata.NamespaceProperty);
- }
- }
-}
diff --git a/tests/KubernetesClient.Tests/Util/Informer/Cache/ListerTest.cs b/tests/KubernetesClient.Tests/Util/Informer/Cache/ListerTest.cs
deleted file mode 100644
index 6a6003a03..000000000
--- a/tests/KubernetesClient.Tests/Util/Informer/Cache/ListerTest.cs
+++ /dev/null
@@ -1,95 +0,0 @@
-using System.Linq;
-using FluentAssertions;
-using k8s.Models;
-using k8s.Util.Informer.Cache;
-using Xunit;
-
-namespace k8s.Tests.Util.Informer.Cache
-{
- public class ListerTest
- {
- [Fact(DisplayName = "Create default lister success")]
- public void CreateListerDefaultsSuccess()
- {
- var cache = new Cache();
- var lister = new Lister(cache);
-
- lister.Should().NotBeNull();
- }
-
- [Fact(DisplayName = "List with null namespace success")]
- public void ListNullNamespaceSuccess()
- {
- var aPod = Helpers.CreatePods(1).First();
- var cache = new Cache();
- var lister = new Lister(cache);
-
- cache.Add(aPod);
- var pods = lister.List();
-
- pods.Should().HaveCount(1);
- pods.Should().Contain(aPod);
- // Can't 'Get' the pod due to no namespace specified in Lister constructor
- }
-
- [Fact(DisplayName = "List with custom namespace success")]
- public void ListCustomNamespaceSuccess()
- {
- var aPod = Helpers.CreatePods(1).First();
- var cache = new Cache();
- var lister = new Lister(cache, aPod.Metadata.NamespaceProperty);
-
- cache.Add(aPod);
- var pods = lister.List();
-
- pods.Should().HaveCount(1);
- pods.Should().Contain(aPod);
- lister.Get(aPod.Metadata.Name).Should().Be(aPod);
- }
-
- [Fact(DisplayName = "Get with null namespace success")]
- public void GetNullNamespaceSuccess()
- {
- var aPod = Helpers.CreatePods(1).First();
- var cache = new Cache();
- var lister = new Lister(cache);
-
- cache.Add(aPod);
- var pod = lister.Get(aPod.Metadata.Name);
-
- // it's null because the namespace was not set in Lister constructor, but the pod did have a namespace.
- // So it can't build the right key name for lookup in Cache
- pod.Should().BeNull();
- }
-
- [Fact(DisplayName = "Get with custom namespace success")]
- public void GetCustomNamespaceSuccess()
- {
- var aPod = Helpers.CreatePods(1).First();
- var cache = new Cache();
- var lister = new Lister(cache, aPod.Metadata.NamespaceProperty);
-
- cache.Add(aPod);
- var pod = lister.Get(aPod.Metadata.Name);
-
- pod.Should().Be(aPod);
- }
-
- [Fact(DisplayName = "Set custom namespace success")]
- public void SetCustomNamespaceSuccess()
- {
- var aPod = Helpers.CreatePods(1).First();
- var cache = new Cache();
- var lister = new Lister(cache);
-
- cache.Add(aPod);
- var pod = lister.Get(aPod.Metadata.Name);
- pod.Should().BeNull();
-
- lister = lister.Namespace(aPod.Metadata.NamespaceProperty);
-
- pod = lister.Get(aPod.Metadata.Name);
- pod.Should().Be(aPod);
- }
- }
-}
diff --git a/tests/KubernetesClient.Tests/Util/MockKubeApiServerOptions.cs b/tests/KubernetesClient.Tests/Util/MockKubeApiServerOptions.cs
deleted file mode 100644
index 08c1971a1..000000000
--- a/tests/KubernetesClient.Tests/Util/MockKubeApiServerOptions.cs
+++ /dev/null
@@ -1,167 +0,0 @@
-using System;
-using System.Linq;
-using System.Net;
-using System.Threading.Tasks;
-using k8s.Models;
-using Microsoft.AspNetCore.Http;
-using Nito.AsyncEx;
-
-namespace k8s.Tests.Util
-{
- ///
- /// Flags to configure how the server will respond to requests
- ///
- [Flags]
- public enum MockKubeServerFlags
- {
- ///
- /// No flag
- ///
- None = 0,
-
- ///
- /// Include a response with malformed json
- ///
- BadJson = 1,
-
- ///
- /// Include a pod added response
- ///
- AddedPod = 2,
-
- ///
- /// Include a pod delete response
- ///
- DeletedPod = 4,
-
- ///
- /// Include a pod modified response
- ///
- ModifiedPod = 8,
-
- ///
- /// Include a pod error response
- ///
- ErrorPod = 16,
-
- ///
- /// Include a response of pod list
- ///
- ListPods = 32,
-
- ///
- /// Include a reponse of get pod
- ///
- GetPod = 64,
-
- ///
- /// Throw a 500 Http status code on any request
- ///
- Throw500 = 128,
- }
-
- internal class MockKubeApiServerOptions
- {
- // paste from minikube /api/v1/namespaces/default/pods
- public const string MockPodResponse =
- "{\r\n \"kind\": \"PodList\",\r\n \"apiVersion\": \"v1\",\r\n \"metadata\": {\r\n \"selfLink\": \"/api/v1/namespaces/default/pods\",\r\n \"resourceVersion\": \"1762810\"\r\n },\r\n \"items\": [\r\n {\r\n \"metadata\": {\r\n \"name\": \"nginx-1493591563-xb2v4\",\r\n \"generateName\": \"nginx-1493591563-\",\r\n \"namespace\": \"default\",\r\n \"selfLink\": \"/api/v1/namespaces/default/pods/nginx-1493591563-xb2v4\",\r\n \"uid\": \"ac1abb94-9c58-11e7-aaf5-00155d744505\",\r\n \"resourceVersion\": \"1737928\",\r\n \"creationTimestamp\": \"2017-09-18T10:03:51Z\",\r\n \"labels\": {\r\n \"app\": \"nginx\",\r\n \"pod-template-hash\": \"1493591563\"\r\n },\r\n \"annotations\": {\r\n \"kubernetes.io/created-by\": \"{\\\"kind\\\":\\\"SerializedReference\\\",\\\"apiVersion\\\":\\\"v1\\\",\\\"reference\\\":{\\\"kind\\\":\\\"ReplicaSet\\\",\\\"namespace\\\":\\\"default\\\",\\\"name\\\":\\\"nginx-1493591563\\\",\\\"uid\\\":\\\"ac013b63-9c58-11e7-aaf5-00155d744505\\\",\\\"apiVersion\\\":\\\"extensions\\\",\\\"resourceVersion\\\":\\\"5306\\\"}}\\n\"\r\n },\r\n \"ownerReferences\": [\r\n {\r\n \"apiVersion\": \"extensions/v1beta1\",\r\n \"kind\": \"ReplicaSet\",\r\n \"name\": \"nginx-1493591563\",\r\n \"uid\": \"ac013b63-9c58-11e7-aaf5-00155d744505\",\r\n \"controller\": true,\r\n \"blockOwnerDeletion\": true\r\n }\r\n ]\r\n },\r\n \"spec\": {\r\n \"volumes\": [\r\n {\r\n \"name\": \"default-token-3zzcj\",\r\n \"secret\": {\r\n \"secretName\": \"default-token-3zzcj\",\r\n \"defaultMode\": 420\r\n }\r\n }\r\n ],\r\n \"containers\": [\r\n {\r\n \"name\": \"nginx\",\r\n \"image\": \"nginx\",\r\n \"resources\": {},\r\n \"volumeMounts\": [\r\n {\r\n \"name\": \"default-token-3zzcj\",\r\n \"readOnly\": true,\r\n \"mountPath\": \"/var/run/secrets/kubernetes.io/serviceaccount\"\r\n }\r\n ],\r\n \"terminationMessagePath\": \"/dev/termination-log\",\r\n \"terminationMessagePolicy\": \"File\",\r\n \"imagePullPolicy\": \"Always\"\r\n }\r\n ],\r\n \"restartPolicy\": \"Always\",\r\n \"terminationGracePeriodSeconds\": 30,\r\n \"dnsPolicy\": \"ClusterFirst\",\r\n \"serviceAccountName\": \"default\",\r\n \"serviceAccount\": \"default\",\r\n \"nodeName\": \"ubuntu\",\r\n \"securityContext\": {},\r\n \"schedulerName\": \"default-scheduler\"\r\n },\r\n \"status\": {\r\n \"phase\": \"Running\",\r\n \"conditions\": [\r\n {\r\n \"type\": \"Initialized\",\r\n \"status\": \"True\",\r\n \"lastProbeTime\": null,\r\n \"lastTransitionTime\": \"2017-09-18T10:03:51Z\"\r\n },\r\n {\r\n \"type\": \"Ready\",\r\n \"status\": \"True\",\r\n \"lastProbeTime\": null,\r\n \"lastTransitionTime\": \"2017-10-12T07:09:21Z\"\r\n },\r\n {\r\n \"type\": \"PodScheduled\",\r\n \"status\": \"True\",\r\n \"lastProbeTime\": null,\r\n \"lastTransitionTime\": \"2017-09-18T10:03:51Z\"\r\n }\r\n ],\r\n \"hostIP\": \"192.168.188.42\",\r\n \"podIP\": \"172.17.0.5\",\r\n \"startTime\": \"2017-09-18T10:03:51Z\",\r\n \"containerStatuses\": [\r\n {\r\n \"name\": \"nginx\",\r\n \"state\": {\r\n \"running\": {\r\n \"startedAt\": \"2017-10-12T07:09:20Z\"\r\n }\r\n },\r\n \"lastState\": {\r\n \"terminated\": {\r\n \"exitCode\": 0,\r\n \"reason\": \"Completed\",\r\n \"startedAt\": \"2017-10-10T21:35:51Z\",\r\n \"finishedAt\": \"2017-10-12T07:07:37Z\",\r\n \"containerID\": \"docker://94df3f3965807421ad6dc76618e00b76cb15d024919c4946f3eb46a92659c62a\"\r\n }\r\n },\r\n \"ready\": true,\r\n \"restartCount\": 7,\r\n \"image\": \"nginx:latest\",\r\n \"imageID\": \"docker-pullable://nginx@sha256:004ac1d5e791e705f12a17c80d7bb1e8f7f01aa7dca7deee6e65a03465392072\",\r\n \"containerID\": \"docker://fa11bdd48c9b7d3a6c4c3f9b6d7319743c3455ab8d00c57d59c083b319b88194\"\r\n }\r\n ],\r\n \"qosClass\": \"BestEffort\"\r\n }\r\n }\r\n ]\r\n}";
-
- public AsyncManualResetEvent ServerShutdown { get; private set; }
-
- private readonly MockKubeServerFlags _serverFlags;
- private readonly string _mockAddedEventStreamLine = BuildWatchEventStreamLine(WatchEventType.Added);
- private readonly string _mockDeletedStreamLine = BuildWatchEventStreamLine(WatchEventType.Deleted);
- private readonly string _mockModifiedStreamLine = BuildWatchEventStreamLine(WatchEventType.Modified);
- private readonly string _mockErrorStreamLine = BuildWatchEventStreamLine(WatchEventType.Error);
- private const string MockBadStreamLine = "bad json";
-
- public MockKubeApiServerOptions(MockKubeServerFlags? serverFlags)
- {
- _serverFlags = serverFlags ?? MockKubeServerFlags.None;
- }
-
- private static string BuildWatchEventStreamLine(WatchEventType eventType)
- {
- var corev1PodList = KubernetesJson.Deserialize(MockPodResponse);
- return KubernetesJson.Serialize(new Watcher.WatchEvent { Type = eventType, Object = corev1PodList.Items.First() });
- }
-
- private async Task WriteStreamLine(HttpContext httpContext, string reponseLine)
- {
- const string crlf = "\r\n";
- await httpContext.Response.WriteAsync(reponseLine.Replace(crlf, "")).ConfigureAwait(false);
- await httpContext.Response.WriteAsync(crlf).ConfigureAwait(false);
- await httpContext.Response.Body.FlushAsync().ConfigureAwait(false);
- }
-
- public async Task ShouldNext(HttpContext httpContext)
- {
- var isWatch = (httpContext.Request.Query.ContainsKey("watch") && httpContext.Request.Query["watch"] == "true");
- var returnStatusCode = (_serverFlags.HasFlag(MockKubeServerFlags.Throw500) ? HttpStatusCode.InternalServerError : HttpStatusCode.OK);
-
- httpContext.Response.StatusCode = (int)returnStatusCode;
- httpContext.Response.ContentLength = null;
-
- if (isWatch)
- {
- ServerShutdown = new AsyncManualResetEvent();
-
- foreach (Enum flag in Enum.GetValues(_serverFlags.GetType()))
- {
- if (!_serverFlags.HasFlag(flag))
- {
- continue;
- }
-
- switch (flag)
- {
- case MockKubeServerFlags.AddedPod:
- await WriteStreamLine(httpContext, _mockAddedEventStreamLine).ConfigureAwait(false);
- break;
- case MockKubeServerFlags.ErrorPod:
- await WriteStreamLine(httpContext, _mockErrorStreamLine).ConfigureAwait(false);
- break;
- case MockKubeServerFlags.DeletedPod:
- await WriteStreamLine(httpContext, _mockDeletedStreamLine).ConfigureAwait(false);
- break;
- case MockKubeServerFlags.ModifiedPod:
- await WriteStreamLine(httpContext, _mockModifiedStreamLine).ConfigureAwait(false);
- break;
- case MockKubeServerFlags.BadJson:
- await WriteStreamLine(httpContext, MockBadStreamLine).ConfigureAwait(false);
- break;
- case MockKubeServerFlags.Throw500:
- return false;
- }
- }
-
- // keep server connection open
- await ServerShutdown.WaitAsync().ConfigureAwait(false);
- return false;
- }
-
- foreach (Enum flag in Enum.GetValues(_serverFlags.GetType()))
- {
- if (!_serverFlags.HasFlag(flag))
- {
- continue;
- }
-
- switch (flag)
- {
- case MockKubeServerFlags.ListPods:
- await WriteStreamLine(httpContext, MockPodResponse).ConfigureAwait(false);
- break;
- case MockKubeServerFlags.GetPod:
- var corev1PodList = KubernetesJson.Deserialize(MockPodResponse);
- await WriteStreamLine(httpContext, KubernetesJson.Serialize(corev1PodList.Items.First())).ConfigureAwait(false);
- break;
- case MockKubeServerFlags.Throw500:
- return false;
- }
- }
-
- return false;
- }
- }
-}
diff --git a/tests/KubernetesClient.Util.Tests/KubernetesClient.Util.Tests.csproj b/tests/KubernetesClient.Util.Tests/KubernetesClient.Util.Tests.csproj
deleted file mode 100644
index e54ad7af1..000000000
--- a/tests/KubernetesClient.Util.Tests/KubernetesClient.Util.Tests.csproj
+++ /dev/null
@@ -1,34 +0,0 @@
-
-
-
- net5.0
-
- false
-
-
-
-
-
-
-
-
-
- runtime; build; native; contentfiles; analyzers; buildtransitive
- all
-
-
- runtime; build; native; contentfiles; analyzers; buildtransitive
- all
-
-
-
-
-
-
-
-
-
-
-
-
-