Skip to content

daemon/config: make DNSConfig.DNS a netip.Addr#50600

Merged
robmry merged 1 commit intomoby:masterfrom
thaJeztah:DNSConfig_netip
Aug 4, 2025
Merged

daemon/config: make DNSConfig.DNS a netip.Addr#50600
robmry merged 1 commit intomoby:masterfrom
thaJeztah:DNSConfig_netip

Conversation

@thaJeztah
Copy link
Member

@thaJeztah thaJeztah commented Aug 1, 2025

Modernize the field and allow using it as-is in some places, or convert it to a string (which won't produce an error down the line).

- Human readable description for the release notes

daemon: improve validation of the `--dns` option and corresponding `"dns"` field in `daemon.json`.

- A picture of a cute animal (not mandatory but encouraged)

Modernize the field and allow using it as-is in some places, or
convert it to a string (which won't produce an error down the line).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah added this to the 29.0.0 milestone Aug 1, 2025
@thaJeztah thaJeztah added status/2-code-review area/daemon Core Engine kind/refactor PR's that refactor, or clean-up code labels Aug 1, 2025
doc: "single DNS, invalid IP-address",
input: `{"dns": ["1.1.1.1o"]}`,
expectedErr: `invalid IP address: 1.1.1.1o`,
expectedErr: `ParseAddr("1.1.1.1o"): unexpected character (at "o")`,
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the only downside; I dislike the errors produced by stdlib. In this case, the error is not exported, so it's not possible to dismantle it (i.e., do an errors.As and cherry-pick the bits that are useful to produce a user-friendly error); https://github.com/golang/go/blob/e666972a674eb96f5847c7bbeb5c6e1bcb572af5/src/net/netip/netip.go#L141-L153

type parseAddrError struct {
	in  string // the string given to ParseAddr
	msg string // an explanation of the parse failure
	at  string // optionally, the unparsed portion of in at which the error occurred.
}

func (err parseAddrError) Error() string {
	q := strconv.Quote
	if err.at != "" {
		return "ParseAddr(" + q(err.in) + "): " + err.msg + " (at " + q(err.at) + ")"
	}
	return "ParseAddr(" + q(err.in) + "): " + err.msg
}

Comment on lines -65 to +70
sboxOptions = append(sboxOptions, libnetwork.OptionDNS(ctr.HostConfig.DNS))
dnsAddrs, err := toNetIP(ctr.HostConfig.DNS)
Copy link
Member Author

Choose a reason for hiding this comment

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

Would be great if we could change HostConfig.DNS as well, but it's part of the API, so much harder to change.

@thaJeztah thaJeztah added kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. impact/changelog labels Aug 1, 2025
@thaJeztah thaJeztah marked this pull request as ready for review August 1, 2025 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/daemon Core Engine impact/changelog kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. kind/refactor PR's that refactor, or clean-up code status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants