Skip to content

Preserve pod DNS options when translating ClusterFirst DNS - #4105

Open
Kunalbehbud wants to merge 1 commit into
loft-sh:mainfrom
Kunalbehbud:fix/pod-dns-options
Open

Kunalbehbud wants to merge 1 commit into
loft-sh:mainfrom
Kunalbehbud:fix/pod-dns-options

Conversation

@Kunalbehbud

@Kunalbehbud Kunalbehbud commented Jul 21, 2026

Copy link
Copy Markdown

What issue type does this pull request address? (keep at least one, remove the others)
/kind bugfix

What does this pull request do? Which issues does it resolve? (use resolves #<issue_number> if possible)
resolves #1120

When a pod uses ClusterFirst DNS, translateDNSClusterFirstConfig builds a DNS config (nameserver + search domains + an injected ndots=5) and then merges the pod's own config back in — but only its Nameservers and Searches:

existingDNSConfig := pPod.Spec.DNSConfig
if existingDNSConfig != nil {
    dnsConfig.Nameservers = deleteDuplicates(append(dnsConfig.Nameservers, existingDNSConfig.Nameservers...))
    dnsConfig.Searches = deleteDuplicates(append(dnsConfig.Searches, existingDNSConfig.Searches...))
}

Options was never merged, so anything a pod set in dnsConfig.options (e.g. single-request-reopen, or a custom ndots) was silently dropped — exactly what the issue reports.

This merges the options too, via a small mergeDNSOptions helper. An option set on the pod takes precedence over the injected default with the same name, so an explicit ndots: "2" replaces the injected ndots=5 rather than colliding with it; options the pod sets that aren't in the defaults are simply appended.

Please provide a short message that should be published in the vcluster release notes
Fixed an issue where vcluster dropped a pod's dnsConfig.options when translating ClusterFirst DNS.

What else do we need to know?

translateDNSClusterFirstConfig is a pure function over corev1.Pod, so this is covered by a table-driven unit test (TestTranslateDNSClusterFirstConfigOptions) with no cluster required: default kept when the pod sets nothing, pod options preserved alongside the default, and pod ndots overriding the injected one. The test fails on main and passes with this change.


Note

Low Risk
Small, localized pod DNS translation fix with table-driven unit tests and no auth or data-path changes.

Overview
Fixes a bug where virtual pods with ClusterFirst DNS lost dnsConfig.options on the host pod. translateDNSClusterFirstConfig already merged nameservers and search domains from the pod spec but ignored options, so settings like single-request-reopen or a custom ndots never reached the physical pod.

The merge path now calls mergeDNSOptions, which keeps injected defaults (including ndots=5) unless the pod defines the same option name—in which case the pod value wins. Other pod-only options are kept alongside the defaults.

TestTranslateDNSClusterFirstConfigOptions covers no existing config, extra pod options, and pod ndots overriding the default.

Reviewed by Cursor Bugbot for commit cc3b0ed. Bugbot is set up for automated code reviews on this repo. Configure here.

translateDNSClusterFirstConfig merged the pod's nameservers and
searches back into the generated DNS config but dropped its options,
so a pod setting dnsConfig.options silently lost them.

Merge the options too. An option set on the pod wins over the
injected default of the same name, so an explicit ndots replaces the
injected ndots=5 instead of being discarded.

Fixes loft-sh#1120

This branch has not been deployed

No deployments
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.

dnsOptions configuration on a pod does not work

1 participant