fix: endpoint mode slave (#24016)

Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
Jian Qiu
2026-01-06 18:05:41 +08:00
committed by GitHub
parent de05b050e4
commit f50f83feb1
63 changed files with 351 additions and 281 deletions

View File

@@ -269,15 +269,15 @@ func (ep *SEndpoint) getService() *SService {
}
type SEndpointExtended struct {
Id string
Name string
Interface string
Url string
Region string
RegionId string
ServiceId string
ServiceType string
ServiceName string
Id string `json:"id"`
Name string `json:"name"`
Interface string `json:"interface"`
Url string `json:"url"`
Region string `json:"region"`
RegionId string `json:"region_id"`
ServiceId string `json:"service_id"`
ServiceType string `json:"service_type"`
ServiceName string `json:"service_name"`
}
type SServiceCatalog []SEndpointExtended
@@ -493,7 +493,8 @@ func (manager *SEndpointManager) ValidateCreateData(
}
service := servObj.(*SService)
if !data.Contains("name") {
data.Set("name", jsonutils.NewString(fmt.Sprintf("%s-%s", service.Type, infname)))
nameStr := fmt.Sprintf("%s-%s", service.Type, infname)
data.Set("name", jsonutils.NewString(nameStr))
}
data.Set("service_id", jsonutils.NewString(service.Id))
} else {
@@ -550,10 +551,7 @@ func (manager *SEndpointManager) ListItemFilter(
}
}
if len(query.Interface) > 0 {
infType := query.Interface
if strings.HasSuffix(infType, "URL") {
infType = infType[0 : len(infType)-3]
}
infType := strings.TrimSuffix(query.Interface, "URL")
q = q.Equals("interface", infType)
}
return q, nil

View File

@@ -32,18 +32,18 @@ const (
API_VERSION = "v3"
)
func InitHandlers(app *appsrv.Application) {
func InitHandlers(app *appsrv.Application, isSlave bool) {
db.InitAllManagers()
// add version handler with API_VERSION prefix
app.AddDefaultHandler("GET", API_VERSION+"/version", appsrv.VersionHandler, "version")
cronjobs.AddRefreshHandler(API_VERSION, app)
quotas.AddQuotaHandler(&models.IdentityQuotaManager.SQuotaBaseManager, API_VERSION, app)
quotas.AddQuotaHandler(&models.IdentityQuotaManager.SQuotaBaseManager, API_VERSION, app, isSlave)
usages.AddUsageHandler(API_VERSION, app)
taskman.AddTaskHandler(API_VERSION, app)
taskman.AddTaskHandler(API_VERSION, app, isSlave)
app_common.ExportOptionsHandlerWithPrefix(app, API_VERSION, &options.Options)
@@ -108,7 +108,7 @@ func InitHandlers(app *appsrv.Application) {
} {
db.RegisterModelManager(manager)
handler := db.NewModelHandler(manager)
dispatcher.AddModelDispatcher(API_VERSION, app, handler)
dispatcher.AddModelDispatcher(API_VERSION, app, handler, isSlave)
}
models.AddAdhocHandlers(API_VERSION, app)

View File

@@ -86,7 +86,7 @@ func StartService() {
cloudcommon.InitDB(&opts.DBOptions)
InitHandlers(app)
InitHandlers(app, opts.IsSlaveNode)
db.EnsureAppSyncDB(app, &opts.DBOptions, models.InitDB)
@@ -94,7 +94,7 @@ func StartService() {
common_options.StartOptionManagerWithSessionDriver(opts, opts.ConfigSyncPeriodSeconds, api.SERVICE_TYPE, "", options.OnOptionsChange, models.NewServiceConfigSession())
{
if !opts.IsSlaveNode {
err := models.UserManager.EnforceUserMfa(context.Background())
if err != nil {
log.Errorf("EnforceUserMfa fail %s", err)