Skip to content

fix: add ownership check before deleting PodMonitor#9340

Merged
mnencia merged 3 commits intocloudnative-pg:mainfrom
juliamertz:fix/podmonitor-deletion
Jan 15, 2026
Merged

fix: add ownership check before deleting PodMonitor#9340
mnencia merged 3 commits intocloudnative-pg:mainfrom
juliamertz:fix/podmonitor-deletion

Conversation

@juliamertz
Copy link
Contributor

@juliamertz juliamertz commented Dec 1, 2025

The operator was incorrectly deleting manually-created PodMonitors that shared the same name and namespace as the cluster, even when they were not owned by the cluster.

This fix adds an ownership check before deleting PodMonitors when monitoring is disabled, ensuring only operator-managed PodMonitors are deleted.

Closes #6109

@juliamertz juliamertz requested a review from a team as a code owner December 1, 2025 09:49
@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Dec 1, 2025
@cnpg-bot cnpg-bot added backport-requested ◀️ This pull request should be backported to all supported releases release-1.25 release-1.26 release-1.27 labels Dec 1, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Dec 1, 2025

❗ By default, the pull request is configured to backport to all release branches.

  • To stop backporting this pr, remove the label: backport-requested ◀️ or add the label 'do not backport'
  • To stop backporting this pr to a certain release branch, remove the specific branch label: release-x.y

Signed-off-by: Julia Mertz <info@juliamertz.dev>
@mnencia mnencia force-pushed the fix/podmonitor-deletion branch from b0e9b8f to b5e96ea Compare January 15, 2026 09:39
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Jan 15, 2026
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jan 15, 2026
Verify that unowned PodMonitors are not deleted when monitoring is
disabled, and that owned PodMonitors are correctly deleted.

Update existing test to properly set cluster ownership on the
PodMonitor being tested.

Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
@mnencia mnencia force-pushed the fix/podmonitor-deletion branch from 3ee1106 to 7767eea Compare January 15, 2026 11:06
@mnencia mnencia changed the title fix: only delete podmonitor if owned by cluster fix: add ownership check before deleting PodMonitor Jan 15, 2026
Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
@armru armru force-pushed the fix/podmonitor-deletion branch from 82e78ce to ed649ac Compare January 15, 2026 11:39
@mnencia mnencia merged commit 694b3b9 into cloudnative-pg:main Jan 15, 2026
32 checks passed
cnpg-bot pushed a commit that referenced this pull request Jan 15, 2026
The operator was incorrectly deleting manually-created PodMonitors that
shared the same name and namespace as the cluster, even when they were
not owned by the cluster.

This fix adds an ownership check before deleting PodMonitors when
monitoring is disabled, ensuring only operator-managed PodMonitors are
deleted.

Closes #6109

Signed-off-by: Julia Mertz <info@juliamertz.dev>
Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
Co-authored-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
Co-authored-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
(cherry picked from commit 694b3b9)
cnpg-bot pushed a commit that referenced this pull request Jan 15, 2026
The operator was incorrectly deleting manually-created PodMonitors that
shared the same name and namespace as the cluster, even when they were
not owned by the cluster.

This fix adds an ownership check before deleting PodMonitors when
monitoring is disabled, ensuring only operator-managed PodMonitors are
deleted.

Closes #6109

Signed-off-by: Julia Mertz <info@juliamertz.dev>
Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
Co-authored-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
Co-authored-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
(cherry picked from commit 694b3b9)
cnpg-bot pushed a commit that referenced this pull request Jan 15, 2026
The operator was incorrectly deleting manually-created PodMonitors that
shared the same name and namespace as the cluster, even when they were
not owned by the cluster.

This fix adds an ownership check before deleting PodMonitors when
monitoring is disabled, ensuring only operator-managed PodMonitors are
deleted.

Closes #6109

Signed-off-by: Julia Mertz <info@juliamertz.dev>
Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
Co-authored-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
Co-authored-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
(cherry picked from commit 694b3b9)
mnencia added a commit that referenced this pull request Jan 20, 2026
The operator was incorrectly deleting manually-created PodMonitors that
shared the same name and namespace as the cluster, even when they were
not owned by the cluster.

This fix adds an ownership check before deleting PodMonitors when
monitoring is disabled, ensuring only operator-managed PodMonitors are
deleted.

Closes #6109

Signed-off-by: Julia Mertz <info@juliamertz.dev>
Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
Co-authored-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
Co-authored-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
(cherry picked from commit 694b3b9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-requested ◀️ This pull request should be backported to all supported releases bug 🐛 Something isn't working lgtm This PR has been approved by a maintainer ok to merge 👌 This PR can be merged release-1.25 release-1.27 release-1.28 size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Operator deletes PodMonitor that it didn't create due to lack of owner reference check

5 participants