Skip to content

Commit 3a24155

Browse files
committed
style: code style cleanup
1 parent 39f5a29 commit 3a24155

File tree

9 files changed

+554
-561
lines changed

9 files changed

+554
-561
lines changed

examples/ConversionWebhookOperator/Controller/V1TestEntityController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using KubeOps.Abstractions.Controller;
2-
using KubeOps.Abstractions.Rbac;
1+
using ConversionWebhookOperator.Entities;
32

4-
using ConversionWebhookOperator.Entities;
3+
using KubeOps.Abstractions.Controller;
4+
using KubeOps.Abstractions.Rbac;
55

66
namespace ConversionWebhookOperator.Controller;
77

examples/ConversionWebhookOperator/Webhooks/TestConversionWebhook.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using KubeOps.Operator.Web.Webhooks.Conversion;
2-
31
using ConversionWebhookOperator.Entities;
42

3+
using KubeOps.Operator.Web.Webhooks.Conversion;
4+
55
namespace ConversionWebhookOperator.Webhooks;
66

77
[ConversionWebhook(typeof(V3TestEntity))]

src/KubeOps.Cli/Generators/MutationWebhookGenerator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public void Generate(ResultOutput output)
4343
CaBundle = caBundle,
4444
Service = new Admissionregistrationv1ServiceReference
4545
{
46-
Name = "operator", Path = hook.WebhookPath,
46+
Name = "operator",
47+
Path = hook.WebhookPath,
4748
},
4849
},
4950
});

src/KubeOps.Cli/Generators/ValidationWebhookGenerator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public void Generate(ResultOutput output)
4343
CaBundle = caBundle,
4444
Service = new Admissionregistrationv1ServiceReference
4545
{
46-
Name = "operator", Path = hook.WebhookPath,
46+
Name = "operator",
47+
Path = hook.WebhookPath,
4748
},
4849
},
4950
});

src/KubeOps.KubernetesClient/IKubernetesClient.cs

Lines changed: 403 additions & 403 deletions
Large diffs are not rendered by default.

src/KubeOps.Transpiler/Crds.cs

Lines changed: 65 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Collections;
22
using System.Collections.ObjectModel;
3-
using System.Diagnostics.CodeAnalysis;
43
using System.Reflection;
54
using System.Text.Json.Serialization;
65

@@ -79,7 +78,7 @@ public static V1CustomResourceDefinition Transpile(this MetadataLoadContext cont
7978
type.GetCustomAttributeData<DescriptionAttribute>()?.GetCustomAttributeCtorArg<string>(context, 0),
8079
Properties = type.GetProperties()
8180
.Where(p => !IgnoredToplevelProperties.Contains(p.Name.ToLowerInvariant())
82-
&& p.GetCustomAttributeData<IgnoreAttribute>() == null)
81+
&& p.GetCustomAttributeData<IgnoreAttribute>() == null)
8382
.Select(p => (Name: p.GetPropertyName(context), Schema: context.Map(p)))
8483
.ToDictionary(t => t.Name, t => t.Schema),
8584
});
@@ -107,8 +106,8 @@ public static IEnumerable<V1CustomResourceDefinition> Transpile(
107106
=> types
108107
.Select(context.GetContextType)
109108
.Where(type => type.Assembly != context.GetContextType<KubernetesEntityAttribute>().Assembly
110-
&& type.GetCustomAttributesData<KubernetesEntityAttribute>().Any()
111-
&& !type.GetCustomAttributesData<IgnoreAttribute>().Any())
109+
&& type.GetCustomAttributesData<KubernetesEntityAttribute>().Any()
110+
&& !type.GetCustomAttributesData<IgnoreAttribute>().Any())
112111
.Select(type => (Props: context.Transpile(type),
113112
IsStorage: type.GetCustomAttributesData<StorageVersionAttribute>().Any()))
114113
.GroupBy(grp => grp.Props.Metadata.Name)
@@ -291,56 +290,50 @@ private static V1JSONSchemaProps Map(this MetadataLoadContext context, Type type
291290
return props;
292291
}
293292

294-
var interfaces = type.IsInterface
293+
var interfaces = (type.IsInterface
295294
? type.GetInterfaces().Append(type)
296-
: type.GetInterfaces();
295+
: type.GetInterfaces()).ToList();
297296

298297
var interfaceNames = interfaces.Select(i =>
299298
i.IsGenericType
300299
? i.GetGenericTypeDefinition().FullName
301-
: i.FullName);
300+
: i.FullName).ToList();
302301

