Skip to content

Commit 4492249

Browse files
refactor: Update code to support .NET 8.0 and newer only (#876)
Co-authored-by: openhands <[email protected]>
1 parent 5a99011 commit 4492249

File tree

7 files changed

+6
-45
lines changed

7 files changed

+6
-45
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ detailed documentation, head to the [GitHub Pages](https://buehler.github.io/dot
1212

1313
## Packages
1414

15-
All packages support .NET6.0 and higher. The reason is that modern C# features are
16-
used and client libraries are still possible for .NET 6.0 and up.
15+
All packages support .NET8.0 and higher. The reason is that modern C# features are
16+
used and client libraries are optimized for .NET 8.0 and up.
1717
Also, the KubernetesClient package follows the same strategy regarding the
18-
older framework versions.
18+
framework versions.
1919
The following packages exist:
2020

2121
| Package | Description | Latest Version |

src/KubeOps.Cli/Transpilation/AssemblyLoader.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,6 @@ private static IEnumerable<TypeInfo> GetTypesToInspect(this MetadataLoadContext
183183
.SelectMany(a => a.DefinedTypes)
184184
.Where(t => !t.IsInterface && !t.IsAbstract && !t.IsGenericType);
185185

186-
#if NET7_0_OR_GREATER
187186
[GeneratedRegex(".*")]
188187
private static partial Regex DefaultRegex();
189-
#else
190-
private static Regex DefaultRegex() => new(".*");
191-
#endif
192188
}

src/KubeOps.Cli/Transpilation/TfmComparer.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Text.RegularExpressions;
1+
using System.Text.RegularExpressions;
22

33
namespace KubeOps.Cli.Transpilation;
44

@@ -7,17 +7,10 @@ namespace KubeOps.Cli.Transpilation;
77
/// </summary>
88
internal sealed partial class TfmComparer : IComparer<string>
99
{
10-
#if NET7_0_OR_GREATER
1110
[GeneratedRegex(
12-
"[(]?(?<tfm>(?<name>(netcoreapp|net|netstandard){1})(?<major>[0-9]+)[.](?<minor>[0-9]+))[)]?",
11+
"[(]?(?<tfm>(?<n>(netcoreapp|net|netstandard){1})(?<major>[0-9]+)[.](?<minor>[0-9]+))[)]?",
1312
RegexOptions.Compiled)]
1413
public static partial Regex TfmRegex();
15-
#else
16-
public static Regex TfmRegex() =>
17-
new(
18-
"[(]?(?<tfm>(?<name>(netcoreapp|net|netstandard){1})(?<major>[0-9]+)[.](?<minor>[0-9]+))[)]?",
19-
RegexOptions.Compiled);
20-
#endif
2114

2215
public int Compare(string? x, string? y)
2316
{

src/KubeOps.Operator/LeaderElection/LeaderElectionBackgroundService.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,7 @@ public async Task StopAsync(CancellationToken cancellationToken)
4848
return;
4949
}
5050

51-
#if NET8_0_OR_GREATER
5251
await _cts.CancelAsync();
53-
#else
54-
_cts.Cancel();
55-
#endif
5652

5753
if (_leadershipTask is not null)
5854
{

src/KubeOps.Operator/Queue/EntityRequeueBackgroundService.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,7 @@ public Task StopAsync(CancellationToken cancellationToken)
4444
return Task.CompletedTask;
4545
}
4646

47-
#if NET8_0_OR_GREATER
4847
return _cts.CancelAsync();
49-
#else
50-
_cts.Cancel();
51-
return Task.CompletedTask;
52-
#endif
5348
}
5449

5550
public void Dispose()

src/KubeOps.Operator/Watcher/ResourceWatcher{TEntity}.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,7 @@ public virtual async Task StopAsync(CancellationToken cancellationToken)
6262
return;
6363
}
6464

65-
#if NET8_0_OR_GREATER
6665
await _cancellationTokenSource.CancelAsync();
67-
#else
68-
_cancellationTokenSource.Cancel();
69-
#endif
7066
if (_eventWatcher is not null)
7167
{
7268
await _eventWatcher.WaitAsync(cancellationToken);

src/KubeOps.Transpiler/Kubernetes/KubernetesVersionComparer.cs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Text.RegularExpressions;
1+
using System.Text.RegularExpressions;
22

33
namespace KubeOps.Transpiler.Kubernetes;
44

@@ -10,11 +10,6 @@ namespace KubeOps.Transpiler.Kubernetes;
1010
/// </summary>
1111
public sealed partial class KubernetesVersionComparer : IComparer<string>
1212
{
13-
#if !NET7_0_OR_GREATER
14-
private static readonly Regex KubernetesVersionRegex =
15-
new("^v(?<major>[0-9]+)((?<stream>alpha|beta)(?<minor>[0-9]+))?$", RegexOptions.Compiled);
16-
#endif
17-
1813
private enum Stream
1914
{
2015
Alpha = 1,
@@ -29,21 +24,13 @@ public int Compare(string? x, string? y)
2924
return StringComparer.CurrentCulture.Compare(x, y);
3025
}
3126

32-
#if NET7_0_OR_GREATER
3327
var matchX = KubernetesVersionRegex().Match(x);
34-
#else
35-
var matchX = KubernetesVersionRegex.Match(x);
36-
#endif
3728
if (!matchX.Success)
3829
{
3930
return StringComparer.CurrentCulture.Compare(x, y);
4031
}
4132

42-
#if NET7_0_OR_GREATER
4333
var matchY = KubernetesVersionRegex().Match(y);
44-
#else
45-
var matchY = KubernetesVersionRegex.Match(y);
46-
#endif
4734
if (!matchY.Success)
4835
{
4936
return StringComparer.CurrentCulture.Compare(x, y);
@@ -54,10 +41,8 @@ public int Compare(string? x, string? y)
5441
return versionX.CompareTo(versionY);
5542
}
5643

57-
#if NET7_0_OR_GREATER
5844
[GeneratedRegex("^v(?<major>[0-9]+)((?<stream>alpha|beta)(?<minor>[0-9]+))?$", RegexOptions.Compiled)]
5945
private static partial Regex KubernetesVersionRegex();
60-
#endif
6146

6247
private static Version ExtractVersion(Match match)
6348
{

0 commit comments

Comments
 (0)