Skip to content

Commit 27c07fa

Browse files
committed
feat(kubernetes): improve code formatting and structure
- Refactored various files for better readability by adjusting spacing and line breaks. - Ensured consistent formatting in method signatures and property definitions. - Updated package references in `Directory.Packages.props` for clarity. No breaking changes introduced.
1 parent 8b26ff8 commit 27c07fa

File tree

14 files changed

+94
-97
lines changed

14 files changed

+94
-97
lines changed

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<!--Disable warnings NuGet vulnerabilities - NU1901;NU1902;NU1903; - -->
1717
<NoWarn>CS1591;CS1571;CS1573;CS1574;CS1723;NU1901;NU1902;NU1903;</NoWarn>
1818
</PropertyGroup>
19-
19+
2020
<!-- JetBrains.Annotations -->
2121
<ItemGroup>
2222
<PackageReference Include="JetBrains.Annotations" PrivateAssets="All" />

src/Directory.Packages.props

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<Project>
2-
<PropertyGroup>
3-
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
4-
<CentralPackageTransitivePinningEnabled>false</CentralPackageTransitivePinningEnabled>
5-
</PropertyGroup>
6-
<ItemGroup>
7-
<PackageVersion Include="ES.FX" Version="9.1.0-develop.146" />
8-
<PackageVersion Include="ES.FX.Ignite" Version="9.1.0-develop.146" />
9-
<PackageVersion Include="ES.FX.Ignite.OpenTelemetry.Exporter.Seq" Version="9.1.0-develop.146" />
10-
<PackageVersion Include="ES.FX.Ignite.Serilog" Version="9.1.0-develop.146" />
11-
<PackageVersion Include="JetBrains.Annotations" Version="2024.3.0" />
12-
<PackageVersion Include="KubernetesClient" Version="16.0.2" />
13-
<PackageVersion Include="MediatR" Version="12.4.1" />
14-
<PackageVersion Include="Microsoft.AspNetCore.JsonPatch" Version="9.0.2" />
15-
<PackageVersion Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
16-
</ItemGroup>
2+
<PropertyGroup>
3+
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
4+
<CentralPackageTransitivePinningEnabled>false</CentralPackageTransitivePinningEnabled>
5+
</PropertyGroup>
6+
<ItemGroup>
7+
<PackageVersion Include="ES.FX" Version="9.1.0-develop.146" />
8+
<PackageVersion Include="ES.FX.Ignite" Version="9.1.0-develop.146" />
9+
<PackageVersion Include="ES.FX.Ignite.OpenTelemetry.Exporter.Seq" Version="9.1.0-develop.146" />
10+
<PackageVersion Include="ES.FX.Ignite.Serilog" Version="9.1.0-develop.146" />
11+
<PackageVersion Include="JetBrains.Annotations" Version="2024.3.0" />
12+
<PackageVersion Include="KubernetesClient" Version="16.0.2" />
13+
<PackageVersion Include="MediatR" Version="12.4.1" />
14+
<PackageVersion Include="Microsoft.AspNetCore.JsonPatch" Version="9.0.2" />
15+
<PackageVersion Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
16+
</ItemGroup>
1717
</Project>

