Use client-go / apimachinery label selector utilities instead of custom label matching helpers in the PDB controller. #91
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Use
client-go/ apimachinery label selector utilities instead of custom label matching helpers in the PDB controller.Fixes #8.
Background / Motivation
The controller previously implemented its own label matching helpers (
containLabels,labelsIntersect) to:heritage: pdb-controller).getMatchedPDBs).Kubernetes already provides robust label selector types and matching logic via
client-go/k8s.io/apimachinery, so this PR replaces our ad‑hoc implementations with those built‑in utilities. This reduces duplicated logic and keeps behavior consistent with other Kubernetes components.What this PR changes
Replace custom intersection logic in
getMatchedPDBsgetMatchedPDBsrelied on a customlabelsIntersectfunction comparing twomap[string]string.Spec.Selector(*metav1.LabelSelector) usingmetav1.LabelSelectorAsSelector.labels.Set.selector.Matches(labels.Set(resourceLabels))to decide whether the PDB matches the workload.Use label selectors to find managed PDBs
filterPDBsusedcontainLabels(pdb.Labels, ownerLabels)to decide whether a PDB is managed.filterPDBsuseslabels.SelectorFromSet(ownerLabels).Matches(labels.Set(pdb.Labels)), delegating the match semantics to apimachinery.Remove custom helpers that duplicate selector behavior
labelsIntersectand the custom subset logic incontainLabelsare no longer used for controller behavior.Tests
controller_test.gocontinue to exercise:Behavior notes
LabelSelectorform (we already useMatchLabels, but this prepares us for more complex selectors).LabelSelectorwill be safely skipped (logged and ignored) rather than leading to undefined behavior.ownerLabels(heritage: pdb-controller); only the implementation is switched to selectors.