Skip to content

Commit f615b5b

Browse files
authored
Fix some compilation warnings (#1010)
* Fixe some summary warning * Fixed more warning * Uniformed example projects code * Uniformed test projects code * Fix OperatingSystems enum and GenericType summaries
1 parent fd3931c commit f615b5b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+210
-154
lines changed

examples/attach/Attach.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using System;
2-
using System.Threading.Tasks;
31
using k8s;
42
using k8s.Models;
3+
using System;
4+
using System.Threading.Tasks;
55

66
namespace attach
77
{
@@ -18,7 +18,7 @@ private static async Task Main(string[] args)
1818
await AttachToPod(client, pod).ConfigureAwait(false);
1919
}
2020

21-
private async static Task AttachToPod(IKubernetes client, V1Pod pod)
21+
private static async Task AttachToPod(IKubernetes client, V1Pod pod)
2222
{
2323
var webSocket =
2424
await client.WebSocketNamespacedPodAttachAsync(pod.Metadata.Name, "default",

examples/cp/Cp.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
using System;
2-
using System.IO;
3-
using System.Threading.Tasks;
1+
using ICSharpCode.SharpZipLib.Tar;
42
using k8s;
5-
using ICSharpCode.SharpZipLib.Tar;
6-
using System.Threading;
3+
using System;
4+
using System.IO;
75
using System.Linq;
86
using System.Text;
7+
using System.Threading;
8+
using System.Threading.Tasks;
99

1010
namespace cp
1111
{
@@ -57,7 +57,7 @@ private static void ValidatePathParameters(string sourcePath, string destination
5757
using (var memoryStream = new MemoryStream())
5858
{
5959
using (var inputFileStream = File.OpenRead(sourceFilePath))
60-
using (var tarOutputStream = new TarOutputStream(memoryStream, Encoding.Default))
60+
using (var tarOutputStream = new TarOutputStream(memoryStream, Encoding.Default))
6161
{
6262
tarOutputStream.IsStreamOwner = false;
6363

examples/csrApproval/Program.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
using System.Net;
1+
using Json.Patch;
2+
using k8s;
3+
using k8s.Models;
4+
using System.Net;
25
using System.Security.Cryptography;
36
using System.Security.Cryptography.X509Certificates;
47
using System.Text;
58
using System.Text.Json;
6-
using Json.Patch;
7-
using k8s;
8-
using k8s.Models;
99

1010
string GenerateCertificate(string name)
1111
{
@@ -18,10 +18,10 @@ string GenerateCertificate(string name)
1818
var distinguishedName = new X500DistinguishedName(name);
1919

2020
using var rsa = RSA.Create(4096);
21-
var request = new CertificateRequest(distinguishedName, rsa, HashAlgorithmName.SHA256,RSASignaturePadding.Pkcs1);
21+
var request = new CertificateRequest(distinguishedName, rsa, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
2222

23-
request.CertificateExtensions.Add(new X509KeyUsageExtension(X509KeyUsageFlags.DataEncipherment | X509KeyUsageFlags.KeyEncipherment | X509KeyUsageFlags.DigitalSignature , false));
24-
request.CertificateExtensions.Add(new X509EnhancedKeyUsageExtension(new OidCollection { new ("1.3.6.1.5.5.7.3.1") }, false));
23+
request.CertificateExtensions.Add(new X509KeyUsageExtension(X509KeyUsageFlags.DataEncipherment | X509KeyUsageFlags.KeyEncipherment | X509KeyUsageFlags.DigitalSignature, false));
24+
request.CertificateExtensions.Add(new X509EnhancedKeyUsageExtension(new OidCollection { new("1.3.6.1.5.5.7.3.1") }, false));
2525
request.CertificateExtensions.Add(sanBuilder.Build());
2626
var csr = request.CreateSigningRequest();
2727
var pemKey = "-----BEGIN CERTIFICATE REQUEST-----\r\n" +
@@ -36,7 +36,7 @@ string GenerateCertificate(string name)
3636
Console.WriteLine("Starting Request!");
3737
var name = "demo";
3838
var x509 = GenerateCertificate(name);
39-
var encodedCsr= Encoding.UTF8.GetBytes(x509);
39+
var encodedCsr = Encoding.UTF8.GetBytes(x509);
4040

4141
var request = new V1CertificateSigningRequest
4242
{

examples/exec/Exec.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using System;
2-
using System.Threading.Tasks;
31
using k8s;
42
using k8s.Models;
3+
using System;
4+
using System.Threading.Tasks;
55

66
namespace exec
77
{
@@ -18,7 +18,7 @@ private static async Task Main(string[] args)
1818
await ExecInPod(client, pod).ConfigureAwait(false);
1919
}
2020

21-
private async static Task ExecInPod(IKubernetes client, V1Pod pod)
21+
private static async Task ExecInPod(IKubernetes client, V1Pod pod)
2222
{
2323
var webSocket =
2424
await client.WebSocketNamespacedPodExecAsync(pod.Metadata.Name, "default", "ls",

examples/generic/Generic.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using System;
2-
using System.Threading.Tasks;
31
using k8s;
42
using k8s.Models;
3+
using System;
4+
using System.Threading.Tasks;
55

66
namespace exec
77
{

examples/labels/PodList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
using k8s;
12
using System;
23
using System.Collections.Generic;
3-
using k8s;
44

55
namespace simple
66
{

examples/logs/Logs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
using k8s;
12
using System;
23
using System.Threading.Tasks;
3-
using k8s;
44

55
namespace logs
66
{

examples/namespace/NamespaceExample.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
using k8s;
2+
using k8s.Models;
13
using System;
24
using System.Net;
35
using System.Threading.Tasks;
4-
using k8s;
5-
using k8s.Models;
66

77
namespace @namespace
88
{

examples/patch/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using System;
2-
using System.Linq;
31
using k8s;
42
using k8s.Models;
3+
using System;
4+
using System.Linq;
55

66
namespace patch
77
{

examples/portforward/PortForward.cs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
using k8s;
2+
using k8s.Models;
13
using System;
24
using System.Net;
35
using System.Net.Sockets;
46
using System.Text;
57
using System.Threading.Tasks;
6-
using k8s;
7-
using k8s.Models;
88

99
namespace portforward
1010
{
@@ -21,48 +21,56 @@ private static async Task Main(string[] args)
2121
await Forward(client, pod);
2222
}
2323

24-
private async static Task Forward(IKubernetes client, V1Pod pod) {
24+
private static async Task Forward(IKubernetes client, V1Pod pod)
25+
{
2526
// Note this is single-threaded, it won't handle concurrent requests well...
26-
var webSocket = await client.WebSocketNamespacedPodPortForwardAsync(pod.Metadata.Name, "default", new int[] {80}, "v4.channel.k8s.io");
27+
var webSocket = await client.WebSocketNamespacedPodPortForwardAsync(pod.Metadata.Name, "default", new int[] { 80 }, "v4.channel.k8s.io");
2728
var demux = new StreamDemuxer(webSocket, StreamType.PortForward);
2829
demux.Start();
2930

3031
var stream = demux.GetStream((byte?)0, (byte?)0);
3132

3233
IPAddress ipAddress = IPAddress.Loopback;
33-
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 8080);
34-
Socket listener = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
35-
listener.Bind(localEndPoint);
34+
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 8080);
35+
Socket listener = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
36+
listener.Bind(localEndPoint);
3637
listener.Listen(100);
3738

3839
Socket handler = null;
3940

4041
// Note this will only accept a single connection
41-
var accept = Task.Run(() => {
42-
while (true) {
42+
var accept = Task.Run(() =>
43+
{
44+
while (true)
45+
{
4346
handler = listener.Accept();
4447
var bytes = new byte[4096];
45-
while (true) {
48+
while (true)
49+
{
4650
int bytesRec = handler.Receive(bytes);
4751
stream.Write(bytes, 0, bytesRec);
48-
if (bytesRec == 0 || Encoding.ASCII.GetString(bytes,0,bytesRec).IndexOf("<EOF>") > -1) {
49-
break;
52+
if (bytesRec == 0 || Encoding.ASCII.GetString(bytes, 0, bytesRec).IndexOf("<EOF>") > -1)
53+
{
54+
break;
5055
}
5156
}
5257
}
5358
});
5459

55-
var copy = Task.Run(() => {
60+
var copy = Task.Run(() =>
61+
{
5662
var buff = new byte[4096];
57-
while (true) {
63+
while (true)
64+
{
5865
var read = stream.Read(buff, 0, 4096);
5966
handler.Send(buff, read, 0);
6067
}
6168
});
6269

6370
await accept;
6471
await copy;
65-
if (handler != null) {
72+
if (handler != null)
73+
{
6674
handler.Close();
6775
}
6876
listener.Close();

examples/prometheus/Prometheus.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using System;
2-
using System.Net.Http;
3-
using System.Threading;
41
using k8s;
52
using k8s.Monitoring;
63
using Prometheus;
4+
using System;
5+
using System.Net.Http;
6+
using System.Threading;
77

88
namespace prom
99
{

examples/restart/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using System.Text.Json;
2-
using Json.Patch;
1+
using Json.Patch;
32
using k8s;
43
using k8s.Models;
4+
using System.Text.Json;
55

66
async Task RestartDaemonSetAsync(string name, string @namespace, IKubernetes client)
77
{

examples/simple/PodList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using System;
21
using k8s;
2+
using System;
33

44
namespace simple
55
{

examples/watch/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
using k8s;
2+
using k8s.Models;
13
using System;
24
using System.Threading;
35
using System.Threading.Tasks;
4-
using k8s;
5-
using k8s.Models;
66

77
namespace watch
88
{
99
internal class Program
1010
{
11-
private async static Task Main(string[] args)
11+
private static async Task Main(string[] args)
1212
{
1313
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
1414

examples/yaml/Program.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
using k8s;
2+
using k8s.Models;
13
using System;
24
using System.Collections.Generic;
35
using System.Threading.Tasks;
4-
using k8s;
5-
using k8s.Models;
66

77
namespace yaml
88
{
99
internal class Program
1010
{
11-
private async static Task Main(string[] args)
11+
private static async Task Main(string[] args)
1212
{
1313
var typeMap = new Dictionary<String, Type>();
1414
typeMap.Add("v1/Pod", typeof(V1Pod));
@@ -17,7 +17,8 @@ private async static Task Main(string[] args)
1717

1818
var objects = await KubernetesYaml.LoadAllFromFileAsync(args[0], typeMap);
1919

20-
foreach (var obj in objects) {
20+
foreach (var obj in objects)
21+
{
2122
Console.WriteLine(obj);
2223
}
2324
}

src/KubernetesClient/KubernetesMetricsExtensions.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ public static class KubernetesMetricsExtensions
1515
/// <returns>the metrics <see cref="PodMetricsList"/></returns>
1616
public static async Task<NodeMetricsList> GetKubernetesNodesMetricsAsync(this IKubernetes kubernetes)
1717
{
18+
if (kubernetes is null)
19+
{
20+
throw new ArgumentNullException(nameof(kubernetes));
21+
}
22+
1823
var customObject = (JsonElement)await kubernetes.CustomObjects.GetClusterCustomObjectAsync("metrics.k8s.io", "v1beta1", "nodes", string.Empty).ConfigureAwait(false);
1924
return customObject.Deserialize<NodeMetricsList>();
2025
}
@@ -26,6 +31,11 @@ public static async Task<NodeMetricsList> GetKubernetesNodesMetricsAsync(this IK
2631
/// <returns>the metrics <see cref="PodMetricsList"/></returns>
2732
public static async Task<PodMetricsList> GetKubernetesPodsMetricsAsync(this IKubernetes kubernetes)
2833
{
34+
if (kubernetes is null)
35+
{
36+
throw new ArgumentNullException(nameof(kubernetes));
37+
}
38+
2939
var customObject = (JsonElement)await kubernetes.CustomObjects.GetClusterCustomObjectAsync("metrics.k8s.io", "v1beta1", "pods", string.Empty).ConfigureAwait(false);
3040
return customObject.Deserialize<PodMetricsList>();
3141
}
@@ -38,6 +48,11 @@ public static async Task<PodMetricsList> GetKubernetesPodsMetricsAsync(this IKub
3848
/// <returns>the metrics <see cref="PodMetricsList"/></returns>
3949
public static async Task<PodMetricsList> GetKubernetesPodsMetricsByNamespaceAsync(this IKubernetes kubernetes, string namespaceParameter)
4050
{
51+
if (kubernetes is null)
52+
{
53+
throw new ArgumentNullException(nameof(kubernetes));
54+
}
55+
4156
var customObject = (JsonElement)await kubernetes.CustomObjects.GetNamespacedCustomObjectAsync("metrics.k8s.io", "v1beta1", namespaceParameter, "pods", string.Empty).ConfigureAwait(false);
4257
return customObject.Deserialize<PodMetricsList>();
4358
}

src/KubernetesClient/LeaderElection/ResourceLock/ConfigMapLock.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
using k8s.Models;
12
using System.Threading;
23
using System.Threading.Tasks;
3-
using k8s.Models;
44

55
namespace k8s.LeaderElection.ResourceLock
66
{
@@ -15,22 +15,36 @@ protected override Task<V1ConfigMap> ReadMetaObjectAsync(IKubernetes client, str
1515
string namespaceParameter,
1616
CancellationToken cancellationToken)
1717
{
18+
if (client is null)
19+
{
20+
throw new ArgumentNullException(nameof(client));
21+
}
22+
1823
return client.CoreV1.ReadNamespacedConfigMapAsync(name, namespaceParameter, cancellationToken: cancellationToken);
1924
}
2025

2126
protected override Task<V1ConfigMap> CreateMetaObjectAsync(IKubernetes client, V1ConfigMap obj,
2227
string namespaceParameter,
2328
CancellationToken cancellationToken)
2429
{
30+
if (client is null)
31+
{
32+
throw new ArgumentNullException(nameof(client));
33+
}
34+
2535
return client.CoreV1.CreateNamespacedConfigMapAsync(obj, namespaceParameter, cancellationToken: cancellationToken);
2636
}
2737

2838
protected override Task<V1ConfigMap> ReplaceMetaObjectAsync(IKubernetes client, V1ConfigMap obj, string name,
2939
string namespaceParameter,
3040
CancellationToken cancellationToken)
3141
{
32-
return client.CoreV1.ReplaceNamespacedConfigMapAsync(obj, name, namespaceParameter,
33-
cancellationToken: cancellationToken);
42+
if (client is null)
43+
{
44+
throw new ArgumentNullException(nameof(client));
45+
}
46+
47+
return client.CoreV1.ReplaceNamespacedConfigMapAsync(obj, name, namespaceParameter, cancellationToken: cancellationToken);
3448
}
3549
}
3650
}

0 commit comments

Comments
 (0)