Skip to content

Add multi-domain support via alias zones using ZoneOrigins class#1

Merged
indisoluble merged 35 commits intomasterfrom
copilot/add-multi-domain-support
Feb 21, 2026
Merged

Add multi-domain support via alias zones using ZoneOrigins class#1
indisoluble merged 35 commits intomasterfrom
copilot/add-multi-domain-support

Conversation

Copy link
Contributor

Copilot AI commented Feb 12, 2026

Multi-Domain DNS Support - ZoneOrigins Integration

  • Integrate ZoneOrigins class into DNS configuration
  • Update DnsServerConfig to use zone_origins instead of origin_name + alias_zones
  • Update config factory to create ZoneOrigins instance
  • Update UDP handler to use ZoneOrigins.relativize() method
  • Update zone updater to use zone_origins.primary
  • Update main.py to pass zone_origins to server
  • Update all tests (184 passing)
  • Remove redundant multi-domain test files
  • Clean up unused code and redundant validation
  • Simplify _make_zone_origins function
  • Add Python object protocol methods to ZoneOrigins class

Changes Made

Core Integration:

  • DNS server now supports multiple domains (e.g., long.com and short.com) with the same subdomains resolving to the same IPs
  • Single zone maintained internally with health checks performed only once
  • Query normalization handled transparently via ZoneOrigins.relativize() method

ZoneOrigins Class Enhancement:

  • Added __eq__ method for proper equality comparison based on primary zone and origins
  • Added __hash__ method to enable use in sets and as dictionary keys
  • Added __repr__ method for readable string representation showing primary and aliases
  • 9 new tests added to validate equality, hashing, and repr functionality

Code Simplification:

  • Removed unnecessary conditional logging in _make_zone_origins()
  • Removed redundant subdomain conflict validation (handled by ZoneOrigins)
  • Removed unused _make_alias_zones() function
  • Cleaned up test fixtures to use zone_origins.primary consistently

Interface

Command-line:

a-healthy-dns \
  --hosted-zone primary.com \
  --alias-zones '["alias1.com", "alias2.com"]' \
  --zone-resolutions '{"www": {"ips": ["192.168.1.100"], "health_port": 8080}}' \
  --ns '["ns1.primary.com"]'

Docker:

  • Supports DNS_ALIAS_ZONES environment variable

Result

  • All 184 tests passing
  • www.primary.com, www.alias1.com, and www.alias2.com all resolve to the same IP with a single health check
  • ZoneOrigins class fully integrated with complete Python object protocol support
  • Clean, maintainable codebase with no redundant validation logic
Original prompt

This project code a DNS server based on dnspython library.

In a nutshell, a dnspython zone is filled at the beginning with the data provided with input parameters when the server is launched and, later, A records in the zone are regularly checked to ensure the are still valid.

Then DNS queries are replied based on the updated info into the aforementioned dnspython zone.

However, this zone is linked to a single domain/origin. I would like this DNS server to be able to reply to queries for multiple domains/origin. But I do not want this server to maintain multiples zones, I want have only one. To be clearer, let's imagine the following scenario:

  • I have domain long.com
  • And I also have short.com
  • I want this DNS server to resolve vm1.long.com and vm1.short.com to the same A record

I understand the simplest thing would be to have one dnspython zone per domain/origin with the same A records in all of them. But a key functionality of this server is to check the health of servers behind the A records. If the zone is duplicated, then the checked servers will receive double the numbers of health requests. And the workload on the DNS server itself double too.

I could consider to create a DNS zone per domain as long as that would not imply to double the workload as described before.

So, in a nutshell, I want this DNS server to be able to reply to DNS queries for 2 or more domains/origins (with the same subdomains) without increasing the workload to validate the informed A records are still healthy


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits February 12, 2026 09:16
Co-authored-by: indisoluble <472832+indisoluble@users.noreply.github.com>
Co-authored-by: indisoluble <472832+indisoluble@users.noreply.github.com>
Co-authored-by: indisoluble <472832+indisoluble@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for multiple domains in DNS server Add multi-domain support via alias zones Feb 12, 2026
Copilot AI requested a review from indisoluble February 12, 2026 09:25
@codecov-commenter
Copy link

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@indisoluble
Copy link
Owner

