← Back to Pull requests

ServiceEntry: Promote configured WE annotations into workload labels #14198

Merged
ymesika merged 4 files (118 lines) on Jun 09, 2026 14:18 UTC
View on GitHub
ymesika ymesika commented on Jun 08, 2026 12:52 UTC
Author

<!--
Thanks for opening a PR! Please delete any sections that don’t apply.
-->

Description

<!--
A concise explanation of the change. You may include:

  • Motivation: why this change is needed

  • What changed: key implementation details

  • Related issues: e.g., Fixes #123

  • -->

    Add Options.PromoteWorkloadEntryAnnotations so callers can supply a set of WorkloadEntry annotation keys to copy verbatim into AugmentedLabels, letting endpoint plugins observe them.
    kgateway stays agnostic to the keys' meaning.

    Main reason not to include all annotations instead of configured ones:
    1. Annotation values aren't valid label values
    2. Collisions with meaningful labels
    3. Endpoint hash stability

    Change Type

    <!--
    Select one or more of the following by including the corresponding slash-command:

    /kind breaking_change
    /kind bump
    /kind cleanup
    /kind design
    /kind deprecation
    /kind documentation
    /kind feature
    /kind fix
    /kind flake
    /kind install
    

    -->
    /kind cleanup

    Changelog

    <!--
    Provide the exact line to appear in release notes for the chosen changelog type.

    If no, just write "NONE" in the release-note block below.
    If yes, a release note is required:
    -->

    ``release-note
    NONE
    ``

    (not a user facing change)

    Additional Notes

    <!--
    Any extra context or edge cases for reviewers.
    -->

    Diff: 118 lines (+118 / -0) across 4 files Reviewer: davidjumani Review duration: 1525m
    All Vouch review confidence checks passed
    Residual risk 0.09 = Change Risk (0.59) × (1 − Review Confidence (0.85)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.59 · 118 lines diff across 4 files
    0.59
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.78 · 3 substantive comment(s)
    0.78
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    84%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.286
    Sensitive Paths sensitive_paths
    0.059
    Real PR Conversation Timeline
    6 items
    Copilot Copilot commented on code on Jun 08, 2026 12:55 UTC
    Code Review
    pkg/kgateway/extensions2/plugins/serviceentry/collections.go:1
    @@ -275,6 +281,15 @@ func selectedWorkloadFromEntry(
     		labels = maps.MergeCopy(metadataLabels, labels)
     	}
     
    +	// Promote configured WorkloadEntry metadata annotations into the labels so that
    +	// endpoint plugins can observe them. This is an opaque string copy; kgateway is
    +	// agnostic to what the keys mean or how their values are interpreted.
    +	for key := range promoteAnnotationKeys {
    +		if v, ok := metadataAnnotations[key]; ok {
    +			labels[key] = v
    +		}
    +	}

    Promoted annotation keys can overwrite an existing label with the same key (from metadata or spec). That can unintentionally change selection/metadata behavior, and it contradicts the motivation of avoiding label collisions. Consider only promoting when the key is not already present in the merged label set (or explicitly document that promotion overrides labels).

    Copilot Copilot commented on code on Jun 08, 2026 12:55 UTC
    Code Review
    pkg/kgateway/extensions2/plugins/serviceentry/plugin.go:1
    @@ -42,6 +42,13 @@ type Options struct {
     	// Settings.WorkloadEntriesExclusionLabels is used. Use an empty set to explicitly disable
     	// exclusions.
     	WorkloadEntriesExclusionLabelKeys sets.Set[string]
    +
    +	// PromoteWorkloadEntryAnnotations is the set of WorkloadEntry annotation keys that, if present
    +	// on the WorkloadEntry's metadata, are copied verbatim into the workload's AugmentedLabels so
    +	// that endpoint plugins can observe them. kgateway is agnostic to what the keys mean; it does
    +	// an opaque string copy. Callers (e.g. downstream distributions) supply the keys they care
    +	// about. When nil or empty, no annotations are promoted.

    This option comment says promotion is for endpoint plugins, but the promoted keys are merged into AugmentedLabels which are also consumed by core logic (e.g. transport socket match metadata for Istio auto-mTLS). Please clarify the potential side-effects/collision risks so callers choose safe keys.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Jun 08, 2026 12:55 UTC
    Reviewer

    Pull request overview

    This PR adds an opt-in mechanism to copy a configured subset of WorkloadEntry metadata annotations into the derived workload’s AugmentedLabels, enabling endpoint plugins to observe those values while avoiding wholesale annotation propagation.

    Changes:

  • Introduces Options.PromoteWorkloadEntryAnnotations to configure which annotation keys to promote.

  • Threads the configured key set through ServiceEntry workload selection and applies promotion during WorkloadEntry → selectedWorkload conversion.

  • Adds unit coverage for the promotion behavior.
  • Reviewed changes

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

    | File | Description |
    | ---- | ----------- |
    | pkg/kgateway/extensions2/plugins/serviceentry/promote_annotations_test.go | Adds tests validating configured annotation promotion into AugmentedLabels. |
    | pkg/kgateway/extensions2/plugins/serviceentry/plugin.go | Adds the new Options.PromoteWorkloadEntryAnnotations option and documents intended behavior. |
    | pkg/kgateway/extensions2/plugins/serviceentry/endpoints.go | Updates inline endpoint conversion calls to the expanded selectedWorkloadFromEntry signature. |
    | pkg/kgateway/extensions2/plugins/serviceentry/collections.go | Wires the option through collections and performs the actual annotation-to-label promotion. |

    ymesika ymesika commented on code on Jun 08, 2026 12:58 UTC
    Code Review
    pkg/kgateway/extensions2/plugins/serviceentry/collections.go:1
    @@ -275,6 +281,15 @@ func selectedWorkloadFromEntry(
     		labels = maps.MergeCopy(metadataLabels, labels)
     	}
     
    +	// Promote configured WorkloadEntry metadata annotations into the labels so that
    +	// endpoint plugins can observe them. This is an opaque string copy; kgateway is
    +	// agnostic to what the keys mean or how their values are interpreted.
    +	for key := range promoteAnnotationKeys {
    +		if v, ok := metadataAnnotations[key]; ok {
    +			labels[key] = v
    +		}
    +	}

    It basically the responsibility of the plugin developer.
    Might also be the intention of the plugin to overwrite the label with a promoted annotation.

    davidjumani davidjumani approved these changes on Jun 09, 2026 13:33 UTC
    Approved Reviewer

    Approved these changes.

    Reviewers
    Assignees
    ymesika ymesika
    Labels
    risk: low confidence: 84.5% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 59.2% (MEDIUM) · Higher = larger blast radius
    59.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 84.5% · Lower = rushed or shallow review
    84.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 9.2% · Safe to merge
    9.2%