cubemaster: stop shadowing err when parsing container resource quantities - #1463
cubemaster: stop shadowing err when parsing container resource quantities#1463dwin-gharibi wants to merge 1 commit into
Conversation
…resource parse Signed-off-by: Dwin Gharibi <dwin.gharibi@email.kntu.ac.ir>
| }, | ||
| } | ||
|
|
||
| cpu, mem, err := getReqResource(req) |
There was a problem hiding this comment.
Minor: this success-path assertion depends on the package-global config's scheduler limits staying above the summed values. getReqResource rejects the request when cpu.Cmp(MaxMvmCPURes()) >= 0 or mem.Cmp(MaxMvmMemoryRes()) >= 0, and the defaults (max CPU=100, mem=300Gi) are what keep this test green. If conf.yaml ever tightens those limits below 750m/512Mi — or an earlier test mutates cfg.Scheduler without restoring it (the PR notes this package already has cross-test state pollution) — this test fails for an unrelated reason.
Suggest mirroring the sibling overflow tests: call ensureSandboxTestConfig(t) and pin cfg.Scheduler (e.g. max CPU "100", mem "300Gi") before calling getReqResource, restoring afterward, so the test asserts only the summing behaviour it intends.
Review: cubemaster: stop shadowing
|
Closes #1462.
Motivation
getReqResourcehas a named returnerr, but the loop body used:=when callingresource.ParseQuantity, which declares a newerrscoped to the loop body. Theerr = fmt.Errorf(...)assignments therefore wrote to that shadow and were discarded atbreak,leaving the named return
nil.Consequence: a
CreateCubeSandboxrequest with an unparseablecpuormemstring was admitted asconsuming
cpu=0, mem=0. Those values flow throughcheckAndGetReqResourceintoselctx.RequestResource, which is what the scheduler filters on — so the sandbox passed everyresource filter and could land on any node regardless of its real footprint.
The
ctr.Resources == nilbranch a few lines above uses plain=on the named return and workedcorrectly, which is what made the bug easy to miss.
What this changes
CubeMaster/pkg/service/sandbox/util.go— the twoParseQuantitycalls now use distinct errorvariables (
cpuErr,memErr) so thefmt.Errorfassignments land on the named return:Three lines, no behaviour change on the success path, no comment changes.
Testing
New:
CubeMaster/pkg/service/sandbox/util_resource_parse_test.goTestGetReqResourceRejectsUnparseableQuantities— three sub-cases (bad cpu, bad mem, both); eachasserts a non-nil error that names both the offending field and the container.
TestGetReqResourceSumsValidQuantities— regression guard that valid multi-container quantitiesstill sum correctly (
750m/512Mi).CI gates checked locally:
gofmt -l ./pkg— clean (fmt-check).GOOS=linux go build ./...— clean.staticcheck -checks 'SA*' ./pkg/service/sandbox/— theSA4006/SA4017findings onutil.go:168and:173are gone.Pre-existing failure, unrelated to this change
Running the whole
pkg/service/sandboxpackage in Linux (asmake testdoes) shows one failure:I confirmed this is pre-existing on master, not introduced here:
-run TestValidatePauseResumeVolumesPresent) on both master and this branch;It looks like cross-test state pollution within the package. Not fixed here to keep this PR
single-purpose; worth its own issue.
(On macOS the package additionally cannot run at all —
gomonkeycannot patch binaries on darwin —so Linux is the only meaningful local target, matching CI.)