mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-01 19:28:05 +08:00
fix: create docker-compose k8s app name exists (#1574)
Co-authored-by: 曲源成 <quyc@goodrain.com>
This commit is contained in:
parent
d950870433
commit
6b6c151e8a
@ -208,6 +208,7 @@ type ApplicationInterface interface {
|
||||
ListComponents(w http.ResponseWriter, r *http.Request)
|
||||
BatchBindService(w http.ResponseWriter, r *http.Request)
|
||||
DeleteApp(w http.ResponseWriter, r *http.Request)
|
||||
DeleteK8sApp(w http.ResponseWriter, r *http.Request)
|
||||
AddConfigGroup(w http.ResponseWriter, r *http.Request)
|
||||
UpdateConfigGroup(w http.ResponseWriter, r *http.Request)
|
||||
|
||||
|
@ -192,6 +192,7 @@ func (v2 *V2) tenantNameRouter() chi.Router {
|
||||
r.Post("/apps", controller.GetManager().CreateApp)
|
||||
r.Post("/batch_create_apps", controller.GetManager().BatchCreateApp)
|
||||
r.Get("/apps", controller.GetManager().ListApps)
|
||||
r.Delete("/k8s-app/{k8s_app}", controller.GetManager().DeleteK8sApp)
|
||||
r.Post("/checkResourceName", controller.GetManager().CheckResourceName)
|
||||
r.Get("/appstatuses", controller.GetManager().ListAppStatuses)
|
||||
r.Mount("/apps/{app_id}", v2.applicationRouter())
|
||||
|
@ -181,6 +181,20 @@ func (a *ApplicationController) DeleteApp(w http.ResponseWriter, r *http.Request
|
||||
httputil.ReturnSuccess(r, w, nil)
|
||||
}
|
||||
|
||||
// DeleteK8sApp -
|
||||
func (a *ApplicationController) DeleteK8sApp(w http.ResponseWriter, r *http.Request) {
|
||||
appID := chi.URLParam(r, "k8s_app")
|
||||
// get current tenant
|
||||
tenant := r.Context().Value(ctxutil.ContextKey("tenant")).(*dbmodel.Tenants)
|
||||
// Delete application by k8sapp
|
||||
err := handler.GetApplicationHandler().DeleteAppByK8sApp(tenant.UUID, appID)
|
||||
if err != nil {
|
||||
httputil.ReturnBcodeError(r, w, err)
|
||||
return
|
||||
}
|
||||
httputil.ReturnSuccess(r, w, nil)
|
||||
}
|
||||
|
||||
// BatchUpdateComponentPorts update component ports in batch.
|
||||
func (a *ApplicationController) BatchUpdateComponentPorts(w http.ResponseWriter, r *http.Request) {
|
||||
var appPorts []*model.AppPort
|
||||
|
@ -54,6 +54,7 @@ type ApplicationHandler interface {
|
||||
GetAppByID(appID string) (*dbmodel.Application, error)
|
||||
BatchBindService(appID string, req model.BindServiceRequest) error
|
||||
DeleteApp(ctx context.Context, app *dbmodel.Application) error
|
||||
DeleteAppByK8sApp(tenantID, K8sApp string) error
|
||||
|
||||
AddConfigGroup(appID string, req *model.ApplicationConfigGroup) (*model.ApplicationConfigGroupResp, error)
|
||||
UpdateConfigGroup(appID, configGroupName string, req *model.UpdateAppConfigGroupReq) (*model.ApplicationConfigGroupResp, error)
|
||||
@ -424,6 +425,15 @@ func (a *ApplicationAction) DeleteApp(ctx context.Context, app *dbmodel.Applicat
|
||||
return a.deleteRainbondApp(app)
|
||||
}
|
||||
|
||||
// DeleteAppByK8sApp -
|
||||
func (a *ApplicationAction) DeleteAppByK8sApp(tenantID, k8sApp string) error {
|
||||
err := db.GetManager().ApplicationDao().DeleteAppByK8sApp(tenantID, k8sApp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *ApplicationAction) deleteRainbondApp(app *dbmodel.Application) error {
|
||||
// can't delete rainbond app with components
|
||||
if err := a.isContainComponents(app.AppID); err != nil {
|
||||
|
@ -78,6 +78,7 @@ type ApplicationDao interface {
|
||||
ListByAppIDs(appIDs []string) ([]*model.Application, error)
|
||||
IsK8sAppDuplicate(tenantID, AppID, k8sApp string) bool
|
||||
GetAppByName(tenantID, k8sAppName string) (*model.Application, error)
|
||||
DeleteAppByK8sApp(tenantID, k8sAppName string) error
|
||||
}
|
||||
|
||||
//AppConfigGroupDao Application config group Dao
|
||||
|
@ -87,6 +87,18 @@ func (a *ApplicationDaoImpl) DeleteApp(appID string) error {
|
||||
return a.DB.Delete(&app).Error
|
||||
}
|
||||
|
||||
// DeleteAppByK8sApp Delete application By k8sApp -
|
||||
func (a *ApplicationDaoImpl) DeleteAppByK8sApp(tenantID, k8sApp string) error {
|
||||
var app model.Application
|
||||
if err := a.DB.Where("tenant_id=? and k8s_app=?", tenantID, k8sApp).Find(&app).Error; err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return bcode.ErrApplicationNotFound
|
||||
}
|
||||
return err
|
||||
}
|
||||
return a.DB.Delete(&app).Error
|
||||
}
|
||||
|
||||
// ListByAppIDs -
|
||||
func (a *ApplicationDaoImpl) ListByAppIDs(appIDs []string) ([]*model.Application, error) {
|
||||
var datas []*model.Application
|
||||
|
Loading…
Reference in New Issue
Block a user