diff --git a/src/registryctl/api/registry/gc/gc.go b/src/registryctl/api/registry/gc/gc.go deleted file mode 100644 index 610df2ae3..000000000 --- a/src/registryctl/api/registry/gc/gc.go +++ /dev/null @@ -1,62 +0,0 @@ -package gc - -import ( - "bytes" - "github.com/goharbor/harbor/src/lib/log" - "github.com/goharbor/harbor/src/registryctl/api" - "net/http" - "os/exec" - "time" -) - -// NewHandler returns the handler to handler blob request -func NewHandler(registryConf string) http.Handler { - return &handler{ - registryConf: registryConf, - } -} - -type handler struct { - registryConf string -} - -// ServeHTTP ... -func (h *handler) ServeHTTP(w http.ResponseWriter, req *http.Request) { - switch req.Method { - case http.MethodPost: - h.start(w, req) - default: - api.HandleNotMethodAllowed(w) - } -} - -// Result ... -type Result struct { - Status bool `json:"status"` - Msg string `json:"msg"` - StartTime time.Time `json:"starttime"` - EndTime time.Time `json:"endtime"` -} - -// start ... -func (h *handler) start(w http.ResponseWriter, r *http.Request) { - cmd := exec.Command("/bin/bash", "-c", "registry_DO_NOT_USE_GC garbage-collect --delete-untagged=false "+h.registryConf) - var outBuf, errBuf bytes.Buffer - cmd.Stdout = &outBuf - cmd.Stderr = &errBuf - - start := time.Now() - log.Debugf("Start to execute garbage collection...") - if err := cmd.Run(); err != nil { - log.Errorf("Fail to execute GC: %v, command err: %s", err, errBuf.String()) - api.HandleInternalServerError(w, err) - return - } - - gcr := Result{true, outBuf.String(), start, time.Now()} - if err := api.WriteJSON(w, gcr); err != nil { - log.Errorf("failed to write response: %v", err) - return - } - log.Debugf("Successful to execute garbage collection...") -} diff --git a/src/registryctl/client/client.go b/src/registryctl/client/client.go index 1dfdb1d42..555621b2c 100644 --- a/src/registryctl/client/client.go +++ b/src/registryctl/client/client.go @@ -15,7 +15,6 @@ package client import ( - "encoding/json" "fmt" "github.com/goharbor/harbor/src/lib/errors" "io/ioutil" @@ -25,8 +24,6 @@ import ( common_http "github.com/goharbor/harbor/src/common/http" "github.com/goharbor/harbor/src/common/http/modifier/auth" "github.com/goharbor/harbor/src/common/utils" - "github.com/goharbor/harbor/src/lib/log" - "github.com/goharbor/harbor/src/registryctl/api/registry/gc" ) // const definition @@ -38,8 +35,6 @@ const ( type Client interface { // Health tests the connection with registry server Health() error - // StartGC enable the gc of registry server - StartGC() (*gc.Result, error) // DeleteBlob deletes the specified blob. The "reference" should be "digest" DeleteBlob(reference string) (err error) // DeleteManifest deletes the specified manifest. The "reference" can be "tag" or "digest" @@ -83,36 +78,6 @@ func (c *client) Health() error { return utils.TestTCPConn(addr, 60, 2) } -// StartGC ... -func (c *client) StartGC() (*gc.Result, error) { - url := c.baseURL + "/api/registry/gc" - gcr := &gc.Result{} - - req, err := http.NewRequest(http.MethodPost, url, nil) - if err != nil { - return nil, err - } - req.Header.Set("Content-Type", "application/json") - resp, err := c.do(req) - if err != nil { - return nil, err - } - defer resp.Body.Close() - data, err := ioutil.ReadAll(resp.Body) - if err != nil { - return nil, err - } - if resp.StatusCode != http.StatusOK { - log.Errorf("Failed to start gc: %d", resp.StatusCode) - return nil, fmt.Errorf("failed to start GC: %d", resp.StatusCode) - } - if err := json.Unmarshal(data, gcr); err != nil { - return nil, err - } - - return gcr, nil -} - // DeleteBlob ... func (c *client) DeleteBlob(reference string) (err error) { req, err := http.NewRequest(http.MethodDelete, buildBlobURL(c.baseURL, reference), nil) diff --git a/src/registryctl/client/client_test.go b/src/registryctl/client/client_test.go index 0268fdbfd..7d05ab0f5 100644 --- a/src/registryctl/client/client_test.go +++ b/src/registryctl/client/client_test.go @@ -43,13 +43,6 @@ func (c *clientTestSuite) TesHealth() { c.Require().Nil(err) } -func (c *clientTestSuite) TesStartGC() { - gcr, err := c.client.StartGC() - c.Require().Nil(err) - c.Equal(gcr.Msg, "hello-world") - c.Equal(gcr.Status, true) -} - func (c *clientTestSuite) TestDeleteManifest() { server := test.NewServer( &test.RequestHandlerMapping{ diff --git a/src/registryctl/handlers/router.go b/src/registryctl/handlers/router.go index 274d80d8f..ddc0b074e 100644 --- a/src/registryctl/handlers/router.go +++ b/src/registryctl/handlers/router.go @@ -20,7 +20,6 @@ import ( "github.com/goharbor/harbor/src/registryctl/api" "github.com/goharbor/harbor/src/registryctl/api/registry/blob" - "github.com/goharbor/harbor/src/registryctl/api/registry/gc" "github.com/goharbor/harbor/src/registryctl/config" "github.com/gorilla/mux" ) @@ -31,7 +30,6 @@ func newRouter(conf config.Configuration) http.Handler { rootRouter.StrictSlash(true) rootRouter.HandleFunc("/api/health", api.Health).Methods("GET") - rootRouter.Path("/api/registry/gc").Methods(http.MethodPost).Handler(gc.NewHandler(conf.RegistryConfig)) rootRouter.Path("/api/registry/blob/{reference}").Methods(http.MethodDelete).Handler(blob.NewHandler(conf.StorageDriver)) rootRouter.Path("/api/registry/{name:.*}/manifests/{reference}").Methods(http.MethodDelete).Handler(manifest.NewHandler(conf.StorageDriver)) return rootRouter diff --git a/src/testing/registryctl/client.go b/src/testing/registryctl/client.go index a56760404..084716ce4 100644 --- a/src/testing/registryctl/client.go +++ b/src/testing/registryctl/client.go @@ -1,7 +1,6 @@ package registryctl import ( - "github.com/goharbor/harbor/src/registryctl/api/registry/gc" "github.com/stretchr/testify/mock" ) @@ -14,15 +13,6 @@ func (c *Mockclient) Health() error { return nil } -// StartGC ... -func (c *Mockclient) StartGC() (*gc.Result, error) { - result := &gc.Result{ - Status: true, - Msg: "this is a mock client", - } - return result, nil -} - // DeleteBlob ... func (c *Mockclient) DeleteBlob(reference string) (err error) { return nil