Skip to content

feat: Add record truncation and improve logging #29

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

thekoma
Copy link

@thekoma thekoma commented Jan 28, 2025

  • Add new flag --truncate-long-records to handle long record names
  • Implement record validation and truncation using SHA-256 hash
  • Enhance logging with emoji-based status indicators
  • Update Dockerfile to use Go 1.23
  • Update .dockerignore to exclude manifests directory
  • Improve error and configuration logging messages
  • added skaffold.yaml to simplify development

- Add new flag `--truncate-long-records` to handle long record names
- Implement record validation and truncation using SHA-256 hash
- Enhance logging with emoji-based status indicators
- Update Dockerfile to use Go 1.23
- Update .dockerignore to exclude manifests directory
- Improve error and configuration logging messages
@blake blake added the enhancement New feature or request label Feb 22, 2025
@blake blake self-requested a review February 22, 2025 09:53
Copy link
Owner

@blake blake left a comment

Choose a reason for hiding this comment

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

Thank you for the PR! This looks great.

Copy link
Author

@thekoma thekoma left a comment

Choose a reason for hiding this comment

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

LGTM!

@thekoma
Copy link
Author

thekoma commented Feb 22, 2025

Added requested changes

@thekoma thekoma removed their assignment Feb 22, 2025
@thekoma
Copy link
Author

thekoma commented Feb 22, 2025

@blake Cannot reassign back to you.

@blake blake self-assigned this Feb 23, 2025
@@ -216,6 +220,7 @@ func main() {
flag.BoolVar(&exposeIPv4, "expose-ipv4", lookupEnvOrBool("EXTERNAL_MDNS_EXPOSE_IPV4", exposeIPv4), "Publish A DNS entry (default: true)")
flag.BoolVar(&exposeIPv6, "expose-ipv6", lookupEnvOrBool("EXTERNAL_MDNS_EXPOSE_IPV6", exposeIPv6), "Publish AAAA DNS entry (default: false)")
flag.IntVar(&recordTTL, "record-ttl", lookupEnvOrInt("EXTERNAL_MDNS_RECORD_TTL", recordTTL), "DNS record time-to-live")
flag.BoolVar(&truncateLongRecords, "truncate-long-records", lookupEnvOrBool("EXTERNAL_MDNS_TRUNCATE_LONG_RECORDS", false), "Truncate long record names using SHA-256 hash (default: false)")
Copy link
Owner

Choose a reason for hiding this comment

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

@thekoma What do you think about enabling this by default given that the current behavior violates section 2.3.1 of RFC 1035, DOMAIN NAMES - IMPLEMENTATION AND SPECIFICATION.

@thekoma
Copy link
Author

thekoma commented Feb 24, 2025 via email

@blake
Copy link
Owner

blake commented Mar 2, 2025

@thekoma are you okay with me rebasing these changes onto master, resolving the merge conflicts, and force pushing the changes to your branch?

@thekoma
Copy link
Author

thekoma commented Mar 2, 2025

Sure Blake! Rebase it as you like!

// Verify each component
for _, component := range components {
if len(component) > 63 {
if truncate {
Copy link
Owner

Choose a reason for hiding this comment

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

@thekoma I was able to rebase these changes onto the master branch. I came to a few realizations in the process of testing things out.

First, it seems that truncating the namespace is unnecessary. In my cluster, Kubernetes version 1.28.15, the create namespace command errors if the namespace is longer than 63 characters.

kubectl create namespace TheQuickBrownFoxJumpsOverTheLazyDoggoDyzaLehTrevOspmuJxoFnworBkciuQehT
The Namespace "TheQuickBrownFoxJumpsOverTheLazyDoggoDyzaLehTrevOspmuJxoFnworBkciuQehT" is invalid:
* metadata.name: Invalid value: "TheQuickBrownFoxJumpsOverTheLazyDoggoDyzaLehTrevOspmuJxoFnworBkciuQehT": must be no more than 63 characters
* metadata.name: Invalid value: "TheQuickBrownFoxJumpsOverTheLazyDoggoDyzaLehTrevOspmuJxoFnworBkciuQehT": a lowercase RFC 1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name',  or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?')
* metadata.labels: Invalid value: "TheQuickBrownFoxJumpsOverTheLazyDoggoDyzaLehTrevOspmuJxoFnworBkciuQehT": must be no more than 63 characters

Second, if namespace truncation were needed, it might actually be a worse UX than just refusing to publish the record if the namespace is longer than 63 characters.

The reason is that truncating the namespace will result in the record being published under a completely different subdomain/namespace than where the service actually resides in the cluster. Unless the end-user has access to read the logs from external-mdns, it won't be obvious under what subdomain the record has been published.

The same UX issue applies to the service name if it too is longer than 63 chars.

Given that, I feel a better UX would be to remove the truncation feature and just leave the portion that logs the record is not being advertised since the name or namespace are longer than 63 characters. Users can instead use the new external-mdns.blakecovarrubias.com/hostnames annotation added in #22 to create a shorter service name in lieu of an automatically generated truncated service name.

What do you think about that?

Copy link
Author

Choose a reason for hiding this comment

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

The truncation is needed when you use the service-namespace instead the service.namespace format.
By design kubernetes uses dns discovery and pointers in CNI so it only makes sense that no truncation is ever necessary.

In my code I address exactly this situation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants