Skip to content

fix: default the server port when it is not set - #289

Merged
hagaibarel merged 1 commit into
coredns:masterfrom
lbarrosby:fix/default-server-port
Nov 6, 2026
Merged

hagaibarel merged 1 commit into
coredns:masterfrom
lbarrosby:fix/default-server-port

Conversation

@lbarrosby

Copy link
Copy Markdown
Contributor

Why is this pull request needed and what does it do?

port is optional on a server block (the configmap already handles it, and CoreDNS picks the default for the scheme), but the port helpers call toString .port unconditionally. Without a port the chart renders:

ports:
- {"name":"udp-<nil>","port":null,"protocol":"UDP","targetPort":0}
...
- {"containerPort":0,"name":"udp-<nil>","protocol":"UDP"}

which the API server rejects. This adds a small coredns.serverPort helper that returns .port when set, otherwise the CoreDNS default for the first zone's scheme (53, 853 for tls:///quic://, 443 for grpc:///https://), and uses it in both coredns.servicePorts and coredns.containerPorts. servicePort still overrides the Service port.

Rendering with the default values is byte for byte the same as before. Added unit tests for the Service and the Deployment with port-less server blocks (they fail without the fix), and updated the port comment in values.yaml.

Which issues (if any) are related?

Fixes #67

Checklist:

  • I have bumped the chart version according to versioning.
  • I have updated the chart changelog with all the changes that come with this pull request according to changelog.
  • Any new values are backwards compatible and/or have sensible default.
  • I have signed off all my commits as required by DCO.

Changes are automatically published when merged to main. They are not published on branches.

Note on DCO

If the DCO action in the integration test fails, one or more of your commits are not signed off. Please click on the Details link next to the DCO action for instructions on how to resolve this.

A server block without a port rendered Service and container ports as
null (udp-<nil>), which the API server rejects. Fall back to the port
CoreDNS itself uses for the zone scheme.

Fixes coredns#67

Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
@hagaibarel
hagaibarel merged commit 3254faf into coredns:master Nov 6, 2026
2 checks passed
@hagaibarel

Copy link
Copy Markdown
Collaborator

Thanks for the PR!

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.

coredns.containerPorts template helper does not properly handle missing ports

2 participants