Skip to content

K8SPSMDB-1608 remove stale external-dns annotations when expose.externalDNS changes#2440

Open
nmarukovich wants to merge 4 commits into
mainfrom
K8SPSMDB-1608_fix
Open

K8SPSMDB-1608 remove stale external-dns annotations when expose.externalDNS changes#2440
nmarukovich wants to merge 4 commits into
mainfrom
K8SPSMDB-1608_fix

Conversation

@nmarukovich

@nmarukovich nmarukovich commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

CHANGE DESCRIPTION

Problem:
expose.externalDNS (added in #2280) writes external-dns.alpha.kubernetes.io/hostname
and /ttl annotations to per-pod Services, but never removes them. When a user removes
or edits externalDNS in the CR, the old annotations stay on the Service (merge-only
update path when no user annotations are set), so external-dns keeps live DNS records
for a feature that was turned off.

Cause:
Short explanation of the root cause of the issue if applicable.

Solution:
The operator now marks Services it manages with percona.com/external-dns-managed and,
on update, removes its own external-dns annotations that are no longer in the desired
state. Annotations added manually by the user (without the marker) are left untouched.

CHECKLIST

Jira

  • Is the Jira ticket created and referenced properly?
  • Does the Jira ticket have the proper statuses for documentation (Needs Doc) and QA (Needs QA)?
  • Does the Jira ticket link to the proper milestone (Fix Version field)?

Tests

  • Is an E2E test/test case added for the new feature/change?
  • Are unit tests added where appropriate?
  • Are OpenShift compare files changed for E2E tests (compare/*-oc.yml)?

Config/Logging/Testability

  • Are all needed new/changed options added to default YAML files?
  • Are all needed new/changed options added to the Helm Chart?
  • Did we add proper logging messages for operator actions?
  • Did we ensure compatibility with the previous version or cluster upgrade process?
  • Does the change support oldest and newest supported MongoDB version?
  • Does the change support oldest and newest supported Kubernetes version?

@pull-request-size pull-request-size Bot added the size/L 100-499 lines label Jul 7, 2026
@github-actions github-actions Bot added the tests label Jul 7, 2026
@nmarukovich nmarukovich changed the title K8SPSMDB-1608 fix K8SPSMDB-1608 remove stale external-dns annotations when expose.externalDNS changes Jul 8, 2026
@nmarukovich

Copy link
Copy Markdown
Contributor Author

@copilot

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a long-standing reconciliation issue where expose.externalDNS annotations on per-pod Services were only ever added/merged, but not removed when externalDNS was edited or removed from the CR—leaving ExternalDNS-managed DNS records active after the feature was effectively disabled.

Changes:

  • Introduces a Percona marker annotation (percona.com/external-dns-managed) and uses it to identify operator-managed ExternalDNS annotations.
  • Updates the Service reconciliation merge path to delete stale operator-managed external-dns annotations (hostname/ttl/marker) that are no longer desired.
  • Adds/updates unit tests and introduces an external-dns E2E test scenario, wiring it into PR/release test runs.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/psmdb/service.go Switches ExternalDNS annotation keys to naming constants and adds the managed marker annotation to per-pod replset Services.
pkg/psmdb/service_test.go Updates expected annotations for replset per-pod Services to include the managed marker.
pkg/psmdb/mongos.go Switches ExternalDNS annotation keys to naming constants and adds the managed marker annotation to mongos Services.
pkg/psmdb/mongos_test.go Adds test coverage validating mongos ExternalDNS annotations (single service vs service-per-pod, ttl, marker).
pkg/naming/annotations.go Centralizes ExternalDNS-related annotation keys in pkg/naming.
pkg/controller/perconaservermongodb/psmdb_controller.go Implements and invokes stale ExternalDNS annotation cleanup during Service updates when preserving old metadata.
pkg/controller/perconaservermongodb/service_test.go Adds unit tests for stale ExternalDNS annotation removal behavior.
e2e-tests/run-release.csv Adds the new external-dns E2E test to the release test suite.
e2e-tests/run-pr.csv Adds the new external-dns E2E test to the PR test suite.
e2e-tests/external-dns/run New E2E test validating annotation creation, ttl removal, externalDNS removal cleanup, and manual annotation preservation.
e2e-tests/external-dns/conf/external-dns.yml New sharded cluster manifest used by the external-dns E2E test.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"external-dns.alpha.kubernetes.io/ttl": "60",
},
},
"externalDNS enabled over manual annotations: operator takes ownership": {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L 100-499 lines tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants