Skip to content

Commit

Permalink
feat:新增配置控制是否允许自动创建服务 (polarismesh#1285)
Browse files Browse the repository at this point in the history
Co-authored-by: dongsheng.qi <[email protected]>
  • Loading branch information
qdsordinarydream and dongsheng.qi authored Nov 7, 2023
1 parent ef29b8b commit 3df1d28
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions release/conf/polaris-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ naming:
waitTime: 32ms
maxBatchCount: 128
concurrency: 128
# Whether to allow automatic creation of service
autoCreate: true
# Configuration of health check
healthcheck:
# Whether to open the health check function module
Expand Down
2 changes: 2 additions & 0 deletions release/standalone/docker-compose/server/polaris-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ naming:
waitTime: 32ms
maxBatchCount: 32
concurrency: 64
# Whether to allow automatic creation of service
autoCreate: true
# 健康检查的配置
healthcheck:
open: true
Expand Down
5 changes: 3 additions & 2 deletions service/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ var (

// Config 核心逻辑层配置
type Config struct {
L5Open bool `yaml:"l5Open"`
Batch map[string]interface{} `yaml:"batch"`
L5Open bool `yaml:"l5Open"`
AutoCreate bool `yaml:"autoCreate"`
Batch map[string]interface{} `yaml:"batch"`
}

// Initialize 初始化
Expand Down
4 changes: 4 additions & 0 deletions service/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,10 @@ func (s *Server) createServiceIfAbsent(
if svc != nil {
return svc.ID, nil
}
// if auto_create_service config is false, return service not found
if !s.allowAutoCreate() {
return "", api.NewResponse(apimodel.Code_NotFoundService)
}
simpleService := &apiservice.Service{
Name: utils.NewStringValue(svcName),
Namespace: utils.NewStringValue(namespace),
Expand Down
4 changes: 4 additions & 0 deletions service/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func (s *Server) isSupportL5() bool {
return s.config.L5Open
}

func (s *Server) allowAutoCreate() bool {
return s.config.AutoCreate
}

// HealthServer 健康检查Server
func (s *Server) HealthServer() *healthcheck.Server {
return s.healthServer
Expand Down

0 comments on commit 3df1d28

Please sign in to comment.