Skip to content

Commit 3686641

Browse files
committed
move class to single files
1 parent 0015631 commit 3686641

File tree

5 files changed

+81
-73
lines changed

5 files changed

+81
-73
lines changed

src/KubernetesClient/ModelExtensions.cs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using System.Net;
54

65
namespace k8s.Models
76
{
@@ -487,20 +486,4 @@ public static bool Matches(this V1OwnerReference owner, IKubernetesObject<V1Obje
487486
return owner.ApiVersion == obj.ApiVersion && owner.Kind == obj.Kind && owner.Name == obj.Name() && owner.Uid == obj.Uid();
488487
}
489488
}
490-
491-
public partial class V1Status
492-
{
493-
/// <summary>Converts a <see cref="V1Status"/> object into a short description of the status.</summary>
494-
public override string ToString()
495-
{
496-
string reason = Reason;
497-
if (string.IsNullOrEmpty(reason) && Code.GetValueOrDefault() != 0)
498-
{
499-
reason = ((HttpStatusCode)Code.Value).ToString();
500-
}
501-
502-
return string.IsNullOrEmpty(Message) ? string.IsNullOrEmpty(reason) ? Status : reason :
503-
string.IsNullOrEmpty(reason) ? Message : $"{reason} - {Message}";
504-
}
505-
}
506489
}

src/KubernetesClient/V1Status.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Net;
2+
3+
namespace k8s.Models
4+
{
5+
public partial class V1Status
6+
{
7+
/// <summary>Converts a <see cref="V1Status"/> object into a short description of the status.</summary>
8+
public override string ToString()
9+
{
10+
string reason = Reason;
11+
if (string.IsNullOrEmpty(reason) && Code.GetValueOrDefault() != 0)
12+
{
13+
reason = ((HttpStatusCode)Code.Value).ToString();
14+
}
15+
16+
return string.IsNullOrEmpty(Message) ? string.IsNullOrEmpty(reason) ? Status : reason :
17+
string.IsNullOrEmpty(reason) ? Message : $"{reason} - {Message}";
18+
}
19+
}
20+
}

src/KubernetesClient/Watcher.cs

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
using System.Runtime.Serialization;
44
using System.Threading;
55
using System.Threading.Tasks;
6-
using k8s.Exceptions;
76
using k8s.Models;
8-
using Microsoft.Rest;
97
using Microsoft.Rest.Serialization;
108

119
namespace k8s
@@ -177,57 +175,4 @@ private async Task WatcherLoop(CancellationToken cancellationToken)
177175
}
178176
}
179177
}
180-
181-
public static class WatcherExt
182-
{
183-
/// <summary>
184-
/// create a watch object from a call to api server with watch=true
185-
/// </summary>
186-
/// <typeparam name="T">type of the event object</typeparam>
187-
/// <typeparam name="L">type of the HttpOperationResponse object</typeparam>
188-
/// <param name="response">the api response</param>
189-
/// <param name="onEvent">a callback when any event raised from api server</param>
190-
/// <param name="onError">a callbak when any exception was caught during watching</param>
191-
/// <param name="onClosed">
192-
/// The action to invoke when the server closes the connection.
193-
/// </param>
194-
/// <returns>a watch object</returns>
195-
public static Watcher<T> Watch<T, L>(this Task<HttpOperationResponse<L>> responseTask,
196-
Action<WatchEventType, T> onEvent,
197-
Action<Exception> onError = null,
198-
Action onClosed = null)
199-
{
200-
return new Watcher<T>(async () =>
201-
{
202-
var response = await responseTask.ConfigureAwait(false);
203-
204-
if (!(response.Response.Content is WatcherDelegatingHandler.LineSeparatedHttpContent content))
205-
{
206-
throw new KubernetesClientException("not a watchable request or failed response");
207-
}
208-
209-
return content.StreamReader;
210-
}, onEvent, onError, onClosed);
211-
}
212-
213-
/// <summary>
214-
/// create a watch object from a call to api server with watch=true
215-
/// </summary>
216-
/// <typeparam name="T">type of the event object</typeparam>
217-
/// <typeparam name="L">type of the HttpOperationResponse object</typeparam>
218-
/// <param name="response">the api response</param>
219-
/// <param name="onEvent">a callback when any event raised from api server</param>
220-
/// <param name="onError">a callbak when any exception was caught during watching</param>
221-
/// <param name="onClosed">
222-
/// The action to invoke when the server closes the connection.
223-
/// </param>
224-
/// <returns>a watch object</returns>
225-
public static Watcher<T> Watch<T, L>(this HttpOperationResponse<L> response,
226-
Action<WatchEventType, T> onEvent,
227-
Action<Exception> onError = null,
228-
Action onClosed = null)
229-
{
230-
return Watch(Task.FromResult(response), onEvent, onError, onClosed);
231-
}
232-
}
233178
}

