Skip to content

fix(quota): prefill quota update with a limit the form accepts - #1097

Open
Somilg11 wants to merge 1 commit into
goharbor:mainfrom
Somilg11:fix/quota-update-prefill
Open

Somilg11 wants to merge 1 commit into
goharbor:mainfrom
Somilg11:fix/quota-update-prefill

Conversation

@Somilg11

@Somilg11 Somilg11 commented Sep 6, 2026

Copy link
Copy Markdown

Description

harbor quota update prefilled 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 with strconv.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) as current storage: -0.00 MiB, even though the quota list view already renders -1 as Unlimited.

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Documentation update
  • Chore / maintenance

Changes

  • Add 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.
  • Return an empty value for a limit that cannot be expressed as a whole number of MiB/GiB/TiB, including an unlimited quota, so the user is asked for a value instead of being handed one the form rejects.
  • Add currentStorage, so -1 is reported as Unlimited and matches the quota list view.
  • Drop the unchecked storagearr[1] index and the string splitting it belonged to, along with the now-unused slices and strings imports.
  • Add a trailing newline to the current storage: message, which previously ran into the form.
  • Add unit tests for both helpers, covering the whole-unit conversions, the round-trip through utils.StorageStringToBytes, the unlimited case and the sub-MiB case.

Verification

gofmt -s, go vet ./..., go build ./... and go test ./... are clean.

Reproduced against a local stub returning two quotas — one with a 50 GiB hard limit, one unlimited — using binaries built from main and from this branch.

Before

harbor quota update 1 — the prefilled 50.0 is rejected by the form's own validator. The current storage: line is missing because it had no trailing newline and the form redraw overwrote it:

Screenshot 2026-09-07 at 12 38 09 AM

harbor quota update 2 — an unlimited quota prefills the limit as -0.00 and selects MiB. The current storage: -0.00 MiB line above it is again overwritten by the form:

Screenshot 2026-09-07 at 12 39 14 AM

After

harbor quota update 1 — the prefilled 50 is accepted, so confirming an unchanged form is a no-op:

Screenshot 2026-09-07 at 12 40 06 AM

harbor quota update 2 — the unlimited quota reads correctly and no invalid value is prefilled:

Screenshot 2026-09-07 at 12 40 30 AM

Notes

The unit selected by storageDefaults is the largest one that divides the limit evenly, so a 1536 MiB limit prefills as 1536 MiB rather than a fractional 1.5 GiB that the input would reject. utils.StorageStringToBytes only accepts ^(\d+)(MiB|GiB|TiB)$, so this keeps the value the view returns parseable by its caller.

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>
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.

[bug]: quota update prefills a storage limit its own form rejects

1 participant