Skip to content

Commit f32cf9e

Browse files
authored
fix warnings for net8 (#1481)
* fix ca2007 * xUnit1031 * fix ca2007 * fix ca2007 * remove deprecated ctor * fix xUnit1031 * fix missing doc * fix missing dispose * fix ex
1 parent f75c4aa commit f32cf9e

18 files changed

+180
-206
lines changed

src/KubernetesClient/Autorest/HttpOperationException.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4-
using System.Runtime.Serialization;
5-
64
namespace k8s.Autorest
75
{
86
/// <summary>
97
/// Exception thrown for an invalid response with custom error information.
108
/// </summary>
11-
[Serializable]
129
public class HttpOperationException : Exception
1310
{
1411
/// <summary>
@@ -51,15 +48,5 @@ public HttpOperationException(string message, Exception innerException)
5148
: base(message, innerException)
5249
{
5350
}
54-
55-
/// <summary>
56-
/// Initializes a new instance of the <see cref="HttpOperationException"/> class.
57-
/// </summary>
58-
/// <param name="info">Serialization info.</param>
59-
/// <param name="context">Streaming context.</param>
60-
protected HttpOperationException(SerializationInfo info, StreamingContext context)
61-
: base(info, context)
62-
{
63-
}
6451
}
6552
}

src/KubernetesClient/KubernetesException.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using System.Runtime.Serialization;
2-
31
namespace k8s
42
{
53
/// <summary>
@@ -72,22 +70,6 @@ public KubernetesException(string message, Exception innerException)
7270
{
7371
}
7472

75-
/// <summary>
76-
/// Initializes a new instance of the <see cref="KubernetesException"/> class with serialized data.
77-
/// </summary>
78-
/// <param name="info">
79-
/// The <see cref="SerializationInfo"/> that holds the serialized
80-
/// object data about the exception being thrown.
81-
/// </param>
82-
/// <param name="context">
83-
/// The <see cref="StreamingContext"/> that contains contextual information
84-
/// about the source or destination.
85-
/// </param>
86-
protected KubernetesException(SerializationInfo info, StreamingContext context)
87-
: base(info, context)
88-
{
89-
}
90-
9173
/// <summary>
9274
/// Gets, when this exception was raised because of a Kubernetes status message, the underlying
9375
/// Kubernetes status message.

src/KubernetesClient/LeaderElection/LeaderElector.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public string GetLeader()
5454
/// Will complete the returned Task and not retry to acquire leadership again after leadership is lost once.
5555
/// </summary>
5656
/// <param name="cancellationToken">A token to cancel the operation.</param>
57+
/// <returns>A Task representing the asynchronous operation.</returns>
5758
public async Task RunUntilLeadershipLostAsync(CancellationToken cancellationToken = default)
5859
{
5960
await AcquireAsync(cancellationToken).ConfigureAwait(false);
@@ -132,6 +133,7 @@ public async Task RunAndTryToHoldLeadershipForeverAsync(CancellationToken cancel
132133
/// </summary>
133134
/// <seealso cref="RunUntilLeadershipLostAsync"/>
134135
/// <param name="cancellationToken">A token to cancel the operation.</param>
136+
/// <returns>A Task representing the asynchronous operation.</returns>
135137
[Obsolete("Replaced by RunUntilLeadershipLostAsync to encode behavior in method name.")]
136138
public Task RunAsync(CancellationToken cancellationToken = default)
137139
{

tests/E2E.Tests/MinikubeTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ void DeleteEndpoints(string name)
303303
le.OnStartedLeading += () => leader1acq.Set();
304304
le.OnStoppedLeading += () => leader1lose.Set();
305305

306-
tasks.Add(le.RunAsync(cts.Token));
306+
tasks.Add(le.RunUntilLeadershipLostAsync(cts.Token));
307307
}
308308

309309
// wait 1 become leader
@@ -325,7 +325,7 @@ void DeleteEndpoints(string name)
325325
leader2init.Set();
326326
};
327327

328-
tasks.Add(le.RunAsync());
328+
tasks.Add(le.RunUntilLeadershipLostAsync());
329329
Assert.True(leader2init.WaitOne(TimeSpan.FromSeconds(30)));
330330

331331
Assert.Equal("leader1", le.GetLeader());

tests/KubernetesClient.Classic.Tests/SimpleTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public void Dispose()
5252
{
5353
running = false;
5454
server.Stop();
55+
#if NET8_0_OR_GREATER
56+
server.Dispose();
57+
#endif
5558
loop.Wait();
5659
loop.Dispose();
5760
}
@@ -74,7 +77,7 @@ public async Task QueryPods()
7477
});
7578
var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Addr });
7679

