Skip to content

Commit 4e675b8

Browse files
committed
refactor(function naming): Use best practice names.
BREAKING CHANGE: This essentially renames all async functions. According to best practices, async functions should have the suffix `Async`.
1 parent 307cc55 commit 4e675b8

File tree

17 files changed

+57
-53
lines changed

17 files changed

+57
-53
lines changed

src/KubeOps/Operator/Caching/ResourceCache.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
namespace KubeOps.Operator.Caching
1111
{
12-
internal class ResourceCache<TEntity>
13-
where TEntity : IKubernetesObject<V1ObjectMeta>
12+
internal class ResourceCache<TResource>
13+
where TResource : IKubernetesObject<V1ObjectMeta>
1414
{
1515
private const string ResourceVersion = "ResourceVersion";
1616
private const string ManagedFields = "ManagedFields";
@@ -25,18 +25,18 @@ internal class ResourceCache<TEntity>
2525
MembersToIgnore = new() { ResourceVersion, ManagedFields },
2626
});
2727

28-
private readonly ConcurrentDictionary<string, TEntity> _cache = new();
28+
private readonly ConcurrentDictionary<string, TResource> _cache = new();
2929

30-
private readonly ResourceCacheMetrics<TEntity> _metrics;
30+
private readonly ResourceCacheMetrics<TResource> _metrics;
3131

32-
public ResourceCache(ResourceCacheMetrics<TEntity> metrics)
32+
public ResourceCache(ResourceCacheMetrics<TResource> metrics)
3333
{
3434
_metrics = metrics;
3535
}
3636

37-
public TEntity Get(string id) => _cache[id];
37+
public TResource Get(string id) => _cache[id];
3838

39-
public TEntity Upsert(TEntity resource, out CacheComparisonResult result)
39+
public TResource Upsert(TResource resource, out CacheComparisonResult result)
4040
{
4141
result = CompareCache(resource);
4242

@@ -48,9 +48,9 @@ public TEntity Upsert(TEntity resource, out CacheComparisonResult result)
4848
return resource;
4949
}
5050

51-
public void Fill(IEnumerable<TEntity> entities)
51+
public void Fill(IEnumerable<TResource> resources)
5252
{
53-
foreach (var entity in entities)
53+
foreach (var entity in resources)
5454
{
5555
var clone = entity.DeepClone();
5656
_cache.AddOrUpdate(entity.Metadata.Uid, clone, (_, _) => clone);
@@ -60,7 +60,7 @@ public void Fill(IEnumerable<TEntity> entities)
6060
_metrics.CachedItemsSummary.Observe(_cache.Count);
6161
}
6262

63-
public void Remove(TEntity resource) => Remove(resource.Metadata.Uid);
63+
public void Remove(TResource resource) => Remove(resource.Metadata.Uid);
6464

6565
public void Clear()
6666
{
@@ -69,7 +69,7 @@ public void Clear()
6969
_metrics.CachedItemsSummary.Observe(_cache.Count);
7070
}
7171

72-
private CacheComparisonResult CompareCache(TEntity resource)
72+
private CacheComparisonResult CompareCache(TResource resource)
7373
{
7474
if (!Exists(resource))
7575
{
@@ -96,7 +96,7 @@ private CacheComparisonResult CompareCache(TEntity resource)
9696
return CacheComparisonResult.Modified;
9797
}
9898

99-
private bool Exists(TEntity resource) => _cache.ContainsKey(resource.Metadata.Uid);
99+
private bool Exists(TResource resource) => _cache.ContainsKey(resource.Metadata.Uid);
100100

101101
private void Remove(string resourceUid)
102102
{

src/KubeOps/Operator/Commands/CommandHelpers/CertificateGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public void Dispose()
6262
Delete(_servercsr);
6363
}
6464

65-
public async Task CreateCaCertificate(string outputFolder)
65+
public async Task CreateCaCertificateAsync(string outputFolder)
6666
{
6767
if (!_initialized)
6868
{
@@ -90,7 +90,7 @@ await ExecuteProcess(
9090
await ListDir(outputFolder);
9191
}
9292

93-
public async Task CreateServerCertificate(
93+
public async Task CreateServerCertificateAsync(
9494
string outputFolder,
9595
string name,
9696
string @namespace,

src/KubeOps/Operator/Commands/CommandHelpers/FileWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void Add(string filename, string content)
2121
_files.Add(filename, content);
2222
}
2323

24-
public async Task Output(string? outputPath = null)
24+
public async Task OutputAsync(string? outputPath = null)
2525
{
2626
if (outputPath == null)
2727
{

src/KubeOps/Operator/Commands/Generators/CrdGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public async Task<int> OnExecuteAsync(CommandLineApplication app)
102102
},
103103
Format));
104104

105-
await fileWriter.Output(OutputPath);
105+
await fileWriter.OutputAsync(OutputPath);
106106
return ExitCodes.Success;
107107
}
108108
}

src/KubeOps/Operator/Commands/Generators/InstallerGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public async Task<int> OnExecuteAsync(CommandLineApplication app)
7878
},
7979
Format));
8080

