Skip to content

Initial port of cache functions from java client #665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Aug 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/KubernetesClient/KubernetesClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@
<PackageReference Include="IdentityModel.OidcClient" Version="3.1.2" />
</ItemGroup>

<ItemGroup>
<Folder Include="Util\Informer" />
</ItemGroup>

</Project>
16 changes: 16 additions & 0 deletions src/KubernetesClient/Util/Common/CallGeneratorParams.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace k8s.Util.Common
{
public class CallGeneratorParams
{
public bool Watch { get; }
public string ResourceVersion { get; }
public int? TimeoutSeconds { get; }

public CallGeneratorParams(bool watch, string resourceVersion, int? timeoutSeconds)
{
Watch = watch;
ResourceVersion = resourceVersion;
TimeoutSeconds = timeoutSeconds;
}
}
}
43 changes: 43 additions & 0 deletions src/KubernetesClient/Util/Common/CollectionsExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;

namespace k8s.Util.Common
{
internal static class CollectionsExtensions
{
public static void AddRange<T>(this HashSet<T> hashSet, ICollection<T> items)
{
if (items == null)
{
return;
}

foreach (var item in items)
{
hashSet?.Add(item);
}
}

internal static TValue ComputeIfAbsent<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, Func<TKey, TValue> mappingFunction)
{
if (dictionary is null)
{
throw new ArgumentNullException(nameof(dictionary));
}

if (dictionary.TryGetValue(key, out var value))
{
return value;
}

if (mappingFunction == null)
{
throw new ArgumentNullException(nameof(mappingFunction));
}

var newKey = mappingFunction(key);
dictionary[key] = newKey;
return newKey;
}
}
}
Loading