77-
var pod = await client.CoreV1.ReadNamespacedPodAsync("pod", "default").ConfigureAwait(false);
80+
var pod = await client.CoreV1.ReadNamespacedPodAsync("pod", "default").ConfigureAwait(true);
7881

7982
Assert.Equal("pod0", pod.Metadata.Name);
8083
}

tests/KubernetesClient.Tests/AuthTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ private X509Certificate2 OpenCertificateStore(Stream stream)
541541
var store = new Pkcs12Store();
542542
store.Load(stream, new char[] { });
543543

544-
var keyAlias = store.Aliases.Cast<string>().SingleOrDefault(a => store.IsKeyEntry(a));
544+
var keyAlias = store.Aliases.Cast<string>().SingleOrDefault(store.IsKeyEntry);
545545

546546
var key = (RsaPrivateCrtKeyParameters)store.GetKey(keyAlias).Key;
547547
var bouncyCertificate = store.GetCertificate(keyAlias).Certificate;

tests/KubernetesClient.Tests/ByteBufferTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public async Task ReadBlocksUntilDataAvailableTest()
255255

256256
// Kick off a read operation
257257
var readTask = Task.Run(() => read = buffer.Read(readData, 0, readData.Length));
258-
await Task.Delay(250).ConfigureAwait(false);
258+
await Task.Delay(250).ConfigureAwait(true);
259259
Assert.False(readTask.IsCompleted, "Read task completed before data was available.");
260260

261261
// Write data to the buffer
@@ -264,7 +264,7 @@ public async Task ReadBlocksUntilDataAvailableTest()
264264
await TaskAssert.Completed(
265265
readTask,
266266
TimeSpan.FromMilliseconds(1000),
267-
"Timed out waiting for read task to complete.").ConfigureAwait(false);
267+
"Timed out waiting for read task to complete.").ConfigureAwait(true);
268268

269269
Assert.Equal(3, read);
270270
Assert.Equal(0xF0, readData[0]);
@@ -411,10 +411,10 @@ public async Task ReadFirstTest()
411411
var output = new byte[buffer.Size + 1];
412412

413413
var readTask = Task.Run(() => buffer.Read(output, 0, output.Length));
414-
await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false);
414+
await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(true);
415415

416416
buffer.Write(data, 0, data.Length);
417-
await readTask.ConfigureAwait(false);
417+
await readTask.ConfigureAwait(true);
418418
}
419419

420420
#if NETCOREAPP2_0

tests/KubernetesClient.Tests/KubernetesClientConfigurationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ public async Task ContextWithClusterExtensions()
437437
{
438438
var path = Path.GetFullPath("assets/kubeconfig.cluster-extensions.yml");
439439

440-
_ = await KubernetesClientConfiguration.BuildConfigFromConfigFileAsync(new FileInfo(path)).ConfigureAwait(false);
440+
_ = await KubernetesClientConfiguration.BuildConfigFromConfigFileAsync(new FileInfo(path)).ConfigureAwait(true);
441441
}
442442

443443
[Fact]

tests/KubernetesClient.Tests/KubernetesExecTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public async Task WebSocketNamespacedPodExecAsync()
5151
{
5252
{ "X-My-Header", new List<string>() { "myHeaderValue", "myHeaderValue2" } },
5353
},
54-
cancellationToken: CancellationToken.None).ConfigureAwait(false);
54+
cancellationToken: CancellationToken.None).ConfigureAwait(true);
5555

5656
var expectedHeaders = new Dictionary<string, string>()
5757
{
@@ -91,7 +91,7 @@ public async Task WebSocketNamespacedPodPortForwardAsync()
9191
{
9292
{ "X-My-Header", new List<string>() { "myHeaderValue", "myHeaderValue2" } },
9393
},
94-
cancellationToken: CancellationToken.None).ConfigureAwait(false);
94+
cancellationToken: CancellationToken.None).ConfigureAwait(true);
9595