303302
if (interfaceNames.Contains(typeof(IDictionary<,>).FullName))
304303
{
305304
var dictionaryImpl = interfaces
306305
.First(i => i.IsGenericType
307-
&& i.GetGenericTypeDefinition().FullName == typeof(IDictionary<,>).FullName);
306+
&& i.GetGenericTypeDefinition().FullName == typeof(IDictionary<,>).FullName);
308307

309-
var addlProps = context.Map(dictionaryImpl.GenericTypeArguments[1]);
308+
var additionalProperties = context.Map(dictionaryImpl.GenericTypeArguments[1]);
310309
return new V1JSONSchemaProps
311310
{
312311
Type = Object,
313-
AdditionalProperties = addlProps,
312+
AdditionalProperties = additionalProperties,
314313
Nullable = false,
315314
};
316315
}
317316

318317
if (interfaceNames.Contains(typeof(IDictionary).FullName))
319318
{
320-
return new V1JSONSchemaProps
321-
{
322-
Type = Object,
323-
XKubernetesPreserveUnknownFields = true,
324-
Nullable = false,
325-
};
319+
return new V1JSONSchemaProps { Type = Object, XKubernetesPreserveUnknownFields = true, Nullable = false, };
326320
}
327321

328322
if (interfaceNames.Contains(typeof(IEnumerable<>).FullName))
329323
{
330324
return context.MapEnumerationType(type, interfaces);
331325
}
332326

333-
switch (type.BaseType?.FullName)
327+
return type.BaseType?.FullName switch
334328
{
335-
case "System.Object":
336-
return context.MapObjectType(type);
337-
case "System.ValueType":
338-
return context.MapValueType(type);
339-
case "System.Enum":
340-
return new V1JSONSchemaProps { Type = String, EnumProperty = Enum.GetNames(type).Cast<object>().ToList() };
341-
default:
342-
throw InvalidType(type);
343-
}
329+
"System.Object" => context.MapObjectType(type),
330+
"System.ValueType" => context.MapValueType(type),
331+
"System.Enum" => new V1JSONSchemaProps
332+
{
333+
Type = String, EnumProperty = Enum.GetNames(type).Cast<object>().ToList(),
334+
},
335+
_ => throw InvalidType(type),
336+
};
344337
}
345338

346339
private static V1JSONSchemaProps MapObjectType(this MetadataLoadContext context, Type type)
@@ -367,34 +360,38 @@ private static V1JSONSchemaProps MapObjectType(this MetadataLoadContext context,
367360
}
368361

369362
return new V1JSONSchemaProps
370-
{
371-
Type = Object,
372-
Description =
373-
type.GetCustomAttributeData<DescriptionAttribute>()?.GetCustomAttributeCtorArg<string>(context, 0),
374-
Properties = type
375-
.GetProperties()
376-
.Where(p => p.GetCustomAttributeData<IgnoreAttribute>() == null)
377-
.Select(p => (Name: p.GetPropertyName(context), Schema: context.Map(p)))
378-
.ToDictionary(t => t.Name, t => t.Schema),
379-
Required = type.GetProperties()
380-
.Where(p => p.GetCustomAttributeData<RequiredAttribute>() != null
363+
{
364+
Type = Object,
365+
Description =
366+
type.GetCustomAttributeData<DescriptionAttribute>()
367+
?.GetCustomAttributeCtorArg<string>(context, 0),
368+
Properties = type
369+
.GetProperties()
370+
.Where(p => p.GetCustomAttributeData<IgnoreAttribute>() == null)
371+
.Select(p => (Name: p.GetPropertyName(context), Schema: context.Map(p)))
372+
.ToDictionary(t => t.Name, t => t.Schema),
373+
Required = type.GetProperties()
374+
.Where(p => p.GetCustomAttributeData<RequiredAttribute>() != null
381375
&& p.GetCustomAttributeData<IgnoreAttribute>() == null)
382-
.Select(p => p.GetPropertyName(context))
383-
.ToList() switch
384-
{
385-
{ Count: > 0 } p => p,
386-
_ => null,
387-
},
388-
};
376+
.Select(p => p.GetPropertyName(context))
377+
.ToList() switch
378+
{
379+
{ Count: > 0 } p => p,
380+
_ => null,
381+
},
382+
};
389383
}
390384
}
391385