src/ES.Kubernetes.Reflector/Core/ConfigMapMirror.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public class ConfigMapMirror(ILogger<ConfigMapMirror> logger, IServiceProvider s
1414
protected override async Task<V1ConfigMap[]> OnResourceWithNameList(string itemRefName)
1515
{
1616
using var client = _serviceProvider.GetRequiredService<IKubernetes>();
17-
return (await client.CoreV1.ListConfigMapForAllNamespacesAsync(fieldSelector: $"metadata.name={itemRefName}")).Items
17+
return (await client.CoreV1.ListConfigMapForAllNamespacesAsync(fieldSelector: $"metadata.name={itemRefName}"))
18+
.Items
1819
.ToArray();
1920
}
2021

src/ES.Kubernetes.Reflector/Core/ConfigMapWatcher.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ public class ConfigMapWatcher(
1515
IOptionsMonitor<ReflectorOptions> options)
1616
: WatcherBackgroundService<V1ConfigMap, V1ConfigMapList>(logger, mediator, serviceProvider, options)
1717
{
18-
protected override Task<HttpOperationResponse<V1ConfigMapList>> OnGetWatcher(IKubernetes client ,CancellationToken cancellationToken)
18+
protected override Task<HttpOperationResponse<V1ConfigMapList>> OnGetWatcher(IKubernetes client,
19+
CancellationToken cancellationToken)
1920
{
20-
return client.CoreV1.ListConfigMapForAllNamespacesWithHttpMessagesAsync(watch: true, timeoutSeconds: WatcherTimeout,
21+
return client.CoreV1.ListConfigMapForAllNamespacesWithHttpMessagesAsync(watch: true,
22+
timeoutSeconds: WatcherTimeout,
2123
cancellationToken: cancellationToken);
2224
}
2325
}

src/ES.Kubernetes.Reflector/Core/Extensions/MetadataExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static class MetadataExtensions
1111

1212
public static IReadOnlyDictionary<string, string> SafeAnnotations(this V1ObjectMeta metadata)
1313
{
14-
return (IReadOnlyDictionary<string, string>) (metadata.Annotations ?? new Dictionary<string, string>());
14+
return (IReadOnlyDictionary<string, string>)(metadata.Annotations ?? new Dictionary<string, string>());
1515
}
1616

1717
public static KubeRef GetRef(this IKubernetesObject<V1ObjectMeta> resource)
@@ -39,11 +39,11 @@ public static bool TryGet<T>(this IReadOnlyDictionary<string, string> annotation
3939
Converters.TryAdd(typeof(T), conv);
4040
}
4141

42-
value = (T?) conv.ConvertFromString(raw.Trim());
42+
value = (T?)conv.ConvertFromString(raw.Trim());
4343
}
4444
else
4545
{
46-
value = (T) Convert.ChangeType(raw.Trim(), typeof(T));
46+
value = (T)Convert.ChangeType(raw.Trim(), typeof(T));
4747
}
4848

4949
return true;

src/ES.Kubernetes.Reflector/Core/Json/JsonPropertyNameContractResolver.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@ protected override JsonProperty CreateProperty(MemberInfo member, MemberSerializ
1818
if (member.GetCustomAttribute<JsonPropertyNameAttribute>() is not { } propertyNameAttribute) return property;
1919
property.PropertyName = propertyNameAttribute.Name;
2020
return property;
21-
2221
}
2322
}

