Skip to content

Fix PDB label selectors - #764

Open
pbenas wants to merge 1 commit into
open-policy-agent:masterfrom
pbenas:fix-pdb-label-selector
Open

Fix PDB label selectors#764
pbenas wants to merge 1 commit into
open-policy-agent:masterfrom
pbenas:fix-pdb-label-selector

Conversation

@pbenas

@pbenas pbenas commented Jun 23, 2026

Copy link
Copy Markdown

What this PR does / why we need it:
The actual matching between PDB and deployment is based on the pod template labels (spec.template.metadata.labels) rather than on the configured label selector (.spec.slector.matchLabels). The template can have more labels than the matchLabel selects on and PDB would still apply in such a case.

Which issue(s) does this PR fix:
fixes #755

Special notes for your reviewer:
Disclaimer: This is my first contribution to upstream gatekeeper library.

@pbenas
pbenas requested a review from a team as a code owner June 23, 2026 11:19
Copilot Bot review requested due to automatic review settings June 23, 2026 11:19
@pbenas
pbenas force-pushed the fix-pdb-label-selector branch from dce4110 to 362313c Compare June 23, 2026 11:20
@pbenas
pbenas marked this pull request as draft June 23, 2026 11:22
@pbenas
pbenas marked this pull request as ready for review June 23, 2026 11:22

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 the poddisruptionbudget validation policy so that matching between a PodDisruptionBudget and a workload is based on the workload’s pod template labels (spec.template.metadata.labels) rather than the workload selector’s matchLabels, which aligns with how PDB selectors actually target pods.

Changes:

  • Updated the Rego policy logic to compare PDB selector matchLabels against workload pod template labels.
  • Updated the website documentation snippet to reflect the corrected matching logic.
  • Updated generated ConstraintTemplate artifacts (library + ArtifactHub) and adjusted unit test inputs.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
website/docs/validation/poddisruptionbudget.md Updates the documented Rego snippet to use pod template labels for matching.
src/general/poddisruptionbudget/src.rego Fixes the core matching logic to use spec.template.metadata.labels.
src/general/poddisruptionbudget/src_test.rego Updates test inputs for the new label source (and is the right place to add a regression test for the specific bug scenario).
library/general/poddisruptionbudget/template.yaml Regenerates the published template with the corrected Rego logic.
artifacthub/library/general/poddisruptionbudget/1.0.4/template.yaml Updates the ArtifactHub-published template with the corrected Rego logic.
artifacthub/library/general/poddisruptionbudget/1.0.4/artifacthub-pkg.yml Updates the ArtifactHub digest to reflect the template content change.

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

Comment thread src/general/poddisruptionbudget/src.rego
Comment thread src/general/poddisruptionbudget/src_test.rego
@pbenas
pbenas force-pushed the fix-pdb-label-selector branch from ca561fc to c16fbc7 Compare June 23, 2026 11:59
The actual matching between PDB and deployment is based on the pod template
labels (`spec.template.metadata.labels`) rather than on the configured label
selector (`.spec.slector.matchLabels`). The template can have more labels than
the matchLabel selects on and PDB would still apply in such a case.

fixes open-policy-agent#755

Signed-off-by: Petr Benas <petrbenas@gmail.com>
@pbenas
pbenas force-pushed the fix-pdb-label-selector branch from c16fbc7 to eac8625 Compare June 29, 2026 08:02
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.

PDB example should check labels of pods for evaluation

1 participant