mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-19 04:26:39 +00:00
Feat: add Addon REST API (#2369)
This commit is contained in:
@@ -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"`
|
||||
}
|
||||
@@ -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"`
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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{})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user