src/ES.Kubernetes.Reflector/Core/Mirroring/Extensions/ReflectionStatusExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static bool CanBeAutoReflectedToNamespace(this ReflectorProperties proper
2020
private static bool PatternListMatch(string patternList, string value)
2121
{
2222
if (string.IsNullOrEmpty(patternList)) return true;
23-
var regexPatterns = patternList.Split(new[] {","}, StringSplitOptions.RemoveEmptyEntries);
23+
var regexPatterns = patternList.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
2424
return regexPatterns.Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => s.Trim())
2525
.Select(pattern => Regex.Match(value, pattern))
2626
.Any(match => match.Success && match.Value.Length == value.Length);

src/ES.Kubernetes.Reflector/Core/Mirroring/ResourceMirror.cs

Lines changed: 46 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@ public abstract class ResourceMirror<TResource>(ILogger logger, IServiceProvider
3131

3232

3333
/// <summary>
34-
/// Handles <see cref="WatcherClosed"/> notifications
34+
/// Handles <see cref="WatcherClosed" /> notifications
3535
/// </summary>
3636
public Task Handle(WatcherClosed notification, CancellationToken cancellationToken)
3737
{
38-
3938
//If not TResource or Namespace, not something this instance should handle
4039
if (notification.ResourceType != typeof(TResource) &&
4140
notification.ResourceType != typeof(V1Namespace)) return Task.CompletedTask;
@@ -52,9 +51,8 @@ public Task Handle(WatcherClosed notification, CancellationToken cancellationTok
5251
}
5352

5453
/// <summary>
55-
/// Handles <see cref="WatcherEvent"/> notifications
54+
/// Handles <see cref="WatcherEvent" /> notifications
5655
/// </summary>
57-
5856
public async Task Handle(WatcherEvent notification, CancellationToken cancellationToken)
5957
{
6058
switch (notification.Item)
@@ -74,37 +72,37 @@ public async Task Handle(WatcherEvent notification, CancellationToken cancellati
7472
{
7573
case WatchEventType.Added:
7674
case WatchEventType.Modified:
77-
{
78-
await HandleUpsert(resource, cancellationToken);
79-
}
75+
{
76+
await HandleUpsert(resource, cancellationToken);
77+
}
8078
break;
8179
case WatchEventType.Deleted:
80+
{
81+
_propertiesCache.Remove(itemRef, out _);
82+
var properties = resource.GetReflectionProperties();
83+
84+
85+
if (!properties.IsReflection)
8286
{
83-
_propertiesCache.Remove(itemRef, out _);
84-
var properties = resource.GetReflectionProperties();
85-
86-
87-
if (!properties.IsReflection)
88-
{
89-
if (properties is { Allowed: true, AutoEnabled: true } &&
90-
_autoReflectionCache.TryGetValue(itemRef, out var reflectionList))
91-
foreach (var reflectionId in reflectionList.ToArray())
92-
{
93-
Logger.LogDebug("Deleting {id} - Source {sourceId} has been deleted", reflectionId,
94-
itemRef);
95-
await OnResourceDelete(reflectionId);
96-
}
97-
98-
_autoSources.Remove(itemRef, out _);
99-
_directReflectionCache.Remove(itemRef, out _);
100-
_autoReflectionCache.Remove(itemRef, out _);
101-
}
102-
else
103-
{
104-
foreach (var item in _directReflectionCache) item.Value.Remove(itemRef);
105-
foreach (var item in _autoReflectionCache) item.Value.Remove(itemRef);
106-
}
87+
if (properties is { Allowed: true, AutoEnabled: true } &&
88+
_autoReflectionCache.TryGetValue(itemRef, out var reflectionList))
89+
foreach (var reflectionId in reflectionList.ToArray())
90+
{
91+
Logger.LogDebug("Deleting {id} - Source {sourceId} has been deleted", reflectionId,
92+
itemRef);
93+
await OnResourceDelete(reflectionId);
94+
}
95+
96+
_autoSources.Remove(itemRef, out _);
97+
_directReflectionCache.Remove(itemRef, out _);
98+
_autoReflectionCache.Remove(itemRef, out _);
10799
}
100+
else
101+
{
102+
foreach (var item in _directReflectionCache) item.Value.Remove(itemRef);
103+
foreach (var item in _autoReflectionCache) item.Value.Remove(itemRef);
104+
}
105+
}
108106
break;
109107
case WatchEventType.Error:
110108
case WatchEventType.Bookmark:
@@ -114,29 +112,29 @@ public async Task Handle(WatcherEvent notification, CancellationToken cancellati
114112

115113
break;
116114
case V1Namespace ns:
117-
{
118-
if (notification.Type != WatchEventType.Added) return;
119-
Logger.LogTrace("Handling {eventType} {resourceType} {resourceRef}", notification.Type, ns.Kind,
120-
ns.GetRef());
115+
{
116+
if (notification.Type != WatchEventType.Added) return;
117+
Logger.LogTrace("Handling {eventType} {resourceType} {resourceRef}", notification.Type, ns.Kind,
118+
ns.GetRef());
121119

122120

123-
foreach (var autoSourceRef in _autoSources.Keys)
124-
{
125-
var properties = _propertiesCache[autoSourceRef];
126-
if (!properties.CanBeAutoReflectedToNamespace(ns.Name())) continue;
121+
foreach (var autoSourceRef in _autoSources.Keys)
122+
{
123+
var properties = _propertiesCache[autoSourceRef];
124+
if (!properties.CanBeAutoReflectedToNamespace(ns.Name())) continue;
127125

128126

129-
var reflectionRef = new KubeRef(ns.Name(), autoSourceRef.Name);
130-
var autoReflectionList = _autoReflectionCache.GetOrAdd(autoSourceRef, new List<KubeRef>());
127+
var reflectionRef = new KubeRef(ns.Name(), autoSourceRef.Name);
128+
var autoReflectionList = _autoReflectionCache.GetOrAdd(autoSourceRef, new List<KubeRef>());
131129

132-
if (autoReflectionList.Contains(reflectionRef)) return;
130+
if (autoReflectionList.Contains(reflectionRef)) return;
133131

134-
await ResourceReflect(autoSourceRef, reflectionRef, null, null, true);
132+
await ResourceReflect(autoSourceRef, reflectionRef, null, null, true);
135133

136-
if (!autoReflectionList.Contains(reflectionRef))
137-
autoReflectionList.Add(reflectionRef);
138-
}
134+
if (!autoReflectionList.Contains(reflectionRef))
135+
autoReflectionList.Add(reflectionRef);
139136
}
137+
}
140138
break;
141139
}
142140
}
@@ -179,13 +177,13 @@ private async Task HandleUpsert(TResource resource, CancellationToken cancellati
179177
await OnResourceDelete(reflectionId);
180178
}
181179

182-
var isAutoSource = properties is { Allowed: true, AutoEnabled: true};
180+
var isAutoSource = properties is { Allowed: true, AutoEnabled: true };
183181

184182
//Update the status of an auto-source
185183
_autoSources.AddOrUpdate(resourceRef, isAutoSource, (_, _) => isAutoSource);
186184

187185
//If not allowed or auto is disabled, remove the cache for auto-reflections
188-
if (!isAutoSource) { _autoReflectionCache.Remove(resourceRef, out _); }
186+
if (!isAutoSource) _autoReflectionCache.Remove(resourceRef, out _);
189187

190188
//If reflection is disabled, remove the reflections cache and stop reflecting
191189
if (!properties.Allowed)
@@ -367,7 +365,6 @@ private async Task AutoReflectionForSource(KubeRef resourceRef, TResource? resou
367365
m.GetReflectionProperties().Reflects.Equals(resourceRef))
368366
.Select(m => m.GetRef()).ToList();
369367

370-
371368

372369
autoReflectionList.Clear();
373370
autoReflectionList.AddRange(toCreate);
@@ -514,5 +511,4 @@ protected virtual Task<bool> OnResourceIgnoreCheck(TResource item)
514511
{
515512
return Task.FromResult(false);
516513
}
517-
518514
}

src/ES.Kubernetes.Reflector/Core/NamespaceWatcher.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public class NamespaceWatcher(
1515
IOptionsMonitor<ReflectorOptions> options)
1616
: WatcherBackgroundService<V1Namespace, V1NamespaceList>(logger, mediator, serviceProvider, options)
1717
{
18-
protected override Task<HttpOperationResponse<V1NamespaceList>> OnGetWatcher(IKubernetes client,CancellationToken cancellationToken)
18+
protected override Task<HttpOperationResponse<V1NamespaceList>> OnGetWatcher(IKubernetes client,
19+
CancellationToken cancellationToken)
1920
{
2021
return client.CoreV1.ListNamespaceWithHttpMessagesAsync(watch: true, timeoutSeconds: WatcherTimeout,
2122
cancellationToken: cancellationToken);

src/ES.Kubernetes.Reflector/Core/Resources/KubeRef.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public KubeRef(string ns, string name)
1515
public KubeRef(string value)
1616
{
1717
if (string.IsNullOrWhiteSpace(value)) return;
18-
var split = value.Split(new[] {"/"}, StringSplitOptions.RemoveEmptyEntries).ToList();
18+
var split = value.Split(new[] { "/" }, StringSplitOptions.RemoveEmptyEntries).ToList();
1919
if (!split.Any()) return;
2020
switch (split.Count)
2121
{
@@ -39,12 +39,19 @@ public KubeRef(V1ObjectMeta metadata) : this(metadata.Namespace() ?? string.Empt
3939
public string Name { get; } = string.Empty;
4040

4141

42+
public bool Equals(KubeRef? other)
43+
{
44+
if (ReferenceEquals(this, other)) return true;
45+
return string.Equals(Namespace, other?.Namespace) && string.Equals(Name, other?.Name);
46+
}
47+
48+
4249
public static bool TryParse(string value, out KubeRef id)
4350
{
4451
id = Empty;
4552
if (string.IsNullOrWhiteSpace(value)) return false;
4653

47-
var split = value.Trim().Split(new[] {"/"}, StringSplitOptions.RemoveEmptyEntries).ToList();
54+
var split = value.Trim().Split(new[] { "/" }, StringSplitOptions.RemoveEmptyEntries).ToList();
4855
if (!split.Any()) return false;
4956
if (split.Count > 2) return false;
5057
id = split.Count == 1
@@ -55,15 +62,6 @@ public static bool TryParse(string value, out KubeRef id)
5562
}
5663

5764

58-
public bool Equals(KubeRef? other)
59-
{
60-
if (ReferenceEquals(this, other)) return true;
61-
return string.Equals(Namespace, other?.Namespace) && string.Equals(Name, other?.Name);
62-
}
63-
64-
65-
66-
6765
public override int GetHashCode()
6866
{
6967
unchecked

0 commit comments

Comments
 (0)