mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-26 04:05:40 +01:00
fix int out of range when to set usage in GC job
Signed-off-by: wang yan <wangyan@vmware.com>
This commit is contained in:
parent
469018ae9e
commit
d3f7d01a69
@ -198,7 +198,7 @@ func (m *Manager) UpdateQuota(hardLimits types.ResourceList) error {
|
||||
func (m *Manager) SetResourceUsage(resource types.ResourceName, value int64) error {
|
||||
o := dao.GetOrmer()
|
||||
|
||||
sql := fmt.Sprintf("UPDATE quota_usage SET used = jsonb_set(used, '{%s}', to_jsonb(%d::int), true) WHERE reference = ? AND reference_id = ?", resource, value)
|
||||
sql := fmt.Sprintf("UPDATE quota_usage SET used = jsonb_set(used, '{%s}', to_jsonb(%d::bigint), true) WHERE reference = ? AND reference_id = ?", resource, value)
|
||||
_, err := o.Raw(sql, m.reference, m.referenceID).Exec()
|
||||
|
||||
return err
|
||||
|
@ -136,17 +136,17 @@ func (suite *ManagerSuite) TestSetResourceUsage() {
|
||||
mgr := suite.quotaManager()
|
||||
id, _ := mgr.NewQuota(hardLimits)
|
||||
|
||||
if err := mgr.SetResourceUsage(types.ResourceCount, 123); suite.Nil(err) {
|
||||
if err := mgr.SetResourceUsage(types.ResourceCount, 999999999999999999); suite.Nil(err) {
|
||||
quota, _ := dao.GetQuota(id)
|
||||
suite.Equal(hardLimits, mustResourceList(quota.Hard))
|
||||
|
||||
usage, _ := dao.GetQuotaUsage(id)
|
||||
suite.Equal(types.ResourceList{types.ResourceCount: 123, types.ResourceStorage: 0}, mustResourceList(usage.Used))
|
||||
suite.Equal(types.ResourceList{types.ResourceCount: 999999999999999999, types.ResourceStorage: 0}, mustResourceList(usage.Used))
|
||||
}
|
||||
|
||||
if err := mgr.SetResourceUsage(types.ResourceStorage, 234); suite.Nil(err) {
|
||||
usage, _ := dao.GetQuotaUsage(id)
|
||||
suite.Equal(types.ResourceList{types.ResourceCount: 123, types.ResourceStorage: 234}, mustResourceList(usage.Used))
|
||||
suite.Equal(types.ResourceList{types.ResourceCount: 999999999999999999, types.ResourceStorage: 234}, mustResourceList(usage.Used))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user