Skip to content

Commit 54c200d

Browse files
anpinAarononthewebArkatufus
authored
Akka.Discovery.Dns (#3365)
* init Akka.Discovery.Dns only A/AAAA records are supported at this moment * init dns cluster example * SRV example cluster is starting * cleanup commented code and typos * Custom override for DnsExt is no longer required see akkadotnet/akka.net#7727 * fix IPv6 formating * fix logging of parsed IP records * separate A and AAAA examples * use dns.oci root domain instead of default dns.podman for runtime independent expirience * use docker-compose to run examples as it is more common * fix reference HOCON * cleanup hosting extensions * make internals availiable to tests * tests for DNS lookup and config parsing * Handle multiple nameservers * Cache for async-dns resolver * Refactor AsyncDnsClient: - Rename DnsClient to AsyncDnsClient.cs - Drop answer wrapper messages and use DnsProtocol.Message directly - Fix handling of legacy IO.Dns.Resolve requests - Add tests for various combinations of positive-ttl parameter which affect caching strategy * Add IDnsProviderWithSrvLookup and refactor tests * test TCP fallback client * Add missing options to hosting extension * remove leaked local dev settings * Upgrade to Akka.NET v1.5.46 * skip check of AAAA records on Windows with default resolver * update docs * fix compiler warnings and slight cache refactor * Add additional records to lookup result * add doc comments * reduce line noise * Fix/add documentation * make constructors for immutable messages private * Make TcpDropped message immutable and handle it * Remove unreferenced DropRequest message and handlers * Reply with error on TCP failure * Refactor query ID generation * applied copilot suggestions * add better comment * Fix DNS resolution in cluster bootstrap examples The dig commands in entrypoint.sh were not specifying the DNS server address, causing them to use the default Docker resolver (127.0.0.11) instead of the configured CoreDNS server. This prevented the demo containers from properly resolving service discovery records. Added @$DNS_SERVER parameter to all dig commands to ensure they query the correct DNS server specified by the DNS_NAMESERVER environment variable. --------- Co-authored-by: Aaron Stannard <aaron@petabridge.com> Co-authored-by: Gregorius Soedharmo <arkatufus@yahoo.com>
1 parent 1c6e72f commit 54c200d

37 files changed

+3580
-2
lines changed

Akka.Management.sln

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.StressTest", "src\coo
8080
EndProject
8181
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HoconKubernetesCluster", "src\cluster.bootstrap\examples\discovery\hocon-kubernetes\src\HoconKubernetesCluster\HoconKubernetesCluster.csproj", "{7015572E-6225-4F32-A00C-4D52280E6C94}"
8282
EndProject
83+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dns", "dns", "{CF2BA83A-4CF9-4E29-9128-A7A3D3ADBB35}"
84+
EndProject
85+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.Discovery.Dns", "src\discovery\dns\Akka.Discovery.Dns\Akka.Discovery.Dns.csproj", "{5C5403F4-F496-4246-8BEC-E125E1A2BC94}"
86+
EndProject
87+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.Discovery.Dns.Tests", "src\discovery\dns\Akka.Discovery.Dns.Tests\Akka.Discovery.Dns.Tests.csproj", "{2E13DE8F-0001-4008-A066-B66B4B640915}"
88+
EndProject
89+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DnsCluster", "src\cluster.bootstrap\examples\discovery\dns\src\DnsCluster.csproj", "{24B1214E-CFE2-44C0-9B0D-8139C269EED5}"
90+
EndProject
8391
Global
8492
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8593
Debug|Any CPU = Debug|Any CPU
@@ -174,6 +182,18 @@ Global
174182
{7015572E-6225-4F32-A00C-4D52280E6C94}.Debug|Any CPU.Build.0 = Debug|Any CPU
175183
{7015572E-6225-4F32-A00C-4D52280E6C94}.Release|Any CPU.ActiveCfg = Release|Any CPU
176184
{7015572E-6225-4F32-A00C-4D52280E6C94}.Release|Any CPU.Build.0 = Release|Any CPU
185+
{5C5403F4-F496-4246-8BEC-E125E1A2BC94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
186+
{5C5403F4-F496-4246-8BEC-E125E1A2BC94}.Debug|Any CPU.Build.0 = Debug|Any CPU
187+
{5C5403F4-F496-4246-8BEC-E125E1A2BC94}.Release|Any CPU.ActiveCfg = Release|Any CPU
188+
{5C5403F4-F496-4246-8BEC-E125E1A2BC94}.Release|Any CPU.Build.0 = Release|Any CPU
189+
{2E13DE8F-0001-4008-A066-B66B4B640915}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
190+
{2E13DE8F-0001-4008-A066-B66B4B640915}.Debug|Any CPU.Build.0 = Debug|Any CPU
191+
{2E13DE8F-0001-4008-A066-B66B4B640915}.Release|Any CPU.ActiveCfg = Release|Any CPU
192+
{2E13DE8F-0001-4008-A066-B66B4B640915}.Release|Any CPU.Build.0 = Release|Any CPU
193+
{24B1214E-CFE2-44C0-9B0D-8139C269EED5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
194+
{24B1214E-CFE2-44C0-9B0D-8139C269EED5}.Debug|Any CPU.Build.0 = Debug|Any CPU
195+
{24B1214E-CFE2-44C0-9B0D-8139C269EED5}.Release|Any CPU.ActiveCfg = Release|Any CPU
196+
{24B1214E-CFE2-44C0-9B0D-8139C269EED5}.Release|Any CPU.Build.0 = Release|Any CPU
177197
EndGlobalSection
178198
GlobalSection(SolutionProperties) = preSolution
179199
HideSolutionNode = FALSE
@@ -209,6 +229,10 @@ Global
209229
{296A0309-2370-4153-B3B0-A4105622CC9A} = {C4C8BE03-A7C0-4F2E-8922-92854FE7A5BF}
210230
{24FEBA95-1FC2-4AC2-8386-6AB13AE87056} = {9B10ADF5-60D1-4EED-9E98-9CB2E1E84E98}
211231
{7015572E-6225-4F32-A00C-4D52280E6C94} = {24FEBA95-1FC2-4AC2-8386-6AB13AE87056}
232+
{CF2BA83A-4CF9-4E29-9128-A7A3D3ADBB35} = {52ACBC5B-D5F0-4FEA-A27B-0A8577204E64}
233+
{5C5403F4-F496-4246-8BEC-E125E1A2BC94} = {CF2BA83A-4CF9-4E29-9128-A7A3D3ADBB35}
234+
{2E13DE8F-0001-4008-A066-B66B4B640915} = {CF2BA83A-4CF9-4E29-9128-A7A3D3ADBB35}
235+
{24B1214E-CFE2-44C0-9B0D-8139C269EED5} = {24FEBA95-1FC2-4AC2-8386-6AB13AE87056}
212236
EndGlobalSection
213237
GlobalSection(ExtensibilityGlobals) = postSolution
214238
SolutionGuid = {B99E6BB8-642A-4A68-86DF-69567CBA700A}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ These tools aims to help with cluster management in various dynamic environments
1414
* [`Akka.Discovery.AwsApi`](/src/discovery/aws/Akka.Discovery.AwsApi) - Akka.Cluster bootstrapping discovery service using EC2, ECS, and the AWS API. You can read more in the documentation [here](https://github.com/akkadotnet/Akka.Management/blob/dev/src/discovery/aws/Akka.Discovery.AwsApi/README.md).
1515
* [`Akka.Discovery.KubernetesApi`](/src/discovery/kubernetes/Akka.Discovery.KubernetesApi) - Akka.Cluster bootstrapping discovery service using Kubernetes API. You can read more in the documentation [here](https://github.com/akkadotnet/Akka.Management/blob/dev/src/discovery/kubernetes/Akka.Discovery.KubernetesApi/README.md).
1616
* [`Akka.Discovery.Azure`](src/discovery/azure/Akka.Discovery.Azure) - Akka.Cluster bootstrapping discovery service using Azure Table Storage. You can read more in the documentation [here](https://github.com/akkadotnet/Akka.Management/blob/dev/src/discovery/azure/Akka.Discovery.Azure/README.md).
17+
* [`Akka.Discovery.Dns`](src/discovery/dns/Akka.Discovery.Dns) - Akka.Cluster bootstrapping discovery service using DNS. You can read more in the documentation [here](https://github.com/akkadotnet/Akka.Management/blob/dev/src/discovery/dns/Akka.Discovery.Dns/README.md).
1718
* [`Akka.Coordination.KubernetesApi`](https://github.com/akkadotnet/Akka.Management/tree/dev/src/coordination/kubernetes/Akka.Coordination.KubernetesApi) - provides a lease-based distributed lock mechanism backed by [Kubernetes CRD](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/) for [Akka.NET Split Brain Resolver](https://getakka.net/articles/clustering/split-brain-resolver.html), [Akka.Cluster.Sharding](https://getakka.net/articles/clustering/cluster-sharding.html), and [Akka.Cluster.Singleton](https://getakka.net/articles/clustering/cluster-singleton.html). Documentation can be read [here](https://github.com/akkadotnet/Akka.Management/blob/dev/src/coordination/kubernetes/Akka.Coordination.KubernetesApi/README.md)
1819
* [`Akka.Coordination.Azure`](https://github.com/akkadotnet/Akka.Management/tree/dev/src/coordination/azure/Akka.Coordination.Azure) - provides a lease-based distributed lock mechanism backed by [Microsoft Azure Blob Storage](https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blobs-overview) for [Akka.NET Split Brain Resolver](https://getakka.net/articles/clustering/split-brain-resolver.html), [Akka.Cluster.Sharding](https://getakka.net/articles/clustering/cluster-sharding.html), and [Akka.Cluster.Singleton](https://getakka.net/articles/clustering/cluster-singleton.html). Documentation can be read [here](https://github.com/akkadotnet/Akka.Management/blob/dev/src/coordination/azure/Akka.Coordination.Azure/README.md)
1920

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# DNS Cluster Bootstrap Example
2+
3+
This example demonstrates how to use DNS-based service discovery with Akka.Management Cluster Bootstrap to form an Akka.NET Cluster.
4+
5+
Three types of records are supported: A, AAAA and SRV.
6+
7+
To run exmample use:
8+
```pwsh
9+
./build.ps1 [a|aaaa|srv]
10+
```
11+
This will build example on your host machine and spawn dedicated docker-compose file for each record type.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env pwsh
2+
3+
param(
4+
[Parameter(Mandatory=$false)]
5+
[string]$recordType = "srv"
6+
)
7+
8+
if ($recordType -ne "srv" -and $recordType -ne "a" -and $recordType -ne "aaaa") {
9+
Write-Error "Invalid record type. Must be 'srv' or 'a' or 'aaaa'."
10+
exit 1
11+
}
12+
Write-Output "Cleaning up previous containers (ignore errors if containers do not exist)...."
13+
docker-compose -f "$(pwd)/src/docker-compose.srv.yml" down
14+
docker-compose -f "$(pwd)/src/docker-compose.aaaa.yml" down
15+
docker-compose -f "$(pwd)/src/docker-compose.a.yml" down
16+
17+
Write-Output "Building and publishing example..."
18+
dotnet publish --os linux --arch x64 -c Release /t:PublishContainer ./src/DnsCluster.csproj
19+
20+
Write-Output "Start $recordType example"
21+
docker-compose -f "$(pwd)/src/docker-compose.$recordType.yml" up --build
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>$(TestsNet)</TargetFramework>
6+
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
7+
<IsPackable>false</IsPackable>
8+
<LangVersion>latest</LangVersion>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0" />
13+
<PackageReference Include="Akka.Hosting" Version="$(AkkaHostingVersion)" />
14+
<PackageReference Include="Akka.Cluster.Hosting" Version="$(AkkaHostingVersion)" />
15+
<PackageReference Include="Akka.Cluster.Tools" Version="$(AkkaVersion)" />
16+
<PackageReference Include="Akka.DependencyInjection" Version="$(AkkaVersion)" />
17+
<PackageReference Include="Petabridge.Cmd.Cluster" Version="$(PbmVersion)" />
18+
<PackageReference Include="Petabridge.Cmd.Remote" Version="$(PbmVersion)" />
19+
</ItemGroup>
20+
21+
<ItemGroup>
22+
<ProjectReference Include="..\..\..\..\..\discovery\dns\Akka.Discovery.Dns\Akka.Discovery.Dns.csproj" />
23+
<ProjectReference Include="..\..\..\..\..\management\Akka.Management\Akka.Management.csproj" />
24+
25+
</ItemGroup>
26+
27+
<ItemGroup>
28+
<Compile Include="..\..\kubernetes\src\KubernetesCluster\Actors\ChaosActor.cs">
29+
<Link>Actors\ChaosActor.cs</Link>
30+
</Compile>
31+
<Compile Include="..\..\kubernetes\src\KubernetesCluster\Actors\ClusterListener.cs">
32+
<Link>Actors\ClusterListener.cs</Link>
33+
</Compile>
34+
<Compile Include="..\..\kubernetes\src\KubernetesCluster\Actors\SubscriberActor.cs">
35+
<Link>Actors\SubscriberActor.cs</Link>
36+
</Compile>
37+
</ItemGroup>
38+
39+
</Project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM mcr.microsoft.com/dotnet/aspnet:9.0
2+
3+
# Install DNS utilities and diagnostic tools
4+
RUN apt-get update && apt-get install -y \
5+
dnsutils \
6+
iputils-ping \
7+
net-tools \
8+
&& rm -rf /var/lib/apt/lists/*
9+
# Copy published app
10+
COPY bin/Release/net9.0/linux-x64/publish/ /app
11+
12+
# Copy entrypoint script
13+
COPY entrypoint.sh /entrypoint.sh
14+
RUN chmod +x /entrypoint.sh
15+
16+
# Configure entry point
17+
# ENTRYPOINT ["dotnet", "/app/DnsCluster.dll"]
18+
ENTRYPOINT ["/entrypoint.sh"]

0 commit comments

Comments
 (0)