Skip to content

feat: Add wildcard DNS support for DNSEndpoint resources#107

Open
angelbarrera92 wants to merge 1 commit into
k8gb-io:mainfrom
angelbarrera92:issue-106
Open

feat: Add wildcard DNS support for DNSEndpoint resources#107
angelbarrera92 wants to merge 1 commit into
k8gb-io:mainfrom
angelbarrera92:issue-106

Conversation

@angelbarrera92

Copy link
Copy Markdown

Fixes #106

Description

This PR implements wildcard DNS support for DNSEndpoint resources, enabling the CoreDNS CRD plugin to resolve queries using wildcard patterns (e.g., *.example.com).

Previously, the plugin only performed exact hostname matching. With this change, DNSEndpoint resources can now define wildcard patterns that match single-level subdomains, following standard DNS wildcard behavior as defined in RFC 4592.

Changes Made

Core Functionality (common/k8sctrl/ctrl.go)

  • Added matchesWildcard() function to implement wildcard pattern matching logic
  • Modified getEndpointsByCaseInsensitiveName() to support both exact and wildcard matches
  • Implemented precedence logic: exact matches take priority over wildcard matches
  • Updated margeLocalDNSEndpoints() to properly handle nil labels

Testing (common/k8sctrl/ctrl_test.go)

  • Added comprehensive unit tests for matchesWildcard() function (11 test cases)
  • Added integration tests for wildcard DNS endpoint resolution
  • Added test to verify exact match precedence over wildcards
  • All existing tests continue to pass

Documentation (terratest/example/dnsendpoint_wildcard.yaml)

  • Created example YAML demonstrating wildcard DNS usage

Wildcard Behavior

Following standard DNS wildcard rules:

  • *.example.com matches test.example.com
  • *.example.com matches app.example.com
  • *.example.com does NOT match example.com (apex domain)
  • *.example.com does NOT match sub.test.example.com (multi-level subdomain)
  • ✅ Case-insensitive matching is preserved
  • ✅ Exact matches take precedence over wildcard matches

Example Usage

apiVersion: externaldns.k8s.io/v1alpha1
kind: DNSEndpoint
metadata:
  name: wildcard-apps
  labels:
    k8gb.absa.oss/dnstype: local
spec:
  endpoints:
  - dnsName: "*.apps.example.com"
    recordType: A
    targets:
    - 192.168.1.100
    - 192.168.1.101

Now queries for app1.apps.example.com, app2.apps.example.com, etc. will all resolve to the specified targets.

Testing

All tests pass:

go test ./... -short

Specific wildcard tests:

go test ./common/k8sctrl/... -v -run TestWildcard
go test ./common/k8sctrl/... -v -run TestMatchesWildcard

Breaking Changes

None. This is a backwards-compatible feature addition. Existing DNSEndpoint resources with exact hostnames continue to work exactly as before.

Additional Notes

  • Wildcard matching follows DNS standards (RFC 4592)
  • The implementation is efficient and doesn't impact exact match performance
  • Works seamlessly with existing features (GeoIP, round-robin, etc.)

Implements wildcard DNS pattern matching (e.g., *.example.com) to resolve
queries for single-level subdomains, following RFC 4592 standards.

Key changes:
- Add matchesWildcard() function for pattern matching logic
- Update getEndpointsByCaseInsensitiveName() to support wildcards
- Ensure exact matches take precedence over wildcard matches
- Add comprehensive test coverage (11 unit tests + integration tests)
- Include example YAML for wildcard DNS usage

Wildcard behavior:
- *.example.com matches test.example.com ✓
- *.example.com does NOT match example.com (apex) ✗
- *.example.com does NOT match sub.test.example.com ✗
- Case-insensitive matching preserved
- Backwards compatible with existing exact matches

Fixes k8gb-io#106

Signed-off-by: Barrera, Angel <Angel.Barrera@adidas.com>
@ytsarev

ytsarev commented Jan 17, 2026

Copy link
Copy Markdown
Member

@angelbarrera92 thanks for the contribution! Have you tested this change end-to-end?

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.

Wildcard DNS Support for DNSEndpoint Resources

2 participants