fix: create docker-compose k8s app name exists (#1574)

Co-authored-by: 曲源成 <quyc@goodrain.com>
This commit is contained in:
Quyc 2023-03-03 11:35:35 +08:00 committed by GitHub
parent d950870433
commit 6b6c151e8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 0 deletions

View File

@ -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)

View File

@ -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())

View File

@ -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

View File

@ -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 {

View File

@ -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

View File

@ -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