kubeslice / kubeslice/kubeslice-controller
`util.GetOwnerLabel` has no tests despite complex splitting logic and a known edge case
- Dominant language
- Go
- Stars
- 73
- Forks
- 48
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 8
Description
## 📜 Description
`util.GetOwnerLabel` splits resource names longer than 63 characters acrossmultiple label keys using manual index arithmetic. When the resource name length is an exact multiple of 63 (126, 189, 252, …), the post-loop assignment at
line 245 runs unconditionally after the inner `break`, assigning`completeResourceName[j:]` to a new label key even when
`j == len(completeResourceName)`. This produces a label key with an empty string value. Kubernetes accepts empty label values without error, so the resource is created silently, but any downstream label selector that expects the full split name will never match it.
There are also zero test files in the entire `util/` package, so this edge case was undetectable by `make unit-test`.
## 👟 Reproduction steps
```bash
cd /mnt/c/Users/alikh/Desktop/Projects/kubeslice-controller
go test ./util/... -v -run TestGetOwnerLabel
```
The test `name_exactly_126_chars_produces_exactly_two_name_labels_with_no_empty_value`
fails with:
```
actual: map[string]string{
"kubeslice-controller-resource-name": "aaa...63 chars",
"kubeslice-controller-resource-name-1": "bbb...63 chars",
"kubeslice-controller-resource-name-2": "",
"kubeslice-resource-owner": "kubeslice-controller"
}
```
## 👍 Expected behavior
For a 126-character resource name, `GetOwnerLabel` produces exactly two name
label keys (`kubeslice-controller-resource-name` and
`kubeslice-controller-resource-name-1`), both with non-empty values. No
spurious third key is created.
## 👎 Actual Behavior
A third label key `kubeslice-controller-resource-name-2` is created with an
empty string value. Label selectors using this key will silently fail to match
the resource.
## 🐚 Relevant log output
## ✅ Proposed Solution
Guard the post-loop assignment with `if j < len(completeResourceName)` so it
only runs when there are remaining characters to assign. Add
`util/reconciliation_utility_test.go` with table-driven tests covering names
shorter than 63 chars, exactly 63 chars, 64 chars, 126 chars (the edge case),
and 127 chars.
## 👀 Have you spent some time to check if this issue has been raised before?
- [x] I checked and didn't find any similar issue
## Code of Conduct
- [x] I agree to follow this project's Code of Conduct
Contributor guide
Research direction
Start at util.GetOwnerLabel and inspect the post-loop assignment around line 245. Run go test ./util/... -v -run TestGetOwnerLabel, then add util/reconciliation_utility_test.go with table-driven cases for names shorter than 63, exactly 63, 64, 126, and 127 characters. Done means exact 126-character names produce two non-empty name labels and the full test table passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- infrastructure
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100