81-
await fileWriter.Output(OutputPath);
81+
await fileWriter.OutputAsync(OutputPath);
8282
return ExitCodes.Success;
8383
}
8484
}

src/KubeOps/Operator/Commands/Generators/OperatorGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public async Task<int> OnExecuteAsync(CommandLineApplication app)
3737
(!File.Exists(Path.Join(OutputPath, "ca.pem")) || !File.Exists(Path.Join(OutputPath, "ca-key.pem"))))
3838
{
3939
using var certManager = new CertificateGenerator(app.Out);
40-
await certManager.CreateCaCertificate(OutputPath);
40+
await certManager.CreateCaCertificateAsync(OutputPath);
4141
}
4242

4343
fileWriter.Add(
@@ -232,7 +232,7 @@ public async Task<int> OnExecuteAsync(CommandLineApplication app)
232232
}),
233233
Format));
234234

235-
await fileWriter.Output(OutputPath);
235+
await fileWriter.OutputAsync(OutputPath);
236236
return ExitCodes.Success;
237237
}
238238
}

src/KubeOps/Operator/Commands/Generators/RbacGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public async Task<int> OnExecuteAsync(CommandLineApplication app)
9999
},
100100
Format));
101101

102-
await fileWriter.Output(OutputPath);
102+
await fileWriter.OutputAsync(OutputPath);
103103
return ExitCodes.Success;
104104
}
105105
}

src/KubeOps/Operator/Commands/Management/Webhooks/Install.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ public async Task<int> OnExecuteAsync(CommandLineApplication app)
5252
#if DEBUG
5353
CertificatesPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
5454
CaCertificatesPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
55-
await certManager.CreateCaCertificate(CaCertificatesPath);
55+
await certManager.CreateCaCertificateAsync(CaCertificatesPath);
5656
#endif
5757

5858
Directory.CreateDirectory(CertificatesPath);
5959
File.Copy(Path.Join(CaCertificatesPath, "ca.pem"), Path.Join(Path.Join(CertificatesPath, "ca.pem")));
60-
await certManager.CreateServerCertificate(
60+
await certManager.CreateServerCertificateAsync(
6161
CertificatesPath,
6262
_settings.Name,
6363
@namespace,

src/KubeOps/Operator/Commands/RunOperator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal class RunOperator
1818
{
1919
private readonly IHost _host;
2020
private readonly IKubernetesClient _client;
21-
private OperatorSettings _settings;
21+
private readonly OperatorSettings _settings;
2222

2323
public RunOperator(IHost host, IKubernetesClient client, OperatorSettings settings)
2424
{

src/KubeOps/Operator/Controller/IManagedResourceController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ internal interface IManagedResourceController : IDisposable
77
{
88
Type ControllerType { get; set; }
99

10-
Task Start();
10+
Task StartAsync();
1111

12-
Task Stop();
12+
Task StopAsync();
1313
}
1414
}

0 commit comments

Comments
 (0)