src/KubernetesClient/WatcherExt.cs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using k8s.Exceptions;
4+
using Microsoft.Rest;
5+
6+
namespace k8s
7+
{
8+
public static class WatcherExt
9+
{
10+
/// <summary>
11+
/// create a watch object from a call to api server with watch=true
12+
/// </summary>
13+
/// <typeparam name="T">type of the event object</typeparam>
14+
/// <typeparam name="L">type of the HttpOperationResponse object</typeparam>
15+
/// <param name="response">the api response</param>
16+
/// <param name="onEvent">a callback when any event raised from api server</param>
17+
/// <param name="onError">a callbak when any exception was caught during watching</param>
18+
/// <param name="onClosed">
19+
/// The action to invoke when the server closes the connection.
20+
/// </param>
21+
/// <returns>a watch object</returns>
22+
public static Watcher<T> Watch<T, L>(this Task<HttpOperationResponse<L>> responseTask,
23+
Action<WatchEventType, T> onEvent,
24+
Action<Exception> onError = null,
25+
Action onClosed = null)
26+
{
27+
return new Watcher<T>(async () =>
28+
{
29+
var response = await responseTask.ConfigureAwait(false);
30+
31+
if (!(response.Response.Content is WatcherDelegatingHandler.LineSeparatedHttpContent content))
32+
{
33+
throw new KubernetesClientException("not a watchable request or failed response");
34+
}
35+
36+
return content.StreamReader;
37+
}, onEvent, onError, onClosed);
38+
}
39+
40+
/// <summary>
41+
/// create a watch object from a call to api server with watch=true
42+
/// </summary>
43+
/// <typeparam name="T">type of the event object</typeparam>
44+
/// <typeparam name="L">type of the HttpOperationResponse object</typeparam>
45+
/// <param name="response">the api response</param>
46+
/// <param name="onEvent">a callback when any event raised from api server</param>
47+
/// <param name="onError">a callbak when any exception was caught during watching</param>
48+
/// <param name="onClosed">
49+
/// The action to invoke when the server closes the connection.
50+
/// </param>
51+
/// <returns>a watch object</returns>
52+
public static Watcher<T> Watch<T, L>(this HttpOperationResponse<L> response,
53+
Action<WatchEventType, T> onEvent,
54+
Action<Exception> onError = null,
55+
Action onClosed = null)
56+
{
57+
return Watch(Task.FromResult(response), onEvent, onError, onClosed);
58+
}
59+
}
60+
}

tests/KubernetesClient.Tests/KubernetesClientConfigurationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ public void LoadKubeConfigFromEnvironmentVariable()
434434
}
435435

436436
[Fact]
437-
public void LoadKubeConfigFromEnvironmentVariable_MultipleConfigs()
437+
public void LoadKubeConfigFromEnvironmentVariableMultipleConfigs()
438438
{
439439
// This test makes sure that a list of environment variables works (no exceptions),
440440
// doesn't check validity of configuration, which is done in other tests.

0 commit comments

Comments
 (0)