fix(mlbs): migrate AffinityTags to use pod labels when inbound tags are disabled#16030
fix(mlbs): migrate AffinityTags to use pod labels when inbound tags are disabled#16030mail2sudheerobbu-oss wants to merge 32 commits intokumahq:masterfrom
Conversation
Signed-off-by: mail2sudheerobbu-oss <mail2sudheerobbu@gmail.com>
…r pod label support Signed-off-by: mail2sudheerobbu-oss <mail2sudheerobbu@gmail.com>
… in lb metadata Signed-off-by: mail2sudheerobbu-oss <mail2sudheerobbu@gmail.com>
Signed-off-by: mail2sudheerobbu-oss <mail2sudheerobbu@gmail.com>
…to labels in affinity matching Signed-off-by: mail2sudheerobbu-oss <mail2sudheerobbu@gmail.com>
…o labels for AffinityTags Signed-off-by: mail2sudheerobbu-oss <mail2sudheerobbu@gmail.com>
…urer to NewEndpoints Signed-off-by: mail2sudheerobbu-oss <mail2sudheerobbu@gmail.com>
Reviewer Checklist🔍 Each of these sections need to be checked by the reviewer of the PR 🔍:
|
There was a problem hiding this comment.
Pull request overview
This PR fixes MeshLoadBalancingStrategy.LocalityAwareness.LocalZone.AffinityTags when KUMA_EXPERIMENTAL_INBOUND_TAGS_DISABLED=true by propagating pod/workload labels through the endpoint pipeline and using them as a fallback signal when inbound tags are missing.
Changes:
- Extend
core_xds.Endpointto carryLabels, populate them from resource metadata, and serialize them into Envoy endpoint filter metadata. - Update locality-aware logic to extract labels from endpoint metadata and fall back to labels when inbound tags are absent.
- Thread local pod labels through the MLBS plugin’s CLA configurers so local locality-group resolution can fall back to labels.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/core/xds/types.go | Adds Endpoint.Labels field to carry workload labels through xDS routing structures. |
| pkg/xds/topology/outbound.go | Populates Endpoint.Labels from dataplane/DPP resource metadata labels when building outbound endpoints. |
| pkg/xds/envoy/metadata/v3/metadata.go | Introduces io.kuma.labels metadata key, plus helpers to write/read labels in endpoint filter metadata. |
| pkg/xds/envoy/endpoints/v3/endpoints.go | Switches endpoint metadata generation to include labels (via EndpointMetadataWithLabels). |
| pkg/plugins/policies/meshloadbalancingstrategy/plugin/v1alpha1/locality_aware.go | Extracts labels from endpoint metadata and uses them as a fallback for local-zone affinity matching. |
| pkg/plugins/policies/meshloadbalancingstrategy/plugin/v1alpha1/priority.go | Adds local pod-label fallback when deriving locality groups from affinity tag keys. |
| pkg/plugins/policies/meshloadbalancingstrategy/plugin/v1alpha1/plugin.go | Threads podLabels through configurer call sites (DPP/gateway; nil for egress). |
pkg/plugins/policies/meshloadbalancingstrategy/plugin/v1alpha1/priority.go
Outdated
Show resolved
Hide resolved
…safety to ExtractLbLabels Signed-off-by: mail2sudheerobbu-oss <mail2sudheerobbu@gmail.com>
Signed-off-by: mail2sudheerobbu-oss <mail2sudheerobbu@gmail.com>
…ractLbLabels Signed-off-by: mail2sudheerobbu-oss <mail2sudheerobbu@gmail.com>
…en inbound tags disabled Signed-off-by: mail2sudheerobbu-oss <mail2sudheerobbu@gmail.com>
|
Hey @Automaat @bartsmykla — could you take a look at this PR when you get a chance? The branch is up to date with |
pkg/plugins/policies/meshloadbalancingstrategy/plugin/v1alpha1/priority.go
Outdated
Show resolved
Hide resolved
pkg/plugins/policies/meshloadbalancingstrategy/plugin/v1alpha1/priority_test.go
Show resolved
Hide resolved
pkg/plugins/policies/meshloadbalancingstrategy/plugin/v1alpha1/priority.go
Show resolved
Hide resolved
|
Thanks @Automaat for the thorough review! All five points are well-taken. Here's how I'll address each: 1. Filter pod labels to AffinityTag-referenced keys only — Agree, serializing all pod labels is wasteful. I'll thread the active AffinityTag keys down into 2. Add debug logging on label fallback — Will add a 3. Fix 4. Consolidate fallback logic into 5. Golden-file integration test for the full pipeline — Will add a golden-file test that wires InboundTagsDisabled=true through the full chain: endpoint with labels → xDS metadata serialization → MLBS locality grouping. This validates the entire contract in one place. I'll push a follow-up commit addressing items 1–4 (code changes) and then item 5 (golden test) separately for easier review. |
… absent Refactor ExtractLbLabels to return nil for nil metadata and structVal. Signed-off-by: mail2sudheerobbu-oss <mail2sudheerobbu@gmail.com>
…tag/label fallback in priority.go Refactor affinity value resolution to use a dedicated function. Signed-off-by: mail2sudheerobbu-oss <mail2sudheerobbu@gmail.com>
…stent tag/label lookup Refactor locality-aware endpoint configuration to use a helper function for resolving affinity values from tags and labels. Signed-off-by: mail2sudheerobbu-oss <mail2sudheerobbu@gmail.com>
…in priority.go Add logging for missing affinity tags fallback to pod labels. Signed-off-by: mail2sudheerobbu-oss <mail2sudheerobbu@gmail.com>
…ates in locality_aware.go Signed-off-by: mail2sudheerobbu-oss <mail2sudheerobbu@gmail.com>
…priority.go Add affinityTagPodLabels function to filter pod labels based on AffinityTags configuration. Signed-off-by: mail2sudheerobbu-oss <mail2sudheerobbu@gmail.com>
…n locality_aware.go Add pod labels based on configuration for locality-aware balancing. Signed-off-by: mail2sudheerobbu-oss <mail2sudheerobbu@gmail.com>
Added a new test case for locality-aware inbound tags disabled scenario, including multiple backend and payment resources with specific configurations and policies. Signed-off-by: mail2sudheerobbu-oss <mail2sudheerobbu@gmail.com>
Add listeners for backend and payments services with appropriate configurations. Signed-off-by: mail2sudheerobbu-oss <mail2sudheerobbu@gmail.com>
Signed-off-by: mail2sudheerobbu-oss <mail2sudheerobbu@gmail.com>
Signed-off-by: mail2sudheerobbu-oss <mail2sudheerobbu@gmail.com>
Add comments to clarify label filtering process. Signed-off-by: mail2sudheerobbu-oss <mail2sudheerobbu@gmail.com>
|
Hi @Automaat @bartsmykla — all 5 of your review comments have now been fully addressed:
The branch is up to date with |
Motivation
When
KUMA_EXPERIMENTAL_INBOUND_TAGS_DISABLED=trueis set, Kuma strips inbound tags from Dataplane resources to reduce memory overhead. However,MeshLoadBalancingStrategy.LocalityAwareness.LocalZone.AffinityTagsrelies on inbound tags to group and route traffic. This means that when inbound tags are disabled:This results in locality-aware load balancing via
AffinityTagssilently failing whenKUMA_EXPERIMENTAL_INBOUND_TAGS_DISABLEDis enabled.Pod labels, however, are always available from Kubernetes pod metadata regardless of this flag. This PR migrates
AffinityTagshandling to fall back to pod labels when inbound tags are absent.Closes #15995
Implementation information
The fix spans the full data pipeline from endpoint construction through to locality group resolution:
pkg/core/xds/types.go— Added aLabels map[string]stringfield to theEndpointstruct to carry pod/workload labels alongside inbound tags throughout the routing pipeline.pkg/xds/envoy/metadata/v3/metadata.go— Added a newLbLabelsKeyconstant ("io.kuma.labels"), aEndpointMetadataWithLabelsfunction that stores both inbound tags (underenvoy.lb) and pod labels (underio.kuma.labels) in Envoy filter metadata, and anExtractLbLabelsfunction to retrieve pod labels from metadata.pkg/xds/envoy/endpoints/v3/endpoints.go— UpdatedToLocalityLbEndpointsto callEndpointMetadataWithLabelsinstead ofEndpointMetadata, so pod labels are embedded in each endpoint's Envoy filter metadata.pkg/xds/topology/outbound.go— Populated the newLabelsfield infillDataplaneOutboundsandfillLocalMeshServicesfromGetMeta().GetLabels()on the respective Dataplane/DPP resource.pkg/plugins/policies/meshloadbalancingstrategy/plugin/v1alpha1/locality_aware.go— Extracted pod labels from endpoint filter metadata increateEndpoint, and added a label-based fallback inconfigureLocalZoneEndpointLocalitywhen the tag key is not found inendpoint.Tags.pkg/plugins/policies/meshloadbalancingstrategy/plugin/v1alpha1/priority.go— Added a pod labels parameter toGetLocalityGroupsandgetLocalLbGroups, with a fallback topodLabels[tag.Key]wheninboundTags.Values(tag.Key)is empty.pkg/plugins/policies/meshloadbalancingstrategy/plugin/v1alpha1/plugin.go— ThreadedpodLabels(fromproxy.Dataplane.GetMeta().GetLabels()) through all call sites ofclaConfigurerandstaticCLAConfigurerfor DPP and gateway resources. Egress passesnilsince no local pod labels are available in that context.The approach is backward-compatible: when inbound tags are present, they continue to be used as before. The label fallback only activates when the tag key is absent.
Supporting documentation
KUMA_EXPERIMENTAL_INBOUND_TAGS_DISABLEDfeature context: tags are stripped from Dataplane inbound config to reduce memory, but Kubernetes pod labels remain accessible viaGetMeta().GetLabels()