Enable protogetter in golangci config and update all protobuf field
access to use getter methods instead of direct field access.
Getter methods provide safer nil pointer handling and return
appropriate default values, following protobuf best practices.
Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
Enable intrange linter to enforce modern Go range syntax over
traditional for loops, by converting:
for i := 0; i < n; i++
to:
for i := range n
Adding type conversions where needed for compatibility
with existing uint64 parameters.
Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
Enable canonicalheader linter to enforce proper HTTP header casing.
This ensures headers use Go's canonical format (e.g., "Content-Type"
instead of "content-type") for consistency.
Fixes header casing in DoH implementation.
Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
Ensure Dial exits early or returns error when Transport has been
stopped, instead of blocking on the dial or ret channels. This removes
a potential goroutine leak where callers could pile up waiting
forever under heavy load.
Add select guards before send and receive, and propagate clear error
values so callers can handle shutdown gracefully.
Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
Add test suite covering thread-safe random number generator with
tests for:
- Constructor with various seed values (positive, zero, negative)
- Deterministic behavior verification with same seeds
- Permutation generation and validation
- Concurrent access safety with multiple goroutines
- Mixed operations under concurrent load
Also clarify package documentation to explicitly state this is
for load balancing and server selection, not cryptographic use.
The math/rand usage is intentional for performance in non-security
contexts like upstream server selection and DNS record shuffling.
Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
Enable copyloopvar linter and remove redundant variable
shadowing in Kubernetes plugin metadata handling. This pattern is
no longer needed in Go 1.22+ where loop variables are automatically
captured correctly in closures.
Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
Enable the usetesting linter in golangci.yml configuration to
enforce proper testing practices. Replace manual temporary
directory and file creation with t.TempDir() in test files.
This improves test reliability by ensuring proper cleanup and
follows Go testing best practices.
Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
Add conditional test skipping for bind and readme tests that rely on
Linux-specific loopback interface behavior. These tests reference
network configurations that may not exist on for e.g. macOS or other
platforms, causing spurious test failures.
Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
The rewrite plugin modifies DNS messages, affecting the request
size observed in the coredns_dns_request_size_bytes metric.
This change captures the original request size before any plugins
can modify it. It adds a functional options pattern to Report() to
pass this information while maintaining API compatibility.
Tests have been added to verify the fix prevents rewrite from
affecting the request size metrics.
Docs included.
Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
This fixes a bug introduced in
https://github.com/coredns/coredns/pull/6547 which resulted in the zone
being added to IPv4 addresses. This bug results in a failure to start
when binding to an interface with a link-local IPv4 address assigned to
it, with the following error:
$ ./coredns -conf=/etc/coredns/Corefile
maxprocs: Leaving GOMAXPROCS=4: CPU quota undefined
lookup 169.254.1.1%dummy0: no such host
Signed-off-by: Mark Mickan <mark.mickan@openlms.net>
Co-authored-by: Mark Mickan <mark.mickan@openlms.net>
* kubernetes: add multicluster support
Add multicluster support via Multi-Cluster Services API (MCS-API) via a
new option `multiclusterZones` in the kubernetes plugin.
When some multicluster zones are passed to the kubernetes plugin, it
will start watching the ServiceImport objects and its associated
EndpointSlices.
Signed-off-by: Arthur Outhenin-Chalandre <arthur@cri.epita.fr>
* kubernetes: implement xfr support for multicluster zones
Signed-off-by: Arthur Outhenin-Chalandre <arthur@cri.epita.fr>
---------
Signed-off-by: Arthur Outhenin-Chalandre <arthur@cri.epita.fr>
Don't explicitly set `RetryOnError` to `false`. It won't exist in the
next version of the k8s api and it won't make a difference in this code
since the struct would default to that.
Signed-off-by: Kevin Lyda <kevin@lyda.ie>
Forward information that a upstream response is truncated when rewriting
a CNAME. Otherwise, the cache plugin stores the truncated resonse,
making it impossible to receive the full response as a client via TCP.
Signed-off-by: Yannick Epstein <yannicke@spotify.com>
Use the functionality provided by the Go standard library slices package
since Go 1.21 instead of the deprecated functions in the
k8s.io/utils/strings/slices package.
Signed-off-by: Tobias Klauser <tobias@isovalent.com>
* add zone for link-local IPv6 instead of skipping
Signed-off-by: Till Riedel <riedel@teco.edu>
* revert changed error handling for IPs
Signed-off-by: Till Riedel <riedel@teco.edu>
---------
Signed-off-by: Till Riedel <riedel@teco.edu>