Skip to content

evaluator: deduplicate namespace selector matching via shared helper#2

Merged
zemanlx merged 2 commits into
feat/namespace-selector-supportfrom
copilot/sub-pr-1
Feb 19, 2026
Merged

evaluator: deduplicate namespace selector matching via shared helper#2
zemanlx merged 2 commits into
feat/namespace-selector-supportfrom
copilot/sub-pr-1

Conversation

Copilot AI commented Feb 19, 2026

Copy link
Copy Markdown

matchesNamespaceSelector and matchesNamespaceSelectorV1Beta1 had identical implementations differing only in the binding type, risking silent divergence.

Changes

  • New helper matchesNamespaceSelectorByLabelSelector(*metav1.LabelSelector, *unstructured.Unstructured) (bool, error) — package-level function containing the shared selector evaluation logic
  • Refactored wrappers — both original methods now only nil-check their binding/matchResources before delegating to the helper
func matchesNamespaceSelectorByLabelSelector(
    labelSelector *metav1.LabelSelector,
    namespaceObj *unstructured.Unstructured,
) (bool, error) { ... }

func (e *Evaluator) matchesNamespaceSelector(
    binding *admissionregv1.ValidatingAdmissionPolicyBinding, ...
) (bool, error) {
    if binding == nil || binding.Spec.MatchResources == nil {
        return true, nil
    }
    return matchesNamespaceSelectorByLabelSelector(binding.Spec.MatchResources.NamespaceSelector, namespaceObj)
}

func (e *Evaluator) matchesNamespaceSelectorV1Beta1(
    binding *admissionv1beta1.MutatingAdmissionPolicyBinding, ...
) (bool, error) {
    if binding == nil || binding.Spec.MatchResources == nil {
        return true, nil
    }
    return matchesNamespaceSelectorByLabelSelector(binding.Spec.MatchResources.NamespaceSelector, namespaceObj)
}

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: zemanlx <18702153+zemanlx@users.noreply.github.com>
Copilot AI changed the title [WIP] WIP address feedback on evaluator implementation and tests updates evaluator: deduplicate namespace selector matching via shared helper Feb 19, 2026
Copilot AI requested a review from zemanlx February 19, 2026 14:31
@zemanlx zemanlx marked this pull request as ready for review February 19, 2026 14:49
@zemanlx zemanlx merged commit 7a6d58f into feat/namespace-selector-support Feb 19, 2026
@zemanlx zemanlx deleted the copilot/sub-pr-1 branch February 19, 2026 14:49
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.

2 participants