Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
- ".github/workflows/**"

env:
version: 7.1.${{github.run_number}}
version: 9.0.${{github.run_number}}
imageRepository: "emberstack/kubernetes-reflector"
DOCKER_CLI_EXPERIMENTAL: "enabled"

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ If you need help or found a bug, please feel free to open an Issue on GitHub (ht
Reflector can be deployed either manually or using Helm (recommended).

### Prerequisites
- Kubernetes 1.14+
- Kubernetes 1.22+
- Helm 3 (if deployed using Helm)

#### Deployment using Helm
Expand Down
34 changes: 34 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Project>
<!-- Project defaults -->
<PropertyGroup>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<!--Generate debug symbols and embed them in the build output.-->
<DebugType>embedded</DebugType>
<DebugSymbols>true</DebugSymbols>
<!--Set the solution directory to the parent directory of the build file.-->
<SolutionDir Condition="'$(SolutionDir)' == ''">$(MSBuildThisFileDirectory)..\</SolutionDir>
<!--Generate XML documentation file-->
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<!--Disable warnings from XML documentation - CS1591;CS1571;CS1573;CS1574;CS1723; - -->
<!--Disable warnings NuGet vulnerabilities - NU1901;NU1902;NU1903; - -->
<NoWarn>CS1591;CS1571;CS1573;CS1574;CS1723;NU1901;NU1902;NU1903;</NoWarn>
</PropertyGroup>

<!-- JetBrains.Annotations -->
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" PrivateAssets="All" />
</ItemGroup>

<!--Test projects-->
<ItemGroup Condition="'$(MSBuildProjectName)' == '' Or $(MSBuildProjectName.Contains('.Tests'))">
<AssemblyAttribute Include="System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute" />
</ItemGroup>
<PropertyGroup Condition="'$(MSBuildProjectName)' == '' Or $(MSBuildProjectName.Contains('.Tests'))">
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<VSTestLogger>trx%3bLogFileName=$(MSBuildProjectName).trx</VSTestLogger>
<VSTestResultsDirectory>$(MSBuildThisFileDirectory).artifacts/TestResults</VSTestResultsDirectory>
</PropertyGroup>
</Project>
16 changes: 16 additions & 0 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageTransitivePinningEnabled>false</CentralPackageTransitivePinningEnabled>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="ES.FX.Ignite" Version="9.0.2" />
<PackageVersion Include="ES.FX.Ignite.OpenTelemetry.Exporter.Seq" Version="9.0.2" />
<PackageVersion Include="ES.FX.Ignite.Serilog" Version="9.0.2" />
<PackageVersion Include="JetBrains.Annotations" Version="2024.3.0" />
<PackageVersion Include="KubernetesClient" Version="16.0.2" />
<PackageVersion Include="MediatR" Version="12.4.1" />
<PackageVersion Include="Microsoft.AspNetCore.JsonPatch" Version="9.0.2" />
<PackageVersion Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
</ItemGroup>
</Project>
5 changes: 5 additions & 0 deletions src/ES.Kubernetes.Reflector.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ VisualStudioVersion = 17.0.31710.8
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ES.Kubernetes.Reflector", "ES.Kubernetes.Reflector\ES.Kubernetes.Reflector.csproj", "{96CDE0CF-7782-490B-8AF6-4219DB0236B3}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "....Solution Items", "....Solution Items", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
ProjectSection(SolutionItems) = preProject
Directory.Build.props = Directory.Build.props
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
31 changes: 18 additions & 13 deletions src/ES.Kubernetes.Reflector/Core/ConfigMapMirror.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@

namespace ES.Kubernetes.Reflector.Core;

public class ConfigMapMirror : ResourceMirror<V1ConfigMap>
public class ConfigMapMirror(ILogger<ConfigMapMirror> logger, IServiceProvider serviceProvider)
: ResourceMirror<V1ConfigMap>(logger, serviceProvider)
{
public ConfigMapMirror(ILogger<ConfigMapMirror> logger, IKubernetes client) : base(logger, client)
{
}
private readonly IServiceProvider _serviceProvider = serviceProvider;

protected override async Task<V1ConfigMap[]> OnResourceWithNameList(string itemRefName)
{
return (await Client.CoreV1.ListConfigMapForAllNamespacesAsync(fieldSelector: $"metadata.name={itemRefName}")).Items
using var client = _serviceProvider.GetRequiredService<IKubernetes>();
return (await client.CoreV1.ListConfigMapForAllNamespacesAsync(fieldSelector: $"metadata.name={itemRefName}"))
.Items
.ToArray();
}

protected override Task OnResourceApplyPatch(V1Patch patch, KubeRef refId)
protected override async Task OnResourceApplyPatch(V1Patch patch, KubeRef refId)
{
return Client.CoreV1.PatchNamespacedConfigMapAsync(patch, refId.Name, refId.Namespace);
using var client = _serviceProvider.GetRequiredService<IKubernetes>();
await client.CoreV1.PatchNamespacedConfigMapAsync(patch, refId.Name, refId.Namespace);
}

protected override Task OnResourceConfigurePatch(V1ConfigMap source, JsonPatchDocument<V1ConfigMap> patchDoc)
Expand All @@ -30,9 +32,10 @@ protected override Task OnResourceConfigurePatch(V1ConfigMap source, JsonPatchDo
return Task.CompletedTask;
}

protected override Task OnResourceCreate(V1ConfigMap item, string ns)
protected override async Task OnResourceCreate(V1ConfigMap item, string ns)
{
return Client.CoreV1.CreateNamespacedConfigMapAsync(item, ns);
using var client = _serviceProvider.GetRequiredService<IKubernetes>();
await client.CoreV1.CreateNamespacedConfigMapAsync(item, ns);
}

protected override Task<V1ConfigMap> OnResourceClone(V1ConfigMap sourceResource)
Expand All @@ -46,13 +49,15 @@ protected override Task<V1ConfigMap> OnResourceClone(V1ConfigMap sourceResource)
});
}