9696
var expectedHeaders = new Dictionary<string, string>()
9797
{
@@ -137,7 +137,7 @@ public async Task WebSocketNamespacedPodAttachAsync()
137137
{
138138
{ "X-My-Header", new List<string>() { "myHeaderValue", "myHeaderValue2" } },
139139
},
140-
cancellationToken: CancellationToken.None).ConfigureAwait(false);
140+
cancellationToken: CancellationToken.None).ConfigureAwait(true);
141141

142142
var expectedHeaders = new Dictionary<string, string>()
143143
{

tests/KubernetesClient.Tests/KubernetesMetricsTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public async Task NodesMetrics()
3535
{
3636
var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() });
3737

38-
var nodesMetricsList = await client.GetKubernetesNodesMetricsAsync().ConfigureAwait(false);
38+
var nodesMetricsList = await client.GetKubernetesNodesMetricsAsync().ConfigureAwait(true);
3939

4040
Assert.Single(nodesMetricsList.Items);
4141

@@ -56,7 +56,7 @@ public async Task NodesMetricsOptionalProperty()
5656
var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() });
5757

5858
// Should not throw with timespan optional property
59-
var exception = await Record.ExceptionAsync(async () => await client.GetKubernetesNodesMetricsAsync().ConfigureAwait(false)).ConfigureAwait(false);
59+
var exception = await Record.ExceptionAsync(client.GetKubernetesNodesMetricsAsync).ConfigureAwait(true);
6060

6161
Assert.Null(exception);
6262
}
@@ -69,7 +69,7 @@ public async Task PodsMetrics()
6969
{
7070
var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() });
7171

72-
var podsMetricsList = await client.GetKubernetesPodsMetricsAsync().ConfigureAwait(false);
72+
var podsMetricsList = await client.GetKubernetesPodsMetricsAsync().ConfigureAwait(true);
7373

7474
Assert.Single(podsMetricsList.Items);
7575

@@ -94,7 +94,7 @@ public async Task PodsMetricsOptionalProperty()
9494
var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() });
9595

9696
// Should not throw with timespan optional property
97-
var exception = await Record.ExceptionAsync(async () => await client.GetKubernetesPodsMetricsAsync().ConfigureAwait(false)).ConfigureAwait(false);
97+
var exception = await Record.ExceptionAsync(client.GetKubernetesPodsMetricsAsync).ConfigureAwait(true);
9898

9999
Assert.Null(exception);
100100
}
@@ -107,7 +107,7 @@ public async Task PodsMetricsEmptyResponse()
107107
{
108108
var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() });
109109

110-
var podsMetricsList = await client.GetKubernetesPodsMetricsByNamespaceAsync("empty").ConfigureAwait(false);
110+
var podsMetricsList = await client.GetKubernetesPodsMetricsByNamespaceAsync("empty").ConfigureAwait(true);
111111

112112
Assert.Empty(podsMetricsList.Items);
113113
}
@@ -122,7 +122,7 @@ public async Task PodsMetricsByNamespace()
122122
{
123123
var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() });
124124

125-
var podsMetricsList = await client.GetKubernetesPodsMetricsByNamespaceAsync(namespaceName).ConfigureAwait(false);
125+
var podsMetricsList = await client.GetKubernetesPodsMetricsByNamespaceAsync(namespaceName).ConfigureAwait(true);
126126

127127
Assert.Single(podsMetricsList.Items);
128128

@@ -147,7 +147,7 @@ public async Task PodsMetricsNonExistingNamespaceResponse()
147147
{
148148
var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() });
149149

150-
var podsMetricsList = await client.GetKubernetesPodsMetricsByNamespaceAsync("nonexisting").ConfigureAwait(false);
150+
var podsMetricsList = await client.GetKubernetesPodsMetricsByNamespaceAsync("nonexisting").ConfigureAwait(true);
151151

152152
Assert.Empty(podsMetricsList.Items);
153153
}

0 commit comments

Comments
 (0)