392-
private static V1JSONSchemaProps MapEnumerationType(this MetadataLoadContext context, Type type, IEnumerable<Type> interfaces)
386+
private static V1JSONSchemaProps MapEnumerationType(
387+
this MetadataLoadContext context,
388+
Type type,
389+
IEnumerable<Type> interfaces)
393390
{
394391
Type? enumerableType = interfaces
395392
.FirstOrDefault(i => i.IsGenericType
396-
&& i.GetGenericTypeDefinition().FullName == typeof(IEnumerable<>).FullName
397-
&& i.GenericTypeArguments.Length == 1);
393+
&& i.GetGenericTypeDefinition().FullName == typeof(IEnumerable<>).FullName
394+
&& i.GenericTypeArguments.Length == 1);
398395

399396
if (enumerableType == null)
400397
{
@@ -404,40 +401,33 @@ private static V1JSONSchemaProps MapEnumerationType(this MetadataLoadContext con
404401
Type listType = enumerableType.GenericTypeArguments[0];
405402
if (listType.IsGenericType && listType.GetGenericTypeDefinition().FullName == typeof(KeyValuePair<,>).FullName)
406403
{
407-
var addlProps = context.Map(listType.GenericTypeArguments[1]);
408-
return new V1JSONSchemaProps { Type = Object, AdditionalProperties = addlProps, Nullable = false };
404+
var additionalProperties = context.Map(listType.GenericTypeArguments[1]);
405+
return new V1JSONSchemaProps
406+
{
407+
Type = Object,
408+
AdditionalProperties = additionalProperties,
409+
Nullable = false,
410+
};
409411
}
410412

411413
var items = context.Map(listType);
412414
return new V1JSONSchemaProps { Type = Array, Items = items, Nullable = false };
413415
}
414416

415-
private static V1JSONSchemaProps MapValueType(this MetadataLoadContext context, Type type)
416-
{
417-
switch (type.FullName)
417+
private static V1JSONSchemaProps MapValueType(this MetadataLoadContext _, Type type) =>
418+
type.FullName switch
418419
{
419-
case "System.Int32":
420-
return new V1JSONSchemaProps { Type = Integer, Format = Int32, Nullable = false };
421-
case "System.Int64":
422-
return new V1JSONSchemaProps { Type = Integer, Format = Int64, Nullable = false };
423-
case "System.Single":
424-
return new V1JSONSchemaProps { Type = Number, Format = Float, Nullable = false };
425-
case "System.Double":
426-
return new V1JSONSchemaProps { Type = Number, Format = Double, Nullable = false };
427-
case "System.Decimal":
428-
return new V1JSONSchemaProps { Type = Number, Format = Decimal, Nullable = false };
429-
case "System.Boolean":
430-
return new V1JSONSchemaProps { Type = Boolean, Nullable = false };
431-
case "System.DateTime":
432-
case "System.DateTimeOffset":
433-
return new V1JSONSchemaProps { Type = String, Format = DateTime, Nullable = false };
434-
default:
435-
throw InvalidType(type);
436-
}
437-
}
420+
"System.Int32" => new V1JSONSchemaProps { Type = Integer, Format = Int32, Nullable = false },
421+
"System.Int64" => new V1JSONSchemaProps { Type = Integer, Format = Int64, Nullable = false },
422+
"System.Single" => new V1JSONSchemaProps { Type = Number, Format = Float, Nullable = false },
423+
"System.Double" => new V1JSONSchemaProps { Type = Number, Format = Double, Nullable = false },
424+
"System.Decimal" => new V1JSONSchemaProps { Type = Number, Format = Decimal, Nullable = false },
425+
"System.Boolean" => new V1JSONSchemaProps { Type = Boolean, Nullable = false },
426+
"System.DateTime" => new V1JSONSchemaProps { Type = String, Format = DateTime, Nullable = false },
427+
"System.DateTimeOffset" => new V1JSONSchemaProps { Type = String, Format = DateTime, Nullable = false },
428+
_ => throw InvalidType(type),
429+
};
438430

439-
private static ArgumentException InvalidType(Type type)
440-
{
441-
return new ArgumentException($"The given type {type.FullName} is not a valid Kubernetes entity.");
442-
}
431+
private static ArgumentException InvalidType(Type type) =>
432+
new($"The given type {type.FullName} is not a valid Kubernetes entity.");
443433
}

0 commit comments

Comments
 (0)