protected override Task OnResourceDelete(KubeRef resourceId)
protected override async Task OnResourceDelete(KubeRef resourceId)
{
return Client.CoreV1.DeleteNamespacedConfigMapAsync(resourceId.Name, resourceId.Namespace);
using var client = _serviceProvider.GetRequiredService<IKubernetes>();
await client.CoreV1.DeleteNamespacedConfigMapAsync(resourceId.Name, resourceId.Namespace);
}

protected override Task<V1ConfigMap> OnResourceGet(KubeRef refId)
protected override async Task<V1ConfigMap> OnResourceGet(KubeRef refId)
{
return Client.CoreV1.ReadNamespacedConfigMapAsync(refId.Name, refId.Namespace);
using var client = _serviceProvider.GetRequiredService<IKubernetes>();
return await client.CoreV1.ReadNamespacedConfigMapAsync(refId.Name, refId.Namespace);
}
}
20 changes: 10 additions & 10 deletions src/ES.Kubernetes.Reflector/Core/ConfigMapWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@

namespace ES.Kubernetes.Reflector.Core;

public class ConfigMapWatcher : WatcherBackgroundService<V1ConfigMap, V1ConfigMapList>
public class ConfigMapWatcher(
ILogger<ConfigMapWatcher> logger,
IMediator mediator,
IServiceProvider serviceProvider,
IOptionsMonitor<ReflectorOptions> options)
: WatcherBackgroundService<V1ConfigMap, V1ConfigMapList>(logger, mediator, serviceProvider, options)
{
public ConfigMapWatcher(ILogger<ConfigMapWatcher> logger, IMediator mediator, IKubernetes client,
IOptionsMonitor<ReflectorOptions> options) :
base(logger, mediator, client, options)
protected override Task<HttpOperationResponse<V1ConfigMapList>> OnGetWatcher(IKubernetes client,
CancellationToken cancellationToken)
{
}


protected override Task<HttpOperationResponse<V1ConfigMapList>> OnGetWatcher(CancellationToken cancellationToken)
{
return Client.CoreV1.ListConfigMapForAllNamespacesWithHttpMessagesAsync(watch: true, timeoutSeconds: WatcherTimeout,
return client.CoreV1.ListConfigMapForAllNamespacesWithHttpMessagesAsync(watch: true,
timeoutSeconds: WatcherTimeout,
cancellationToken: cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class MetadataExtensions

public static IReadOnlyDictionary<string, string> SafeAnnotations(this V1ObjectMeta metadata)
{
return (IReadOnlyDictionary<string, string>) (metadata.Annotations ?? new Dictionary<string, string>());
return (IReadOnlyDictionary<string, string>)(metadata.Annotations ?? new Dictionary<string, string>());
}

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

value = (T?) conv.ConvertFromString(raw.Trim());
value = (T?)conv.ConvertFromString(raw.Trim());
}
else
{
value = (T) Convert.ChangeType(raw.Trim(), typeof(T));
value = (T)Convert.ChangeType(raw.Trim(), typeof(T));
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ protected override JsonProperty CreateProperty(MemberInfo member, MemberSerializ
if (member.GetCustomAttribute<JsonPropertyNameAttribute>() is not { } propertyNameAttribute) return property;
property.PropertyName = propertyNameAttribute.Name;
return property;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static bool CanBeAutoReflectedToNamespace(this ReflectorProperties proper
private static bool PatternListMatch(string patternList, string value)
{
if (string.IsNullOrEmpty(patternList)) return true;
var regexPatterns = patternList.Split(new[] {","}, StringSplitOptions.RemoveEmptyEntries);
var regexPatterns = patternList.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
return regexPatterns.Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => s.Trim())
.Select(pattern => Regex.Match(value, pattern))
.Any(match => match.Success && match.Value.Length == value.Length);
Expand Down
Loading