Skip to content

service: avoid shared label-map mutation in worker gateway generation#393

Open
ShubhamMishra99 wants to merge 2 commits into
kubeslice:masterfrom
ShubhamMishra99:fix/gateway-label-mutation-determinism
Open

service: avoid shared label-map mutation in worker gateway generation#393
ShubhamMishra99 wants to merge 2 commits into
kubeslice:masterfrom
ShubhamMishra99:fix/gateway-label-mutation-determinism

Conversation

@ShubhamMishra99

Copy link
Copy Markdown

Description

This PR fixes a reconciliation-safety issue in worker gateway topology generation caused by mutation of caller-owned label maps during gateway object construction.

buildMinimumGateway previously copied the provided labels into a local gatewayLabels map, but also mutated the original input map by injecting controller/project/slice labels directly into labels.

Because the same label map can be reused across full-mesh gateway pair generation during SliceConfig reconciliation, this introduced hidden shared mutable state and weakened deterministic topology object synthesis.

Changes

  • Stop mutating the caller-provided labels map in buildMinimumGateway

  • Apply controller/project/slice labels only to the local gatewayLabels copy

  • Extend regression assertions validating that:

    • owner labels remain unchanged
    • no reconciliation-specific labels leak into caller-owned maps
    • original label map size/content remains intact

Why this matters

This improves:

  • reconciliation determinism
  • helper purity/idempotency
  • topology generation safety
  • maintainability of gateway object synthesis logic

The change also reduces hidden coupling between topology intent inputs and generated gateway objects during full-mesh reconciliation workflows.

Testing

Updated:

  • testBuildMinimumGatewayLabelsAreIsolatedPerGateway

Additional assertions now verify:

  • no mutation of caller-owned labels
  • no leaked reconciliation labels
  • original label content remains unchanged after generating multiple gateway objects

Compatibility

  • No API changes
  • No CRD changes
  • No intended topology behavior changes
  • Only removes unintended side effects during gateway construction

Architectural Context

SliceConfig reconciliation computes desired topology intent and generates full-mesh worker gateway objects across clusters. Helper-level mutation of shared label state breaks clean intent-to-object boundaries and can introduce inconsistent reconciliation behavior over time.

This fix restores safer object materialization semantics by ensuring gateway construction operates on isolated label copies.

Signed-off-by: Shubham Mishra <mishrashubham8932@gmail.com>
Signed-off-by: Shubham Mishra <mishrashubham8932@gmail.com>
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.

1 participant