mirror of
https://github.com/kubevela/kubevela.git
synced 2026-02-14 18:10:21 +00:00
implemented component delete API
This commit is contained in:
@@ -335,6 +335,16 @@ sample response
|
||||
### GET /api/envs/:envName/apps/:appName/components/ (component list)
|
||||
Same as `GET /api/envs/:envName/apps/:appName (app description)`.
|
||||
|
||||
### DELETE /api/envs/:envName/apps/:appName/components/:compName (component delete)
|
||||
- example
|
||||
sample response
|
||||
```
|
||||
{
|
||||
"code": 200,
|
||||
"data": "delete apps succeed a1 from default"
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## Workloads
|
||||
### POST /api/workloads/ (workload create, component create)
|
||||
|
||||
@@ -17,10 +17,10 @@ import (
|
||||
)
|
||||
|
||||
type ComponentMeta struct {
|
||||
// Name string `json:"name"`
|
||||
App string `json:"app"`
|
||||
// Workload string `json:"workload,omitempty"`
|
||||
// Traits []string `json:"traits,omitempty"`
|
||||
Name string `json:"name"`
|
||||
App string `json:"app"`
|
||||
Workload string `json:"workload,omitempty"`
|
||||
Traits []string `json:"traits,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
CreatedTime string `json:"created,omitempty"`
|
||||
AppConfig corev1alpha2.ApplicationConfiguration `json:"-"`
|
||||
|
||||
@@ -26,3 +26,23 @@ func GetComponent(c *gin.Context) {
|
||||
}
|
||||
util.AssembleResponse(c, componentMeta, nil)
|
||||
}
|
||||
|
||||
func DeleteComponent(c *gin.Context) {
|
||||
kubeClient := c.MustGet("KubeClient")
|
||||
envName := c.Param("envName")
|
||||
envMeta, err := oam.GetEnvByName(envName)
|
||||
if err != nil {
|
||||
util.HandleError(c, util.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
appName := c.Param("appName")
|
||||
componentName := c.Param("compName")
|
||||
|
||||
o := oam.DeleteOptions{
|
||||
Client: kubeClient.(client.Client),
|
||||
Env: envMeta,
|
||||
AppName: appName,
|
||||
CompName: componentName}
|
||||
message, err := o.DeleteComponent()
|
||||
util.AssembleResponse(c, message, err)
|
||||
}
|
||||
|
||||
@@ -20,31 +20,32 @@ import (
|
||||
func main() {
|
||||
var development = true
|
||||
// setup logging
|
||||
var w io.Writer
|
||||
w = os.Stdout
|
||||
var w io.Writer = os.Stdout
|
||||
|
||||
ctrl.SetLogger(zap.New(func(o *zap.Options) {
|
||||
o.Development = development
|
||||
o.DestWritter = w
|
||||
}))
|
||||
server := server.APIServer{}
|
||||
apiServer := server.APIServer{}
|
||||
kubeClient, err := oam.InitKubeClient()
|
||||
if err != nil {
|
||||
ctrl.Log.Error(err, "failed to init an Kubernetes client")
|
||||
os.Exit(1)
|
||||
}
|
||||
errCh := make(chan error, 1)
|
||||
server.Launch(kubeClient, util.DefaultAPIServerPort, "", errCh)
|
||||
select {
|
||||
case err = <-errCh:
|
||||
apiServer.Launch(kubeClient, util.DefaultAPIServerPort, "", errCh)
|
||||
err = <-errCh
|
||||
if err != nil {
|
||||
ctrl.Log.Error(err, "failed to launch API server")
|
||||
}
|
||||
// handle signal: SIGTERM(15)
|
||||
sc := make(chan os.Signal, 1)
|
||||
signal.Notify(sc, syscall.SIGTERM)
|
||||
select {
|
||||
case <-sc:
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Minute)
|
||||
go server.Shutdown(ctx)
|
||||
<-sc
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
if err := apiServer.Shutdown(ctx); err != nil {
|
||||
ctrl.Log.Error(err, "failed to shut down API server")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ func setupRoute(kubeClient client.Client, staticPath string) http.Handler {
|
||||
components.GET("/:compName", handler.GetComponent)
|
||||
components.PUT("/:compName", handler.GetComponent)
|
||||
components.GET("/", handler.GetApp)
|
||||
components.DELETE("/:compName", handler.GetComponent)
|
||||
components.DELETE("/:compName", handler.DeleteComponent)
|
||||
|
||||
traitWorkload := components.Group("/:compName/" + util.TraitDefinitionPath)
|
||||
{
|
||||
@@ -82,9 +82,7 @@ func setupRoute(kubeClient client.Client, staticPath string) http.Handler {
|
||||
traitWorkload.DELETE("/:traitName", handler.DetachTrait)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
// workload related api
|
||||
workload := api.Group(util.WorkloadDefinitionPath)
|
||||
|
||||
Reference in New Issue
Block a user