Conversation
harbor quota update seeded the interactive form from BytesToStorageString, which renders the hard limit as a decimal string. The quota limit input validates with strconv.ParseInt, so the prefilled default was rejected for every possible limit and the user had to clear the field and retype the number. An unlimited quota was also reported as "current storage: -0.00 MiB", while the quota list view already renders -1 as "Unlimited". Derive the defaults in storageDefaults, which converts the limit in bytes to a whole number plus the largest unit that divides it evenly, so an untouched form round-trips back to the limit it was prefilled with. A limit that cannot be expressed that way, including an unlimited quota, yields an empty value instead of a default the form rejects. Render the current limit through currentStorage so -1 reads as "Unlimited", and drop the unchecked storagearr[1] index along with the string splitting it belonged to. Fixes goharbor#1096 Signed-off-by: Somil Gupta <gsomil93@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
harbor quota updateprefilled the interactive form with a storage limit its own validator rejects, so confirming an unchanged form always errored out.The default came from
BytesToStorageString, which formats the limit as"%.1f GiB"/"%.2f MiB", while the "Quota Limit" input validates withstrconv.ParseInt.ParseInt("50.0")fails, so the user had to clear the field and retype the number, for every possible limit, not just some.The same line also reported an unlimited quota (
hard["storage"] == -1) ascurrent storage: -0.00 MiB, even though the quota list view already renders-1asUnlimited.Type of Change
Changes
storageDefaults, which converts the hard limit in bytes into a whole number plus the largest unit that divides it evenly, so the prefilled default is a value the form accepts and an untouched form round-trips back to the limit it was seeded with.currentStorage, so-1is reported asUnlimitedand matches the quota list view.storagearr[1]index and the string splitting it belonged to, along with the now-unusedslicesandstringsimports.current storage:message, which previously ran into the form.utils.StorageStringToBytes, the unlimited case and the sub-MiB case.Verification
gofmt -s,go vet ./...,go build ./...andgo test ./...are clean.Reproduced against a local stub returning two quotas — one with a 50 GiB hard limit, one unlimited — using binaries built from
mainand from this branch.Before
harbor quota update 1— the prefilled50.0is rejected by the form's own validator. Thecurrent storage:line is missing because it had no trailing newline and the form redraw overwrote it:harbor quota update 2— an unlimited quota prefills the limit as-0.00and selectsMiB. Thecurrent storage: -0.00 MiBline above it is again overwritten by the form:After
harbor quota update 1— the prefilled50is accepted, so confirming an unchanged form is a no-op:harbor quota update 2— the unlimited quota reads correctly and no invalid value is prefilled:Notes
The unit selected by
storageDefaultsis the largest one that divides the limit evenly, so a 1536 MiB limit prefills as1536 MiBrather than a fractional1.5 GiBthat the input would reject.utils.StorageStringToBytesonly accepts^(\d+)(MiB|GiB|TiB)$, so this keeps the value the view returns parseable by its caller.