Skip to content

Commit 3702fd6

Browse files
authored
Standardization of using order and object initialization (#1028)
* Code cleanup KubernetesClient * KubernetesClient.Basic code cleanup * KubernetesClient.Models cleanup * LibKubernetesGenerator code cleanup * Improved readability of object initialization * FIx namespace order * Fixed some compilation warning
1 parent bbd3b6c commit 3702fd6

Some content is hidden

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

47 files changed

+200
-164
lines changed

examples/namespace/NamespaceExample.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ private static async Task DeleteAsync(IKubernetes client, string name, int delay
3535
{
3636
foreach (var innerEx in ex.InnerExceptions)
3737
{
38-
if (innerEx is k8s.Autorest.HttpOperationException)
38+
if (innerEx is k8s.Autorest.HttpOperationException exception)
3939
{
40-
var code = ((k8s.Autorest.HttpOperationException)innerEx).Response.StatusCode;
40+
var code = exception.Response.StatusCode;
4141
if (code == HttpStatusCode.NotFound)
4242
{
4343
return;

examples/yaml/Program.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ internal class Program
1010
{
1111
private static async Task Main(string[] args)
1212
{
13-
var typeMap = new Dictionary<String, Type>();
14-
typeMap.Add("v1/Pod", typeof(V1Pod));
15-
typeMap.Add("v1/Service", typeof(V1Service));
16-
typeMap.Add("apps/v1/Deployment", typeof(V1Deployment));
13+
var typeMap = new Dictionary<String, Type>
14+
{
15+
{ "v1/Pod", typeof(V1Pod) },
16+
{ "v1/Service", typeof(V1Service) },
17+
{ "apps/v1/Deployment", typeof(V1Deployment) }
18+
};
1719

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

src/KubernetesClient.Basic/AbstractKubernetes.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ private static class HttpMethods
1919

2020
private sealed class QueryBuilder
2121
{
22-
private List<string> parameters = new List<string>();
22+
private readonly List<string> parameters = new List<string>();
2323

2424
public void Append(string key, params object[] values)
2525
{

src/KubernetesClient.Basic/Autorest/HttpRequestMessageWrapper.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,10 @@ public HttpRequestMessageWrapper(HttpRequestMessage httpRequest, string content)
3030
this.Content = content;
3131
this.Method = httpRequest.Method;
3232
this.RequestUri = httpRequest.RequestUri;
33-
#pragma warning disable CS0618 // Type or member is obsolete
3433
if (httpRequest.Properties != null)
3534
{
3635
Properties = new Dictionary<string, object>();
3736
foreach (KeyValuePair<string, object> pair in httpRequest.Properties)
38-
#pragma warning restore CS0618 // Type or member is obsolete
3937
{
4038
this.Properties[pair.Key] = pair.Value;
4139
}

src/KubernetesClient.Basic/Autorest/TokenCredentials.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public TokenCredentials(ITokenProvider tokenProvider, string tenantId, string ca
9898
/// <returns>
9999
/// Task that will complete when processing has completed.
100100
/// </returns>
101-
public async override Task ProcessHttpRequestAsync(
101+
public override async Task ProcessHttpRequestAsync(
102102
HttpRequestMessage request,
103103
CancellationToken cancellationToken)
104104
{

src/KubernetesClient.Basic/Global.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
global using System;
2-
global using System.Collections.Generic;
3-
global using System.Linq;
41
global using k8s.Autorest;
52
global using k8s.Models;
3+
global using System;
4+
global using System.Collections.Generic;
65
global using System.IO;
6+
global using System.Linq;
77
global using System.Threading;
88
global using System.Threading.Tasks;

src/KubernetesClient.Models/Extensions.cs

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

55
namespace k8s
66
{

src/KubernetesClient.Models/IItems.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ public static class ItemsExt
1717
{
1818
public static IEnumerator<T> GetEnumerator<T>(this IItems<T> items)
1919
{
20+
if (items is null)
21+
{
22+
throw new ArgumentNullException(nameof(items));
23+
}
24+
2025
return items.Items.GetEnumerator();
2126
}
2227
}

src/KubernetesClient.Models/KubeConfigModels/ExecCredentialResponse.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ public class ExecStatus
1313

1414
public bool IsValid()
1515
{
16-
return (!string.IsNullOrEmpty(Token) ||
17-
(!string.IsNullOrEmpty(ClientCertificateData) && !string.IsNullOrEmpty(ClientKeyData)));
16+
return !string.IsNullOrEmpty(Token) ||
17+
(!string.IsNullOrEmpty(ClientCertificateData) && !string.IsNullOrEmpty(ClientKeyData));
1818
}
1919
}
2020

src/KubernetesClient.Models/KubernetesYaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using k8s.Models;
12
using System.IO;
23
using System.Reflection;
34
using System.Text;
@@ -6,7 +7,6 @@
67
using YamlDotNet.Core.Events;
78
using YamlDotNet.Serialization;
89
using YamlDotNet.Serialization.NamingConventions;
9-
using k8s.Models;
1010

1111
namespace k8s
1212
{

0 commit comments

Comments
 (0)