mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-01 22:54:20 +01:00
Merge pull request #8919 from wy65701436/fix-setresusage-outofrange
fix int out of range when to set usage in GC job
This commit is contained in:
commit
fd4c259821
@ -198,7 +198,7 @@ func (m *Manager) UpdateQuota(hardLimits types.ResourceList) error {
|
|||||||
func (m *Manager) SetResourceUsage(resource types.ResourceName, value int64) error {
|
func (m *Manager) SetResourceUsage(resource types.ResourceName, value int64) error {
|
||||||
o := dao.GetOrmer()
|
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()
|
_, err := o.Raw(sql, m.reference, m.referenceID).Exec()
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
@ -136,17 +136,17 @@ func (suite *ManagerSuite) TestSetResourceUsage() {
|
|||||||
mgr := suite.quotaManager()
|
mgr := suite.quotaManager()
|
||||||
id, _ := mgr.NewQuota(hardLimits)
|
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)
|
quota, _ := dao.GetQuota(id)
|
||||||
suite.Equal(hardLimits, mustResourceList(quota.Hard))
|
suite.Equal(hardLimits, mustResourceList(quota.Hard))
|
||||||
|
|
||||||
usage, _ := dao.GetQuotaUsage(id)
|
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) {
|
if err := mgr.SetResourceUsage(types.ResourceStorage, 234); suite.Nil(err) {
|
||||||
usage, _ := dao.GetQuotaUsage(id)
|
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