diff --git a/make/docker-compose.tpl b/make/docker-compose.tpl index 881c0f2b7..0e8dd2fa5 100644 --- a/make/docker-compose.tpl +++ b/make/docker-compose.tpl @@ -100,6 +100,7 @@ services: - /data/secretkey:/etc/core/key:z - /data/ca_download/:/etc/core/ca/:z - /data/psc/:/etc/core/token/:z + - /data/:/data/:z networks: - harbor dns_search: . diff --git a/src/adminserver/api/systeminfo.go b/src/adminserver/api/systeminfo.go deleted file mode 100644 index b3f6c2915..000000000 --- a/src/adminserver/api/systeminfo.go +++ /dev/null @@ -1,37 +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 api - -import ( - "net/http" - - "github.com/goharbor/harbor/src/adminserver/systeminfo/imagestorage" - "github.com/goharbor/harbor/src/common/utils/log" -) - -// Capacity handles /api/systeminfo/capacity and returns system capacity -func Capacity(w http.ResponseWriter, r *http.Request) { - capacity, err := imagestorage.GlobalDriver.Cap() - if err != nil { - log.Errorf("failed to get capacity: %v", err) - handleInternalServerError(w) - return - } - - if err = writeJSON(w, capacity); err != nil { - log.Errorf("failed to write response: %v", err) - return - } -} diff --git a/src/adminserver/api/systeminfo_test.go b/src/adminserver/api/systeminfo_test.go deleted file mode 100644 index 2acc29a81..000000000 --- a/src/adminserver/api/systeminfo_test.go +++ /dev/null @@ -1,73 +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 api - -import ( - "encoding/json" - "errors" - "io/ioutil" - "net/http" - "net/http/httptest" - "testing" - - "github.com/goharbor/harbor/src/adminserver/systeminfo/imagestorage" - "github.com/stretchr/testify/assert" -) - -type fakeImageStorageDriver struct { - capacity *imagestorage.Capacity - err error -} - -func (f *fakeImageStorageDriver) Name() string { - return "fake" -} - -func (f *fakeImageStorageDriver) Cap() (*imagestorage.Capacity, error) { - return f.capacity, f.err -} - -func TestCapacity(t *testing.T) { - cases := []struct { - driver imagestorage.Driver - responseCode int - capacity *imagestorage.Capacity - }{ - {&fakeImageStorageDriver{nil, errors.New("error")}, http.StatusInternalServerError, nil}, - {&fakeImageStorageDriver{&imagestorage.Capacity{100, 90}, nil}, http.StatusOK, &imagestorage.Capacity{100, 90}}, - } - - req, err := http.NewRequest("", "", nil) - if err != nil { - t.Fatalf("failed to create request: %v", err) - } - for _, c := range cases { - imagestorage.GlobalDriver = c.driver - w := httptest.NewRecorder() - Capacity(w, req) - assert.Equal(t, c.responseCode, w.Code, "unexpected response code") - if c.responseCode == http.StatusOK { - b, err := ioutil.ReadAll(w.Body) - if err != nil { - t.Fatalf("failed to read from response body: %v", err) - } - capacity := &imagestorage.Capacity{} - if err = json.Unmarshal(b, capacity); err != nil { - t.Fatalf("failed to unmarshal: %v", err) - } - assert.Equal(t, c.capacity, capacity) - } - } -} diff --git a/src/adminserver/client/client.go b/src/adminserver/client/client.go index a8ddec450..0f486e693 100644 --- a/src/adminserver/client/client.go +++ b/src/adminserver/client/client.go @@ -17,10 +17,10 @@ package client import ( "strings" - "github.com/goharbor/harbor/src/adminserver/systeminfo/imagestorage" "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/core/systeminfo/imagestorage" ) // Client defines methods that an Adminserver client should implement diff --git a/src/adminserver/client/client_test.go b/src/adminserver/client/client_test.go index 968923308..c11aaf312 100644 --- a/src/adminserver/client/client_test.go +++ b/src/adminserver/client/client_test.go @@ -69,13 +69,3 @@ func TestResetCfgs(t *testing.T) { return } } - -func TestCapacity(t *testing.T) { - capacity, err := c.Capacity() - if !assert.Nil(t, err, "unexpected error") { - return - } - - assert.Equal(t, uint64(100), capacity.Total) - assert.Equal(t, uint64(90), capacity.Free) -} diff --git a/src/adminserver/handlers/router.go b/src/adminserver/handlers/router.go index 7eb28c147..24ad5dd93 100644 --- a/src/adminserver/handlers/router.go +++ b/src/adminserver/handlers/router.go @@ -26,7 +26,6 @@ func newRouter() http.Handler { r.HandleFunc("/api/configurations", api.UpdateCfgs).Methods("PUT") r.HandleFunc("/api/configs", api.ListCfgs).Methods("GET") r.HandleFunc("/api/configurations/reset", api.ResetCfgs).Methods("POST") - r.HandleFunc("/api/systeminfo/capacity", api.Capacity).Methods("GET") r.HandleFunc("/api/ping", api.Ping).Methods("GET") return r } diff --git a/src/adminserver/main.go b/src/adminserver/main.go index 3e945db49..93b47b5b5 100644 --- a/src/adminserver/main.go +++ b/src/adminserver/main.go @@ -20,7 +20,6 @@ import ( "github.com/goharbor/harbor/src/adminserver/handlers" syscfg "github.com/goharbor/harbor/src/adminserver/systemcfg" - sysinfo "github.com/goharbor/harbor/src/adminserver/systeminfo" "github.com/goharbor/harbor/src/common/utils/log" ) @@ -47,8 +46,6 @@ func main() { } log.Info("system initialization completed") - sysinfo.Init() - port := os.Getenv("PORT") if len(port) == 0 { port = "80" diff --git a/src/common/utils/test/adminserver.go b/src/common/utils/test/adminserver.go index b58bf880d..283727225 100644 --- a/src/common/utils/test/adminserver.go +++ b/src/common/utils/test/adminserver.go @@ -19,7 +19,6 @@ import ( "net/http" "net/http/httptest" - "github.com/goharbor/harbor/src/adminserver/systeminfo/imagestorage" "github.com/goharbor/harbor/src/common" ) @@ -122,36 +121,9 @@ func NewAdminserver(config map[string]interface{}) (*httptest.Server, error) { }), }) - capacityHandler, err := NewCapacityHandle() - if err != nil { - return nil, err - } - m = append(m, &RequestHandlerMapping{ - Method: "GET", - Pattern: "/api/systeminfo/capacity", - Handler: capacityHandler, - }) - return NewServer(m...), nil } -// NewCapacityHandle ... -func NewCapacityHandle() (func(http.ResponseWriter, *http.Request), error) { - capacity := imagestorage.Capacity{ - Total: 100, - Free: 90, - } - b, err := json.Marshal(capacity) - if err != nil { - return nil, err - } - resp := &Response{ - StatusCode: http.StatusOK, - Body: b, - } - return Handler(resp), nil -} - // GetDefaultConfigMap returns the defailt config map for easier modification. func GetDefaultConfigMap() map[string]interface{} { return adminServerDefaultConfig diff --git a/src/core/api/systeminfo.go b/src/core/api/systeminfo.go index 254553cc5..619af3dd9 100644 --- a/src/core/api/systeminfo.go +++ b/src/core/api/systeminfo.go @@ -29,6 +29,8 @@ import ( "github.com/goharbor/harbor/src/common/utils/clair" "github.com/goharbor/harbor/src/common/utils/log" "github.com/goharbor/harbor/src/core/config" + "github.com/goharbor/harbor/src/core/systeminfo" + "github.com/goharbor/harbor/src/core/systeminfo/imagestorage" ) // SystemInfoAPI handle requests for getting system info /api/systeminfo @@ -120,7 +122,8 @@ func (sia *SystemInfoAPI) validate() { func (sia *SystemInfoAPI) GetVolumeInfo() { sia.validate() - capacity, err := config.AdminserverClient.Capacity() + systeminfo.Init() + capacity, err := imagestorage.GlobalDriver.Cap() if err != nil { log.Errorf("failed to get capacity: %v", err) sia.CustomAbort(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError)) diff --git a/src/core/router.go b/src/core/router.go index 3f5f8da28..2c629ba01 100644 --- a/src/core/router.go +++ b/src/core/router.go @@ -112,6 +112,7 @@ func initRouters() { beego.Router("/api/internal/syncregistry", &api.InternalAPI{}, "post:SyncRegistry") beego.Router("/api/internal/renameadmin", &api.InternalAPI{}, "post:RenameAdmin") + beego.Router("/api/internal/configurations", &api.ConfigAPI{}, "get:GetInternalConfig") // external service that hosted on harbor process: beego.Router("/service/notifications", ®istry.NotificationHandler{}) diff --git a/src/adminserver/systeminfo/imagestorage/driver.go b/src/core/systeminfo/imagestorage/driver.go similarity index 100% rename from src/adminserver/systeminfo/imagestorage/driver.go rename to src/core/systeminfo/imagestorage/driver.go diff --git a/src/adminserver/systeminfo/imagestorage/filesystem/driver.go b/src/core/systeminfo/imagestorage/filesystem/driver.go similarity index 96% rename from src/adminserver/systeminfo/imagestorage/filesystem/driver.go rename to src/core/systeminfo/imagestorage/filesystem/driver.go index 2e449c7b0..b30c1741e 100644 --- a/src/adminserver/systeminfo/imagestorage/filesystem/driver.go +++ b/src/core/systeminfo/imagestorage/filesystem/driver.go @@ -19,8 +19,8 @@ import ( "reflect" "syscall" - storage "github.com/goharbor/harbor/src/adminserver/systeminfo/imagestorage" "github.com/goharbor/harbor/src/common/utils/log" + storage "github.com/goharbor/harbor/src/core/systeminfo/imagestorage" ) const ( diff --git a/src/adminserver/systeminfo/imagestorage/filesystem/driver_test.go b/src/core/systeminfo/imagestorage/filesystem/driver_test.go similarity index 93% rename from src/adminserver/systeminfo/imagestorage/filesystem/driver_test.go rename to src/core/systeminfo/imagestorage/filesystem/driver_test.go index 607be4334..2e53dee3d 100644 --- a/src/adminserver/systeminfo/imagestorage/filesystem/driver_test.go +++ b/src/core/systeminfo/imagestorage/filesystem/driver_test.go @@ -17,7 +17,7 @@ package filesystem import ( "testing" - storage "github.com/goharbor/harbor/src/adminserver/systeminfo/imagestorage" + storage "github.com/goharbor/harbor/src/core/systeminfo/imagestorage" "github.com/stretchr/testify/assert" ) diff --git a/src/adminserver/systeminfo/systeminfo.go b/src/core/systeminfo/systeminfo.go similarity index 84% rename from src/adminserver/systeminfo/systeminfo.go rename to src/core/systeminfo/systeminfo.go index b2c20751f..3939c0c83 100644 --- a/src/adminserver/systeminfo/systeminfo.go +++ b/src/core/systeminfo/systeminfo.go @@ -17,8 +17,8 @@ package systeminfo import ( "os" - "github.com/goharbor/harbor/src/adminserver/systeminfo/imagestorage" - "github.com/goharbor/harbor/src/adminserver/systeminfo/imagestorage/filesystem" + "github.com/goharbor/harbor/src/core/systeminfo/imagestorage" + "github.com/goharbor/harbor/src/core/systeminfo/imagestorage/filesystem" ) // Init image storage driver