diff --git a/make/migrations/postgresql/0030_2.0.0_schema.up.sql b/make/migrations/postgresql/0030_2.0.0_schema.up.sql index 329633a1e..c7baea7a8 100644 --- a/make/migrations/postgresql/0030_2.0.0_schema.up.sql +++ b/make/migrations/postgresql/0030_2.0.0_schema.up.sql @@ -98,15 +98,6 @@ FROM ( ) AS s WHERE artifact.digest=s.digest; -/*repair the count usage as we calculate the count quota against artifact rather than tag*/ -/*count=count-(tag count-artifact count)*/ -UPDATE quota_usage SET used=jsonb_set(used, '{count}', ((used->>'count')::int - (SELECT ( - SELECT COUNT (*) FROM tag - JOIN artifact ON tag.artifact_id=artifact.id - WHERE artifact.project_id=quota_usage.reference_id::int)-( - SELECT COUNT (*) FROM artifact - WHERE project_id=quota_usage.reference_id::int)))::text::jsonb); - /* artifact_reference records the child artifact referenced by parent artifact */ CREATE TABLE artifact_reference ( diff --git a/src/controller/chartmuseum/controller.go b/src/controller/chartmuseum/controller.go deleted file mode 100644 index 78f24c357..000000000 --- a/src/controller/chartmuseum/controller.go +++ /dev/null @@ -1,144 +0,0 @@ -// Copyright Project Harbor Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package chartmuseum - -import ( - "context" - "errors" - "net/http" - "net/url" - "strings" - "sync" - - "github.com/goharbor/harbor/src/chartserver" - "github.com/goharbor/harbor/src/common" - "github.com/goharbor/harbor/src/common/config" - commonhttp "github.com/goharbor/harbor/src/common/http" - "github.com/goharbor/harbor/src/controller/project" -) - -var ( - // Ctl is a global chartmuseum controller instance - Ctl = NewController() -) - -// Controller defines the operations related with chartmuseum which only used by quota now -type Controller interface { - // Count returns charts count in the project - Count(ctx context.Context, projectID int64) (int64, error) - - // Exist returns true when chart exist in the project - Exist(ctx context.Context, projectID int64, chartName, version string) (bool, error) -} - -// NewController creates an instance of the default repository controller -func NewController() Controller { - return &controller{ - projectCtl: project.Ctl, - } -} - -type controller struct { - projectCtl project.Controller - cc *chartserver.Controller - withChartMuseum bool - - initializeError error - initializeOnce sync.Once -} - -func (c *controller) initialize() error { - c.initializeOnce.Do(func() { - cfg := config.NewDBCfgManager() - - c.withChartMuseum = cfg.Get(common.WithChartMuseum).GetBool() - if !c.withChartMuseum { - return - } - - chartEndpoint := strings.TrimSpace(cfg.Get(common.ChartRepoURL).GetString()) - if len(chartEndpoint) == 0 { - c.initializeError = errors.New("empty chartmuseum endpoint") - return - } - - url, err := url.Parse(strings.TrimSuffix(chartEndpoint, "/")) - if err != nil { - c.initializeError = errors.New("endpoint URL of chart storage server is malformed") - return - } - - ctr, err := chartserver.NewController(url) - if err != nil { - c.initializeError = errors.New("failed to initialize chart API controller") - return - } - - c.cc = ctr - }) - - return c.initializeError -} - -func (c *controller) Count(ctx context.Context, projectID int64) (int64, error) { - if err := c.initialize(); err != nil { - return 0, err - } - - if !c.withChartMuseum { - return 0, nil - } - - proj, err := c.projectCtl.Get(ctx, projectID) - if err != nil { - return 0, err - } - - count, err := c.cc.GetCountOfCharts([]string{proj.Name}) - if err != nil { - return 0, err - } - - return int64(count), nil -} - -func (c *controller) Exist(ctx context.Context, projectID int64, chartName, version string) (bool, error) { - if err := c.initialize(); err != nil { - return false, err - } - - if !c.withChartMuseum { - return false, nil - } - - proj, err := c.projectCtl.Get(ctx, projectID) - if err != nil { - return false, err - } - - chartVersion, err := c.cc.GetChartVersion(proj.Name, chartName, version) - if err != nil { - var httpErr *commonhttp.Error - if errors.As(err, &httpErr) { - if httpErr.Code == http.StatusNotFound { - return false, nil - } - } - - return false, err - } - - return !chartVersion.Removed, nil -} diff --git a/src/controller/quota/driver/project/project.go b/src/controller/quota/driver/project/project.go index 2bb983528..4a78d49e3 100644 --- a/src/controller/quota/driver/project/project.go +++ b/src/controller/quota/driver/project/project.go @@ -22,9 +22,7 @@ import ( "github.com/goharbor/harbor/src/common" "github.com/goharbor/harbor/src/common/config" "github.com/goharbor/harbor/src/common/models" - "github.com/goharbor/harbor/src/controller/artifact" "github.com/goharbor/harbor/src/controller/blob" - "github.com/goharbor/harbor/src/controller/chartmuseum" "github.com/goharbor/harbor/src/lib/log" dr "github.com/goharbor/harbor/src/pkg/quota/driver" "github.com/goharbor/harbor/src/pkg/types" @@ -39,9 +37,7 @@ type driver struct { cfg *config.CfgManager loader *dataloader.Loader - artifactCtl artifact.Controller - blobCtl blob.Controller - chartCtl chartmuseum.Controller + blobCtl blob.Controller } func (d *driver) Enabled(ctx context.Context, key string) (bool, error) { @@ -127,10 +123,8 @@ func newDriver() dr.Driver { loader := dataloader.NewBatchedLoader(getProjectsBatchFn) return &driver{ - cfg: cfg, - loader: loader, - artifactCtl: artifact.Ctl, - blobCtl: blob.Ctl, - chartCtl: chartmuseum.Ctl, + cfg: cfg, + loader: loader, + blobCtl: blob.Ctl, } } diff --git a/src/controller/quota/driver/project/project_test.go b/src/controller/quota/driver/project/project_test.go index 381eb7420..c35e475d4 100644 --- a/src/controller/quota/driver/project/project_test.go +++ b/src/controller/quota/driver/project/project_test.go @@ -21,7 +21,6 @@ import ( "github.com/goharbor/harbor/src/pkg/types" artifacttesting "github.com/goharbor/harbor/src/testing/controller/artifact" blobtesting "github.com/goharbor/harbor/src/testing/controller/blob" - charttesting "github.com/goharbor/harbor/src/testing/controller/chartmuseum" "github.com/goharbor/harbor/src/testing/mock" "github.com/stretchr/testify/suite" ) @@ -31,7 +30,6 @@ type DriverTestSuite struct { artifactCtl *artifacttesting.Controller blobCtl *blobtesting.Controller - chartCtl *charttesting.Controller d *driver } @@ -39,12 +37,9 @@ type DriverTestSuite struct { func (suite *DriverTestSuite) SetupTest() { suite.artifactCtl = &artifacttesting.Controller{} suite.blobCtl = &blobtesting.Controller{} - suite.chartCtl = &charttesting.Controller{} suite.d = &driver{ - artifactCtl: suite.artifactCtl, - blobCtl: suite.blobCtl, - chartCtl: suite.chartCtl, + blobCtl: suite.blobCtl, } } diff --git a/src/server/middleware/quota/controller.go b/src/server/middleware/quota/controller.go index c1603a92d..51738f71d 100644 --- a/src/server/middleware/quota/controller.go +++ b/src/server/middleware/quota/controller.go @@ -17,7 +17,6 @@ package quota import ( "github.com/goharbor/harbor/src/controller/artifact" "github.com/goharbor/harbor/src/controller/blob" - "github.com/goharbor/harbor/src/controller/chartmuseum" "github.com/goharbor/harbor/src/controller/project" "github.com/goharbor/harbor/src/controller/quota" ) @@ -25,7 +24,6 @@ import ( var ( artifactController = artifact.Ctl blobController = blob.Ctl - chartController = chartmuseum.Ctl projectController = project.Ctl quotaController = quota.Ctl ) diff --git a/src/server/middleware/quota/util_test.go b/src/server/middleware/quota/util_test.go index fb0d76b52..20a8f3679 100644 --- a/src/server/middleware/quota/util_test.go +++ b/src/server/middleware/quota/util_test.go @@ -58,7 +58,6 @@ func Test_projectReferenceObject(t *testing.T) { {"/api/v2.0/projects/library/repositories", args{req("/api/v2.0/projects/library/repositories")}, "project", "1", false}, {"/api/v2.0/projects/demo", args{req("/api/v2.0/projects/demo")}, "", "", true}, {"/api/v2.0/library", args{req("/api/v2.0/library")}, "", "", true}, - {"/api/chartrepo/library/charts", args{req("/api/chartrepo/library/charts")}, "project", "1", false}, {"/v2/library/photon/manifests/2.0", args{req("/v2/library/photon/manifests/2.0")}, "project", "1", false}, {"/v2", args{req("/v2")}, "", "", true}, } diff --git a/src/server/middleware/util/util.go b/src/server/middleware/util/util.go index f2e8320ee..77842d27a 100644 --- a/src/server/middleware/util/util.go +++ b/src/server/middleware/util/util.go @@ -32,8 +32,6 @@ func ParseProjectName(r *http.Request) string { prefixes := []string{ fmt.Sprintf("/api/%s/projects/", api.APIVersion), // v2.0 management APIs - "/api/chartrepo/", // chartmuseum APIs - fmt.Sprintf("/api/%s/chartrepo/", api.APIVersion), // chartmuseum Label APIs } for _, prefix := range prefixes {