Skip to content

Commit

Permalink
fix: rm inheritConfig param
Browse files Browse the repository at this point in the history
Signed-off-by: xu.zhu <[email protected]>
  • Loading branch information
xuzhu-591 committed Jun 2, 2023
1 parent 736591f commit ff91d39
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 105 deletions.
1 change: 0 additions & 1 deletion core/common/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const (
ClusterQueryTagSelector = "tagSelector"
ClusterQueryScope = "scope"
ClusterQueryMergePatch = "mergePatch"
ClusterQueryInheritConfig = "inheritConfig"
ClusterQueryTargetBranch = "targetBranch"
ClusterQueryTargetCommit = "targetCommit"
ClusterQueryTargetTag = "targetTag"
Expand Down
64 changes: 27 additions & 37 deletions core/controller/cluster/controller_basic_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ func (c *controller) CreateClusterV2(ctx context.Context,
return nil, err
}
}
if params.Git.URL == "" && !params.InheritConfig {
return nil, perror.Wrap(herrors.ErrParamInvalid, "git url is required")
}
}
if params.Image != nil {
if err := validate.CheckImageURL(*params.Image); err != nil {
Expand Down Expand Up @@ -177,7 +174,7 @@ func (c *controller) CreateClusterV2(ctx context.Context,

// 8. customize db infos
cluster, tags := params.CreateClusterRequestV2.toClusterModel(application,
envEntity, buildTemplateInfo, expireSeconds, params.InheritConfig)
envEntity, buildTemplateInfo, expireSeconds)

// 9. update db and tags
clusterResp, err := c.clusterMgr.Create(ctx, cluster, tags, params.ExtraMembers)
Expand Down Expand Up @@ -592,45 +589,38 @@ func (c *controller) customizeCreateReqBuildTemplateInfo(ctx context.Context, pa
return nil, err
}

if params.InheritConfig {
// inherit config from application if it's empty in the request
buildTemplateInfo.BuildConfig = appGitRepoFile.BuildConf
buildTemplateInfo.TemplateInfo = &codemodels.TemplateInfo{
Name: application.Template,
Release: application.TemplateRelease,
}
buildTemplateInfo.TemplateConfig = appGitRepoFile.TemplateConf

if params.BuildConfig != nil {
if params.MergePatch {
buildTemplateInfo.BuildConfig, err = mergemap.Merge(appGitRepoFile.BuildConf, params.BuildConfig)
if err != nil {
return nil, err
}
} else {
buildTemplateInfo.BuildConfig = params.BuildConfig
// inherit config from application if it's empty in the request
buildTemplateInfo.BuildConfig = appGitRepoFile.BuildConf
buildTemplateInfo.TemplateInfo = &codemodels.TemplateInfo{
Name: application.Template,
Release: application.TemplateRelease,
}
buildTemplateInfo.TemplateConfig = appGitRepoFile.TemplateConf

if params.BuildConfig != nil {
if params.MergePatch {
buildTemplateInfo.BuildConfig, err = mergemap.Merge(appGitRepoFile.BuildConf, params.BuildConfig)
if err != nil {
return nil, err
}
} else {
buildTemplateInfo.BuildConfig = params.BuildConfig
}
}

if params.TemplateInfo != nil {
buildTemplateInfo.TemplateInfo = params.TemplateInfo
}
if params.TemplateInfo != nil {
buildTemplateInfo.TemplateInfo = params.TemplateInfo
}

if params.TemplateConfig != nil {
if params.MergePatch {
buildTemplateInfo.TemplateConfig, err = mergemap.Merge(appGitRepoFile.TemplateConf, params.TemplateConfig)
if err != nil {
return nil, err
}
} else {
buildTemplateInfo.TemplateConfig = params.TemplateConfig
if params.TemplateConfig != nil {
if params.MergePatch {
buildTemplateInfo.TemplateConfig, err = mergemap.Merge(appGitRepoFile.TemplateConf, params.TemplateConfig)
if err != nil {
return nil, err
}
} else {
buildTemplateInfo.TemplateConfig = params.TemplateConfig
}
} else {
// use the config in the request directly
buildTemplateInfo.BuildConfig = params.BuildConfig
buildTemplateInfo.TemplateInfo = params.TemplateInfo
buildTemplateInfo.TemplateConfig = params.TemplateConfig
}
return buildTemplateInfo, nil
}
Expand Down
1 change: 0 additions & 1 deletion core/controller/cluster/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,6 @@ func testV2(t *testing.T) {
Environment: "test2",
Region: "hz",
MergePatch: false,
InheritConfig: true,
})
assert.Nil(t, err)
assert.NotNil(t, resp)
Expand Down
80 changes: 33 additions & 47 deletions core/controller/cluster/models_basic_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type CreateClusterRequestV2 struct {

func (r *CreateClusterRequestV2) toClusterModel(application *appmodels.Application,
er *envregionmodels.EnvironmentRegion, info *BuildTemplateInfo,
expireSeconds uint, inheritConfig bool) (*models.Cluster, []*tagmodels.Tag) {
expireSeconds uint) (*models.Cluster, []*tagmodels.Tag) {
cluster := &models.Cluster{
ApplicationID: application.ID,
Name: r.Name,
Expand All @@ -56,52 +56,40 @@ func (r *CreateClusterRequestV2) toClusterModel(application *appmodels.Applicati
TemplateRelease: info.TemplateInfo.Release,
Status: common.ClusterStatusCreating,
}
if inheritConfig {
cluster.GitURL = func() string {
if r.Git == nil {
return application.GitURL
}
if r.Git.URL == "" && application.GitURL != "" {
return application.GitURL
}
// if URL is empty string, this means this cluster not depends on build from git
return r.Git.URL
}()
cluster.GitSubfolder = func() string {
if r.Git == nil || r.Git.Subfolder == "" {
return application.GitSubfolder
}
return r.Git.Subfolder
}()
cluster.GitRef = func() string {
if r.Git == nil {
return application.GitRef
}
return r.Git.Ref()
}()
cluster.GitRefType = func() string {
if r.Git == nil {
return application.GitRefType
}
return r.Git.RefType()
}()
cluster.Image = func() string {
if r.Image == nil {
return application.Image
}
return *r.Image
}()
} else {
if r.Git != nil {
cluster.GitURL = r.Git.URL
cluster.GitSubfolder = r.Git.Subfolder
cluster.GitRef = r.Git.Ref()
cluster.GitRefType = r.Git.RefType()
cluster.GitURL = func() string {
if r.Git == nil {
return application.GitURL
}
if r.Image != nil {
cluster.Image = *r.Image
if r.Git.URL == "" && application.GitURL != "" {
return application.GitURL
}
}
// if URL is empty string, this means this cluster not depends on build from git
return r.Git.URL
}()
cluster.GitSubfolder = func() string {
if r.Git == nil || r.Git.Subfolder == "" {
return application.GitSubfolder
}
return r.Git.Subfolder
}()
cluster.GitRef = func() string {
if r.Git == nil {
return application.GitRef
}
return r.Git.Ref()
}()
cluster.GitRefType = func() string {
if r.Git == nil {
return application.GitRefType
}
return r.Git.RefType()
}()
cluster.Image = func() string {
if r.Image == nil {
return application.Image
}
return *r.Image
}()
tags := make([]*tagmodels.Tag, 0)
for _, tag := range r.Tags {
tags = append(tags, &tagmodels.Tag{
Expand Down Expand Up @@ -228,6 +216,4 @@ type CreateClusterParamsV2 struct {
Region string
// whether to merge json schema form data
MergePatch bool
// whether to inherit config from application
InheritConfig bool
}
12 changes: 0 additions & 12 deletions core/http/api/v2/cluster/apis_basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,6 @@ func (a *API) Create(c *gin.Context) {
}
}

inheritConfig := true
inheritConfigStr := c.Request.URL.Query().Get(common.ClusterQueryInheritConfig)
if inheritConfigStr != "" {
inheritConfig, err = strconv.ParseBool(inheritConfigStr)
if err != nil {
response.AbortWithRequestError(c, common.InvalidRequestParam,
fmt.Sprintf("inheritConfig is invalid, err: %v", err))
return
}
}

extraOwners := c.QueryArray(common.ClusterQueryExtraOwner)

var request *cluster.CreateClusterRequestV2
Expand Down Expand Up @@ -251,7 +240,6 @@ func (a *API) Create(c *gin.Context) {
Environment: environment,
Region: region,
MergePatch: mergePatch,
InheritConfig: inheritConfig,
})
if err != nil {
if e, ok := perror.Cause(err).(*herrors.HorizonErrNotFound); ok && e.Source == herrors.ApplicationInDB {
Expand Down
7 changes: 0 additions & 7 deletions openapi/v2/restful/cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,6 @@ paths:
schema:
type: boolean
default: false
- name: inheritConfig
in: query
description: whether to inherit build and deploy configs from app if not set
required: false
schema:
type: boolean
default: true
post:
tags:
- cluster
Expand Down

0 comments on commit ff91d39

Please sign in to comment.