Skip to content

fix(util): prevent empty label value in GetOwnerLabel for 126-char resource names#387

Open
mdryaan wants to merge 1 commit into
kubeslice:masterfrom
mdryaan:test/util-getownerlabel
Open

fix(util): prevent empty label value in GetOwnerLabel for 126-char resource names#387
mdryaan wants to merge 1 commit into
kubeslice:masterfrom
mdryaan:test/util-getownerlabel

Conversation

@mdryaan
Copy link
Copy Markdown

@mdryaan mdryaan commented May 17, 2026

Description

util.GetOwnerLabel splits resource names longer than 63 characters across multiple label keys using manual index arithmetic. A post-loop assignment at line 245 ran unconditionally after the inner break, assigning completeResourceName[j:] to a new label key even when j == len(completeResourceName) — which happens whenever the input length is an exact multiple of 63 (126, 189, 252, …). This produced a label key with an empty string value. Kubernetes accepts empty label values, so the resource was created without error, but any downstream label selector that expected the full split name would silently fail to match. The fix is a single guard: if j < len(completeResourceName). This PR also adds the first test file in the util/ package, with five table-driven cases covering all splitting branches including the edge case.

Fixes #386

How Has This Been Tested?

Created util/reconciliation_utility_test.go with TestGetOwnerLabel covering: name ≤ 63 chars, name = 63 chars, name = 64 chars (one overflow), name = 126
chars (the edge case — previously produced a third label key with empty value), and name = 127 chars (three labels, all non-empty). All five subtests pass with
go test ./util/... -v -run TestGetOwnerLabel. go build ./... passes.

Before fix

Screenshot 2026-05-17 201208

After fix

Screenshot 2026-05-17 201313

Checklist:

  • The title of the PR states what changed and the related issues number (used for the release note).
  • Does this PR requires documentation updates? — No.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas. — N/A.
  • I have tested it for all user roles. — N/A.
  • I have added all the required unit test cases.

Does this PR introduce a breaking change for other components like worker-operator?

No — the fix only affects resource names whose byte length is an exact multiple of 63. Previously those names produced a spurious empty-value label that would never match any selector; after the fix they do not. Any selector already working correctly is unaffected.

Fix util.GetOwnerLabel to not emit an empty-value label key when the resource name length is an exact multiple of 63

…label value on exact multiples of 63

Signed-off-by: mdryaan <[email protected]>
@mdryaan mdryaan requested a review from that-backend-guy as a code owner May 17, 2026 14:51
@mdryaan mdryaan changed the title fix(util): guard GetOwnerLabel post-loop assignment to prevent empty label value on exact multiples of 63 fix(util): prevent empty label value in GetOwnerLabel for 126-char resource names May 17, 2026
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.

util.GetOwnerLabel has no tests despite complex splitting logic and a known edge case

1 participant