mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-21 17:55:30 +01:00
feat: Optimize quota checking when pushing images (#17392)
Signed-off-by: lengrongfu <1275177125@qq.com>
This commit is contained in:
parent
fbeeaa7537
commit
8fe578e7ab
@ -143,6 +143,19 @@ func (suite *ControllerTestSuite) TestRequestFunctionFailed() {
|
||||
suite.Error(suite.ctl.Request(ctx, suite.reference, referenceID, resources, func() error { return fmt.Errorf("error") }))
|
||||
}
|
||||
|
||||
func (suite *ControllerTestSuite) TestRequestResourceIsZero() {
|
||||
suite.PrepareForUpdate(suite.quota, nil)
|
||||
|
||||
ctx := orm.NewContext(context.TODO(), &ormtesting.FakeOrmer{})
|
||||
referenceID := uuid.New().String()
|
||||
f := func() error {
|
||||
return nil
|
||||
}
|
||||
res := types.ResourceList{types.ResourceStorage: 0}
|
||||
err := suite.ctl.Request(ctx, suite.reference, referenceID, res, f)
|
||||
suite.Nil(err)
|
||||
}
|
||||
|
||||
func TestControllerTestSuite(t *testing.T) {
|
||||
suite.Run(t, &ControllerTestSuite{})
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ func IsSafe(hardLimits types.ResourceList, currentUsed types.ResourceList, newUs
|
||||
continue
|
||||
}
|
||||
|
||||
if hardLimit == types.UNLIMITED || value == currentUsed[resource] {
|
||||
if hardLimit == types.UNLIMITED {
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -38,8 +38,8 @@ func postInitiateBlobUploadResources(r *http.Request, reference, referenceID str
|
||||
query := r.URL.Query()
|
||||
mount := query.Get("mount")
|
||||
if mount == "" {
|
||||
// it is not mount blob http request, skip to request the resources
|
||||
return nil, nil
|
||||
// it is not mount blob http request, create length is zero resource to check quota is full
|
||||
return types.ResourceList{types.ResourceStorage: 0}, nil
|
||||
}
|
||||
|
||||
ctx := r.Context()
|
||||
|
@ -70,6 +70,25 @@ func (suite *PostInitiateBlobUploadMiddlewareTestSuite) TestMiddleware() {
|
||||
PostInitiateBlobUploadMiddleware()(next).ServeHTTP(rr, req)
|
||||
suite.Equal(http.StatusOK, rr.Code)
|
||||
}
|
||||
|
||||
{
|
||||
url = "/v2/library/photon/blobs/uploads"
|
||||
mock.OnAnything(suite.quotaController, "Request").Return(nil).Once().Run(func(args mock.Arguments) {
|
||||
resources := args.Get(3).(types.ResourceList)
|
||||
suite.Len(resources, 1)
|
||||
suite.Equal(resources[types.ResourceStorage], int64(0))
|
||||
|
||||
f := args.Get(4).(func() error)
|
||||
f()
|
||||
})
|
||||
mock.OnAnything(suite.quotaController, "GetByRef").Return("a.Quota{}, nil).Once()
|
||||
|
||||
req := httptest.NewRequest(http.MethodPost, url, nil)
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
PostInitiateBlobUploadMiddleware()(next).ServeHTTP(rr, req)
|
||||
suite.Equal(http.StatusOK, rr.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPostInitiateBlobUploadMiddlewareTestSuite(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user