diff --git a/pkg/apiserver/rest/apis/v1/catalog.go b/pkg/apiserver/rest/apis/v1/catalog.go deleted file mode 100644 index b3b9e7130..000000000 --- a/pkg/apiserver/rest/apis/v1/catalog.go +++ /dev/null @@ -1,41 +0,0 @@ -/* -Copyright 2021 The KubeVela 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 v1 - -import ( - "github.com/oam-dev/kubevela/pkg/apiserver/model" -) - -// CatalogRequest defines the body of catalog request -type CatalogRequest struct { - Name string `json:"name"` - Desc string `json:"desc,omitempty"` - UpdateAt int64 `json:"updateAt,omitempty"` - Type string `json:"type,omitempty"` - URL string `json:"url,omitempty"` - Token string `json:"token,omitempty"` -} - -// CatalogResponse defines the body of catalog response -type CatalogResponse struct { - Catalog *model.Catalog `json:"catalog"` -} - -// CatalogListResponse defines the body of catalog list response -type CatalogListResponse struct { - Catalogs []*model.Catalog `json:"catalogs,omitempty"` -} diff --git a/pkg/apiserver/rest/apis/v1/types.go b/pkg/apiserver/rest/apis/v1/types.go index 318494251..4fb52ca36 100644 --- a/pkg/apiserver/rest/apis/v1/types.go +++ b/pkg/apiserver/rest/apis/v1/types.go @@ -20,6 +20,81 @@ import ( "time" ) +// AddonPhase defines the phase of an addon +type AddonPhase string + +const ( + // AddonPhaseDisabled indicates the addon is disabled + AddonPhaseDisabled AddonPhase = "disabled" + // AddonPhaseDisabling indicates the addon is disabling + AddonPhaseDisabling AddonPhase = "disabling" + // AddonPhaseEnabled indicates the addon is enabled + AddonPhaseEnabled AddonPhase = "enabled" + // AddonPhaseEnabling indicates the addon is enabling + AddonPhaseEnabling AddonPhase = "enabling" +) + +// CreateAddonRequest defines the format for addon create request +type CreateAddonRequest struct { + Name string `json:"name" validate:"required"` + + Version string `json:"version" validate:"required"` + + // Short description about the addon. + Description string `json:"description,omitempty"` + + Icon string `json:"icon"` + + Tags []string `json:"tags"` + + // The detail of the addon. Could be the entire README data. + Detail string `json:"detail,omitempty"` + + // DeployData is the object to deploy to the cluster to enable addon + DeployData string `json:"deploy_data,omitempty" validate:"required_without=deploy_url"` + + // DeployURL is the URL to the data file location in a Git repository + DeployURL string `json:"deploy_url,omitempty" validate:"required_without=deploy_data"` +} + +// ListAddonResponse defines the format for addon list response +type ListAddonResponse struct { + Addons []AddonMeta `json:"addons"` +} + +// AddonMeta defines the format for a single addon +type AddonMeta struct { + Name string `json:"name"` + + Version string `json:"version"` + + Description string `json:"description"` + + Icon string `json:"icon"` + + Tags []string `json:"tags"` + + Phase AddonPhase `json:"phase"` +} + +// DetailAddonResponse defines the format for showing the addon details +type DetailAddonResponse struct { + AddonMeta + + Detail string `json:"detail,omitempty"` + + // DeployData is the object to deploy to the cluster to enable addon + DeployData string `json:"deploy_data,omitempty"` + + // DeployURL is the URL to the data file location in a Git repository + DeployURL string `json:"deploy_url,omitempty"` +} + +// AddonStatusResponse defines the format of addon status response +type AddonStatusResponse struct { + Phase AddonPhase `json:"phase"` +} + // CreateClusterRequest request parameters to create a cluster type CreateClusterRequest struct { Name string `json:"name" validate:"required"` @@ -65,23 +140,6 @@ type ClusterBase struct { Reason string `json:"reason"` } -// ListClusterAddonResponse list all addon of the cluster -type ListClusterAddonResponse struct { - Addons []ClusterAddonBase `json:"addons"` -} - -// ClusterAddonBase cluster addon base model -type ClusterAddonBase struct { - Name string `json:"name"` - Description string `json:"description"` - Status string `json:"status"` -} - -// DeatilClusterAddonResponse detail addon info -type DeatilClusterAddonResponse struct { - ClusterAddonBase -} - // ListApplicationResponse list applications by query params type ListApplicationResponse struct { Applications []*ApplicationBase `json:"applications"` diff --git a/pkg/apiserver/rest/webservice/addon.go b/pkg/apiserver/rest/webservice/addon.go new file mode 100644 index 000000000..182266c31 --- /dev/null +++ b/pkg/apiserver/rest/webservice/addon.go @@ -0,0 +1,88 @@ +/* +Copyright 2021 The KubeVela 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 webservice + +import ( + restfulspec "github.com/emicklei/go-restful-openapi/v2" + "github.com/emicklei/go-restful/v3" + + apis "github.com/oam-dev/kubevela/pkg/apiserver/rest/apis/v1" +) + +type addonWebService struct { +} + +func (c *addonWebService) GetWebService() *restful.WebService { + ws := new(restful.WebService) + ws.Path("/v1/addons"). + Consumes(restful.MIME_XML, restful.MIME_JSON). + Produces(restful.MIME_JSON, restful.MIME_XML). + Doc("api for addon management") + + tags := []string{"addon"} + + // List + ws.Route(ws.GET("/").To(noop). + Doc("list all addons"). + Metadata(restfulspec.KeyOpenAPITags, tags). + Param(ws.QueryParameter("cluster", "Cluster-based search").DataType("string")). + Writes(apis.ListAddonResponse{}).Do(returns200, returns500)) + + // Create + ws.Route(ws.POST("/").To(noop). + Doc("create an addon"). + Metadata(restfulspec.KeyOpenAPITags, tags). + Reads(apis.CreateAddonRequest{}). + Writes(apis.AddonMeta{})) + + // Delete + ws.Route(ws.DELETE("/{name}").To(noop). + Doc("delete an addon"). + Metadata(restfulspec.KeyOpenAPITags, tags). + Param(ws.PathParameter("name", "identifier of the addon").DataType("string")). + Writes(apis.AddonMeta{})) + + // GET + ws.Route(ws.GET("/{name}").To(noop). + Doc("show details of an addon"). + Metadata(restfulspec.KeyOpenAPITags, tags). + Param(ws.PathParameter("name", "identifier of the addon").DataType("string")). + Writes(apis.DetailAddonResponse{})) + + // GET status + ws.Route(ws.GET("/{name}/status").To(noop). + Doc("show status of an addon"). + Metadata(restfulspec.KeyOpenAPITags, tags). + Param(ws.PathParameter("name", "identifier of the addon").DataType("string")). + Writes(apis.AddonStatusResponse{})) + + // vela enable addon + ws.Route(ws.POST("/{name}/enable").To(noop). + Doc("enable an addon on a cluster"). + Metadata(restfulspec.KeyOpenAPITags, tags). + Param(ws.QueryParameter("cluster", "cluster name").DataType("string")). + Writes(apis.AddonMeta{})) + + // vela disable addon + ws.Route(ws.POST("/{name}/disable").To(noop). + Doc("disable an addon on a cluster"). + Metadata(restfulspec.KeyOpenAPITags, tags). + Param(ws.QueryParameter("cluster", "cluster name").DataType("string")). + Writes(apis.AddonMeta{})) + + return ws +} diff --git a/pkg/apiserver/rest/webservice/catalog.go b/pkg/apiserver/rest/webservice/catalog.go deleted file mode 100644 index aaa8a697d..000000000 --- a/pkg/apiserver/rest/webservice/catalog.go +++ /dev/null @@ -1,45 +0,0 @@ -/* -Copyright 2021 The KubeVela 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 webservice - -import ( - restfulspec "github.com/emicklei/go-restful-openapi/v2" - restful "github.com/emicklei/go-restful/v3" - - apis "github.com/oam-dev/kubevela/pkg/apiserver/rest/apis/v1" -) - -type catalogWebService struct { -} - -func (c *catalogWebService) GetWebService() *restful.WebService { - ws := new(restful.WebService) - ws.Path("/v1/catalogs"). - Consumes(restful.MIME_XML, restful.MIME_JSON). - Produces(restful.MIME_JSON, restful.MIME_XML). - Doc("api for cluster manage") - - tags := []string{"cluster"} - - ws.Route(ws.GET("/").To(noop). - Doc("list all clusters"). - Metadata(restfulspec.KeyOpenAPITags, tags). - Param(ws.QueryParameter("query", "Fuzzy search based on name or description").DataType("string")). - Writes(apis.ListClusterResponse{}).Do(returns200, returns500)) - - return ws -} diff --git a/pkg/apiserver/rest/webservice/webservice.go b/pkg/apiserver/rest/webservice/webservice.go index ed8fb5c6a..690bb3fe8 100644 --- a/pkg/apiserver/rest/webservice/webservice.go +++ b/pkg/apiserver/rest/webservice/webservice.go @@ -20,7 +20,7 @@ import ( "context" "net/http" - restful "github.com/emicklei/go-restful/v3" + "github.com/emicklei/go-restful/v3" "github.com/go-playground/validator/v10" ) @@ -62,6 +62,6 @@ func Init(ctx context.Context) { RegistWebService(&applicationWebService{}) RegistWebService(&namespaceWebService{}) RegistWebService(&componentDefinitionWebservice{}) - RegistWebService(&catalogWebService{}) + RegistWebService(&addonWebService{}) RegistWebService(&oamApplicationWebService{}) }