Skip to content

Commit c1de779

Browse files
Add in formatting pre-check. (#431)
1 parent 56b7f76 commit c1de779

32 files changed

+125
-81
lines changed

.github/workflows/dotnet.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ jobs:
3434
if: matrix.os != 'windows-latest'
3535
run: |
3636
rsync --archive --ignore-existing ${DOTNET_ROOT/3.1.201/2.1.805}/ ${DOTNET_ROOT/3.1.201/2.1.202}/ $DOTNET_ROOT
37+
- name: Setup Format
38+
run: dotnet tool install -g dotnet-format
39+
- name: Check Format
40+
# don't check formatting on Windows b/c of CRLF issues.
41+
if: matrix.os != 'windows-latest'
42+
run: dotnet format --check --dry-run --exclude ./src/KubernetesClient/generated/
3743
- name: Build
3844
run: dotnet build --configuration Release
3945
- name: Test

examples/attach/Attach.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ private static async Task Main(string[] args)
2121
await AttachToPod(client, pod);
2222
}
2323

24-
private async static Task AttachToPod(IKubernetes client, V1Pod pod) {
24+
private async static Task AttachToPod(IKubernetes client, V1Pod pod)
25+
{
2526
var webSocket = await client.WebSocketNamespacedPodAttachAsync(pod.Metadata.Name, "default", pod.Spec.Containers[0].Name);
2627

2728
var demux = new StreamDemuxer(webSocket);

examples/exec/Exec.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ private static async Task Main(string[] args)
1818
await ExecInPod(client, pod);
1919
}
2020

21-
private async static Task ExecInPod(IKubernetes client, V1Pod pod) {
21+
private async static Task ExecInPod(IKubernetes client, V1Pod pod)
22+
{
2223
var webSocket = await client.WebSocketNamespacedPodExecAsync(pod.Metadata.Name, "default", "ls", pod.Spec.Containers[0].Name);
2324

2425
var demux = new StreamDemuxer(webSocket);

examples/logs/Logs.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ private static async Task Main(string[] args)
1414
Console.WriteLine("Starting Request!");
1515

1616
var list = client.ListNamespacedPod("default");
17-
if (list.Items.Count == 0) {
17+
if (list.Items.Count == 0)
18+
{
1819
Console.WriteLine("No pods!");
1920
return;
2021
}

examples/namespace/Namespace.cs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,56 @@ namespace @namespace
88
{
99
class NamespaceExample
1010
{
11-
static void ListNamespaces(IKubernetes client) {
11+
static void ListNamespaces(IKubernetes client)
12+
{
1213
var list = client.ListNamespace();
13-
foreach (var item in list.Items) {
14+
foreach (var item in list.Items)
15+
{
1416
Console.WriteLine(item.Metadata.Name);
1517
}
16-
if (list.Items.Count == 0) {
18+
if (list.Items.Count == 0)
19+
{
1720
Console.WriteLine("Empty!");
1821
}
1922
}
2023

21-
static async Task DeleteAsync(IKubernetes client, string name, int delayMillis) {
22-
while (true) {
24+
static async Task DeleteAsync(IKubernetes client, string name, int delayMillis)
25+
{
26+
while (true)
27+
{
2328
await Task.Delay(delayMillis);
2429
try
2530
{
2631
await client.ReadNamespaceAsync(name);
27-
} catch (AggregateException ex) {
28-
foreach (var innerEx in ex.InnerExceptions) {
29-
if (innerEx is Microsoft.Rest.HttpOperationException) {
32+
}
33+
catch (AggregateException ex)
34+
{
35+
foreach (var innerEx in ex.InnerExceptions)
36+
{
37+
if (innerEx is Microsoft.Rest.HttpOperationException)
38+
{
3039
var code = ((Microsoft.Rest.HttpOperationException)innerEx).Response.StatusCode;
31-
if (code == HttpStatusCode.NotFound) {
40+
if (code == HttpStatusCode.NotFound)
41+
{
3242
return;
3343
}
3444
throw ex;
3545
}
3646
}
37-
} catch (Microsoft.Rest.HttpOperationException ex) {
38-
if (ex.Response.StatusCode == HttpStatusCode.NotFound) {
47+
}
48+
catch (Microsoft.Rest.HttpOperationException ex)
49+
{
50+
if (ex.Response.StatusCode == HttpStatusCode.NotFound)
51+
{
3952
return;
4053
}
4154
throw ex;
4255
}
4356
}
4457
}
4558

46-
static void Delete(IKubernetes client, string name, int delayMillis) {
59+
static void Delete(IKubernetes client, string name, int delayMillis)
60+
{
4761
DeleteAsync(client, name, delayMillis).Wait();
4862
}
4963

gen/KubernetesWatchGenerator/Program.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,25 @@ static async Task Main(string[] args)
5151
_schemaDefinitionsInMultipleGroups = _schemaToNameMap.Values.Select(x =>
5252
{
5353
var parts = x.Split(".");
54-
return new {FullName = x, Name = parts[parts.Length - 1], Version = parts[parts.Length - 2], Group = parts[parts.Length - 3]};
54+
return new { FullName = x, Name = parts[parts.Length - 1], Version = parts[parts.Length - 2], Group = parts[parts.Length - 3] };
5555
})
56-
.GroupBy(x => new {x.Name, x.Version})
56+
.GroupBy(x => new { x.Name, x.Version })
5757
.Where(x => x.Count() > 1)
5858
.SelectMany(x => x)
5959
.Select(x => x.FullName)
6060
.ToHashSet();
6161

6262
_classNameToPluralMap = swagger.Operations
6363
.Where(x => x.Operation.OperationId.StartsWith("list"))
64-
.Select(x => { return new {PluralName = x.Path.Split("/").Last(), ClassName = GetClassNameForSchemaDefinition(x.Operation.Responses["200"].ActualResponseSchema)}; })
64+
.Select(x => { return new { PluralName = x.Path.Split("/").Last(), ClassName = GetClassNameForSchemaDefinition(x.Operation.Responses["200"].ActualResponseSchema) }; })
6565
.Distinct()
6666
.ToDictionary(x => x.ClassName, x => x.PluralName);
6767

6868
// dictionary only contains "list" plural maps. assign the same plural names to entities those lists support
6969
_classNameToPluralMap = _classNameToPluralMap
7070
.Where(x => x.Key.EndsWith("List"))
7171
.Select(x =>
72-
new {ClassName = x.Key.Remove(x.Key.Length - 4), PluralName = x.Value})
72+
new { ClassName = x.Key.Remove(x.Key.Length - 4), PluralName = x.Value })
7373
.ToDictionary(x => x.ClassName, x => x.PluralName)
7474
.Union(_classNameToPluralMap)
7575
.ToDictionary(x => x.Key, x => x.Value);
@@ -119,7 +119,7 @@ static async Task Main(string[] args)
119119

120120
var modelsDir = Path.Combine(outputDirectory, "Models");
121121
_classesWithValidation = Directory.EnumerateFiles(modelsDir)
122-
.Select(x => new {Class = Path.GetFileNameWithoutExtension(x), Content = File.ReadAllText(x)})
122+
.Select(x => new { Class = Path.GetFileNameWithoutExtension(x), Content = File.ReadAllText(x) })
123123
.Where(x => x.Content.Contains("public virtual void Validate()"))
124124
.Select(x => x.Class)
125125
.ToHashSet();
@@ -244,7 +244,7 @@ static string GetInterfaceName(JsonSchema4 definition)
244244
interfaces.Add($"ISpec<{GetClassNameForSchemaDefinition(specProperty.Reference)}>");
245245
}
246246

247-
if(_classesWithValidation.Contains(className))
247+
if (_classesWithValidation.Contains(className))
248248
interfaces.Add("IValidate");
249249
var result = string.Join(", ", interfaces);
250250
return result;
@@ -272,7 +272,7 @@ static void GetPlural(RenderContext context, IList<object> arguments, IDictionar
272272
if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is JsonSchema4)
273273
{
274274
var plural = GetPlural(arguments[0] as JsonSchema4);
275-
if(plural != null)
275+
if (plural != null)
276276
context.Write($"\"{plural}\"");
277277
else
278278
context.Write("null");

src/KubernetesClient/CertUtils.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static class CertUtils
2121
/// <returns>List of x509 instances.</returns>
2222
public static X509Certificate2Collection LoadPemFileCert(string file)
2323
{
24-
var certs = new X509CertificateParser().ReadCertificates(File.OpenRead(file));
24+
var certs = new X509CertificateParser().ReadCertificates(File.OpenRead(file));
2525
var certCollection = new X509Certificate2Collection();
2626

2727
// Convert BouncyCastle X509Certificates to the .NET cryptography implementation and add
@@ -76,7 +76,8 @@ public static X509Certificate2 GeneratePfx(KubernetesClientConfiguration config)
7676
var cert = new X509CertificateParser().ReadCertificate(new MemoryStream(certData));
7777
// key usage is a bit string, zero-th bit is 'digitalSignature'
7878
// See https://www.alvestrand.no/objectid/2.5.29.15.html for more details.
79-
if (cert != null && cert.GetKeyUsage() != null && !cert.GetKeyUsage()[0]) {
79+
if (cert != null && cert.GetKeyUsage() != null && !cert.GetKeyUsage()[0])
80+
{
8081
throw new Exception(
8182
"Client certificates must be marked for digital signing. " +
8283
"See https://github.com/kubernetes-client/csharp/issues/319");
@@ -93,10 +94,10 @@ public static X509Certificate2 GeneratePfx(KubernetesClientConfiguration config)
9394
}
9495
}
9596

96-
var keyParams = (AsymmetricKeyParameter) obj;
97+
var keyParams = (AsymmetricKeyParameter)obj;
9798

9899
var store = new Pkcs12StoreBuilder().Build();
99-
store.SetKeyEntry("K8SKEY", new AsymmetricKeyEntry(keyParams), new[] {new X509CertificateEntry(cert)});
100+
store.SetKeyEntry("K8SKEY", new AsymmetricKeyEntry(keyParams), new[] { new X509CertificateEntry(cert) });
100101

101102
using (var pkcs = new MemoryStream())
102103
{

src/KubernetesClient/IItems.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ public interface IItems<T>
1414
/// </summary>
1515
IList<T> Items { get; set; }
1616
}
17-
}
17+
}

src/KubernetesClient/IMetadata.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ public interface IMetadata<T>
1515
/// </summary>
1616
T Metadata { get; set; }
1717
}
18-
}
18+
}

src/KubernetesClient/ISpec.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ public interface ISpec<T>
1414
/// </summary>
1515
T Spec { get; set; }
1616
}
17-
}
17+
}

0 commit comments

Comments
 (0)