@copilot I have pushed some changes over your first proposal, including a new class named ZoneOrigins. Analyze the aforementioned class carefully, I want you to integrate it (as is) in the project meaning:

  • DNS configuration factory must produce the config including, instead of a hosted zone + aliases, a single instance of ZoneOrigins
  • Then, UDP handler must use the relativize method in this new class to get a node and continue workflow as before

Once changes are applied, review tests and fox them accordingly, including adding new tests or removing those that are redundant, if necessary

- Replace origin_name and alias_zones in DnsServerConfig with zone_origins
- Update dns_server_config_factory to create ZoneOrigins instance
- Update dns_server_udp_handler to use ZoneOrigins.relativize() method
- Update dns_server_zone_updater to use zone_origins.primary
- Update main.py to pass zone_origins to server
- Update all tests to use zone_origins
- Remove redundant multi-domain test files

Co-authored-by: indisoluble <472832+indisoluble@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 15, 2026

@copilot I have pushed some changes over your first proposal, including a new class named ZoneOrigins. Analyze the aforementioned class carefully, I want you to integrate it (as is) in the project m...

Done in commit d8f52d0. The ZoneOrigins class has been fully integrated:

  • DnsServerConfig now uses zone_origins: ZoneOrigins instead of separate origin_name and alias_zones fields
  • Config factory creates ZoneOrigins via _make_zone_origins() which validates the primary zone and alias list
  • UDP handler uses zone_origins.relativize() to normalize query names from any configured zone
  • Zone updater accesses the primary origin via config.zone_origins.primary
  • Main.py passes zone_origins to the server

All 175 tests passing. The redundant multi-domain test files were removed since the functionality is now properly tested in test_zone_origins.py.

Copilot AI changed the title Add multi-domain support via alias zones Add multi-domain support via alias zones using ZoneOrigins class Feb 15, 2026
Copy link
Owner

@indisoluble indisoluble left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Address latest comments

- Remove unused _make_alias_zones function
- Remove docstring comment from _make_zone_origins
- Remove subdomain conflict validation (ZoneOrigins handles this)

Co-authored-by: indisoluble <472832+indisoluble@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 16, 2026

@copilot Address latest comments

All comments addressed in commit 1216b0f:

  • Removed unused _make_alias_zones() function
  • Removed docstring comment from _make_zone_origins()
  • Removed subdomain conflict validation code (handled by ZoneOrigins)

All 175 tests passing.

Copy link
Contributor Author

Copilot AI commented Feb 16, 2026

@copilot Address latest 2 comments in code

Both comments addressed in commit 7883209:

  • Removed the if alias_zones: check and logging message
  • Moved return statement to the end of the function

All 175 tests passing.

Copy link
Owner

@indisoluble indisoluble left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Address new set of comments

- Add __eq__ method for equality comparison based on primary and origins
- Add __hash__ method to allow use in sets and as dict keys
- Add __repr__ method for readable string representation
- Add 9 new tests for these methods
- Refactor test fixtures to use zone_origins.primary instead of separate origin_name
- Remove unused origin_name fixture from test_dns_server_zone_updater.py
- Remove unused mock_origin_name fixture from test_dns_server_zone_updater_threated.py
- Reorder mock_zone_origins before mock_zone in test_dns_server_udp_handler.py

Co-authored-by: indisoluble <472832+indisoluble@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 17, 2026

@copilot Address new set of comments

All comments addressed in commit 6a42800:

  • Added __eq__, __hash__, and __repr__ methods to ZoneOrigins with 9 new tests
  • Reordered and refactored fixtures in test_dns_server_udp_handler.py
  • Removed unused origin_name fixture from test_dns_server_zone_updater.py
  • Removed unused mock_origin_name fixture from test_dns_server_zone_updater_threated.py

All 184 tests passing.

@indisoluble indisoluble marked this pull request as ready for review February 21, 2026 19:32
@indisoluble indisoluble merged commit 13de8fd into master Feb 21, 2026
3 checks passed
@indisoluble indisoluble deleted the copilot/add-multi-domain-support branch February 21, 2026 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants