From 8aeb8ddbf4a02a824b5974dcefe0f54c14a534b4 Mon Sep 17 00:00:00 2001 From: Taekyu Date: Fri, 8 Sep 2023 09:44:43 +0900 Subject: [PATCH 1/2] feature. refactoring infra conf --- api/swagger/docs.go | 169 +++++++++++++++++++++--------- api/swagger/swagger.json | 169 +++++++++++++++++++++--------- api/swagger/swagger.yaml | 138 ++++++++++++++++-------- internal/repository/cluster.go | 93 ++++++++-------- internal/usecase/app-serve-app.go | 12 +-- internal/usecase/cluster.go | 20 ++-- internal/usecase/stack.go | 12 ++- pkg/domain/cluster.go | 106 +++++++++++-------- pkg/domain/stack.go | 53 ++++++---- 9 files changed, 499 insertions(+), 273 deletions(-) diff --git a/api/swagger/docs.go b/api/swagger/docs.go index fbfc0d1a..23696710 100644 --- a/api/swagger/docs.go +++ b/api/swagger/docs.go @@ -3725,6 +3725,10 @@ const docTemplate = `{ "description": "endpoint URL of deployed app", "type": "string" }, + "grafanaUrl": { + "description": "grafana dashboard URL for deployed app", + "type": "string" + }, "id": { "type": "string" }, @@ -4120,22 +4124,31 @@ const docTemplate = `{ "domain.ClusterConf": { "type": "object", "properties": { - "cpNodeCnt": { + "tksCpNode": { + "type": "integer" + }, + "tksCpNodeMax": { "type": "integer" }, - "cpNodeMachineType": { + "tksCpNodeType": { "type": "string" }, - "tksNodeCnt": { + "tksInfraNode": { "type": "integer" }, - "tksNodeMachineType": { + "tksInfraNodeMax": { + "type": "integer" + }, + "tksInfraNodeType": { "type": "string" }, - "userNodeCnt": { + "tksUserNode": { + "type": "integer" + }, + "tksUserNodeMax": { "type": "integer" }, - "userNodeMachineType": { + "tksUserNodeType": { "type": "string" } } @@ -4143,14 +4156,32 @@ const docTemplate = `{ "domain.ClusterConfResponse": { "type": "object", "properties": { - "cpNodeCnt": { + "tksCpNode": { + "type": "integer" + }, + "tksCpNodeMax": { + "type": "integer" + }, + "tksCpNodeType": { + "type": "string" + }, + "tksInfraNode": { + "type": "integer" + }, + "tksInfraNodeMax": { "type": "integer" }, - "tksNodeCnt": { + "tksInfraNodeType": { + "type": "string" + }, + "tksUserNode": { "type": "integer" }, - "userpNodeCnt": { + "tksUserNodeMax": { "type": "integer" + }, + "tksUserNodeType": { + "type": "string" } } }, @@ -4204,31 +4235,34 @@ const docTemplate = `{ "clusterRegion": { "type": "string" }, - "cpNodeMachineType": { + "sshKeyName": { "type": "string" }, - "cpReplicas": { + "tksCpNode": { "type": "integer" }, - "mdMachineType": { - "type": "string" - }, - "mdMaxSizePerAz": { + "tksCpNodeMax": { "type": "integer" }, - "mdMinSizePerAz": { + "tksCpNodeType": { + "type": "string" + }, + "tksInfraNode": { "type": "integer" }, - "mdNumOfAz": { + "tksInfraNodeMax": { "type": "integer" }, - "mpNodeMachineType": { + "tksInfraNodeType": { "type": "string" }, - "mpReplicas": { + "tksUserNode": { "type": "integer" }, - "sshKeyName": { + "tksUserNodeMax": { + "type": "integer" + }, + "tksUserNodeType": { "type": "string" } } @@ -4422,12 +4456,6 @@ const docTemplate = `{ "cloudAccountId": { "type": "string" }, - "cpNodeCnt": { - "type": "integer" - }, - "cpNodeMachineType": { - "type": "string" - }, "description": { "type": "string" }, @@ -4440,16 +4468,31 @@ const docTemplate = `{ "stackTemplateId": { "type": "string" }, - "tksNodeCnt": { + "tksCpNode": { "type": "integer" }, - "tksNodeMachineType": { + "tksCpNodeMax": { + "type": "integer" + }, + "tksCpNodeType": { "type": "string" }, - "userNodeCnt": { + "tksInfraNode": { + "type": "integer" + }, + "tksInfraNodeMax": { + "type": "integer" + }, + "tksInfraNodeType": { + "type": "string" + }, + "tksUserNode": { + "type": "integer" + }, + "tksUserNodeMax": { "type": "integer" }, - "userNodeMachineType": { + "tksUserNodeType": { "type": "string" } } @@ -4491,19 +4534,13 @@ const docTemplate = `{ "cloudAccountId", "name", "stackTemplateId", - "tksNodeCnt", - "userNodeCnt" + "tksInfraNode", + "tksUserNode" ], "properties": { "cloudAccountId": { "type": "string" }, - "cpNodeCnt": { - "type": "integer" - }, - "cpNodeMachineType": { - "type": "string" - }, "description": { "type": "string" }, @@ -4513,20 +4550,35 @@ const docTemplate = `{ "stackTemplateId": { "type": "string" }, - "tksNodeCnt": { + "tksCpNode": { + "type": "integer" + }, + "tksCpNodeMax": { + "type": "integer" + }, + "tksCpNodeType": { + "type": "string" + }, + "tksInfraNode": { "type": "integer", - "maximum": 6, - "minimum": 3 + "maximum": 3, + "minimum": 1 + }, + "tksInfraNodeMax": { + "type": "integer" }, - "tksNodeMachineType": { + "tksInfraNodeType": { "type": "string" }, - "userNodeCnt": { + "tksUserNode": { "type": "integer", "maximum": 100, "minimum": 0 }, - "userNodeMachineType": { + "tksUserNodeMax": { + "type": "integer" + }, + "tksUserNodeType": { "type": "string" } } @@ -5484,23 +5536,40 @@ const docTemplate = `{ }, "domain.StackConfResponse": { "type": "object", + "required": [ + "tksInfraNode", + "tksUserNode" + ], "properties": { - "cpNodeCnt": { + "tksCpNode": { "type": "integer" }, - "cpNodeMachineType": { + "tksCpNodeMax": { + "type": "integer" + }, + "tksCpNodeType": { "type": "string" }, - "tksNodeCnt": { + "tksInfraNode": { + "type": "integer", + "maximum": 3, + "minimum": 1 + }, + "tksInfraNodeMax": { "type": "integer" }, - "tksNodeMachineType": { + "tksInfraNodeType": { "type": "string" }, - "userNodeCnt": { + "tksUserNode": { + "type": "integer", + "maximum": 100, + "minimum": 0 + }, + "tksUserNodeMax": { "type": "integer" }, - "userNodeMachineType": { + "tksUserNodeType": { "type": "string" } } diff --git a/api/swagger/swagger.json b/api/swagger/swagger.json index 7682a695..29a14b8a 100644 --- a/api/swagger/swagger.json +++ b/api/swagger/swagger.json @@ -3718,6 +3718,10 @@ "description": "endpoint URL of deployed app", "type": "string" }, + "grafanaUrl": { + "description": "grafana dashboard URL for deployed app", + "type": "string" + }, "id": { "type": "string" }, @@ -4113,22 +4117,31 @@ "domain.ClusterConf": { "type": "object", "properties": { - "cpNodeCnt": { + "tksCpNode": { + "type": "integer" + }, + "tksCpNodeMax": { "type": "integer" }, - "cpNodeMachineType": { + "tksCpNodeType": { "type": "string" }, - "tksNodeCnt": { + "tksInfraNode": { "type": "integer" }, - "tksNodeMachineType": { + "tksInfraNodeMax": { + "type": "integer" + }, + "tksInfraNodeType": { "type": "string" }, - "userNodeCnt": { + "tksUserNode": { + "type": "integer" + }, + "tksUserNodeMax": { "type": "integer" }, - "userNodeMachineType": { + "tksUserNodeType": { "type": "string" } } @@ -4136,14 +4149,32 @@ "domain.ClusterConfResponse": { "type": "object", "properties": { - "cpNodeCnt": { + "tksCpNode": { + "type": "integer" + }, + "tksCpNodeMax": { + "type": "integer" + }, + "tksCpNodeType": { + "type": "string" + }, + "tksInfraNode": { + "type": "integer" + }, + "tksInfraNodeMax": { "type": "integer" }, - "tksNodeCnt": { + "tksInfraNodeType": { + "type": "string" + }, + "tksUserNode": { "type": "integer" }, - "userpNodeCnt": { + "tksUserNodeMax": { "type": "integer" + }, + "tksUserNodeType": { + "type": "string" } } }, @@ -4197,31 +4228,34 @@ "clusterRegion": { "type": "string" }, - "cpNodeMachineType": { + "sshKeyName": { "type": "string" }, - "cpReplicas": { + "tksCpNode": { "type": "integer" }, - "mdMachineType": { - "type": "string" - }, - "mdMaxSizePerAz": { + "tksCpNodeMax": { "type": "integer" }, - "mdMinSizePerAz": { + "tksCpNodeType": { + "type": "string" + }, + "tksInfraNode": { "type": "integer" }, - "mdNumOfAz": { + "tksInfraNodeMax": { "type": "integer" }, - "mpNodeMachineType": { + "tksInfraNodeType": { "type": "string" }, - "mpReplicas": { + "tksUserNode": { "type": "integer" }, - "sshKeyName": { + "tksUserNodeMax": { + "type": "integer" + }, + "tksUserNodeType": { "type": "string" } } @@ -4415,12 +4449,6 @@ "cloudAccountId": { "type": "string" }, - "cpNodeCnt": { - "type": "integer" - }, - "cpNodeMachineType": { - "type": "string" - }, "description": { "type": "string" }, @@ -4433,16 +4461,31 @@ "stackTemplateId": { "type": "string" }, - "tksNodeCnt": { + "tksCpNode": { "type": "integer" }, - "tksNodeMachineType": { + "tksCpNodeMax": { + "type": "integer" + }, + "tksCpNodeType": { "type": "string" }, - "userNodeCnt": { + "tksInfraNode": { + "type": "integer" + }, + "tksInfraNodeMax": { + "type": "integer" + }, + "tksInfraNodeType": { + "type": "string" + }, + "tksUserNode": { + "type": "integer" + }, + "tksUserNodeMax": { "type": "integer" }, - "userNodeMachineType": { + "tksUserNodeType": { "type": "string" } } @@ -4484,19 +4527,13 @@ "cloudAccountId", "name", "stackTemplateId", - "tksNodeCnt", - "userNodeCnt" + "tksInfraNode", + "tksUserNode" ], "properties": { "cloudAccountId": { "type": "string" }, - "cpNodeCnt": { - "type": "integer" - }, - "cpNodeMachineType": { - "type": "string" - }, "description": { "type": "string" }, @@ -4506,20 +4543,35 @@ "stackTemplateId": { "type": "string" }, - "tksNodeCnt": { + "tksCpNode": { + "type": "integer" + }, + "tksCpNodeMax": { + "type": "integer" + }, + "tksCpNodeType": { + "type": "string" + }, + "tksInfraNode": { "type": "integer", - "maximum": 6, - "minimum": 3 + "maximum": 3, + "minimum": 1 + }, + "tksInfraNodeMax": { + "type": "integer" }, - "tksNodeMachineType": { + "tksInfraNodeType": { "type": "string" }, - "userNodeCnt": { + "tksUserNode": { "type": "integer", "maximum": 100, "minimum": 0 }, - "userNodeMachineType": { + "tksUserNodeMax": { + "type": "integer" + }, + "tksUserNodeType": { "type": "string" } } @@ -5477,23 +5529,40 @@ }, "domain.StackConfResponse": { "type": "object", + "required": [ + "tksInfraNode", + "tksUserNode" + ], "properties": { - "cpNodeCnt": { + "tksCpNode": { "type": "integer" }, - "cpNodeMachineType": { + "tksCpNodeMax": { + "type": "integer" + }, + "tksCpNodeType": { "type": "string" }, - "tksNodeCnt": { + "tksInfraNode": { + "type": "integer", + "maximum": 3, + "minimum": 1 + }, + "tksInfraNodeMax": { "type": "integer" }, - "tksNodeMachineType": { + "tksInfraNodeType": { "type": "string" }, - "userNodeCnt": { + "tksUserNode": { + "type": "integer", + "maximum": 100, + "minimum": 0 + }, + "tksUserNodeMax": { "type": "integer" }, - "userNodeMachineType": { + "tksUserNodeType": { "type": "string" } } diff --git a/api/swagger/swagger.yaml b/api/swagger/swagger.yaml index 5f015d41..c1ddc1b3 100644 --- a/api/swagger/swagger.yaml +++ b/api/swagger/swagger.yaml @@ -124,6 +124,9 @@ definitions: endpointUrl: description: endpoint URL of deployed app type: string + grafanaUrl: + description: grafana dashboard URL for deployed app + type: string id: type: string name: @@ -392,27 +395,45 @@ definitions: type: object domain.ClusterConf: properties: - cpNodeCnt: + tksCpNode: + type: integer + tksCpNodeMax: type: integer - cpNodeMachineType: + tksCpNodeType: type: string - tksNodeCnt: + tksInfraNode: type: integer - tksNodeMachineType: + tksInfraNodeMax: + type: integer + tksInfraNodeType: type: string - userNodeCnt: + tksUserNode: + type: integer + tksUserNodeMax: type: integer - userNodeMachineType: + tksUserNodeType: type: string type: object domain.ClusterConfResponse: properties: - cpNodeCnt: + tksCpNode: + type: integer + tksCpNodeMax: + type: integer + tksCpNodeType: + type: string + tksInfraNode: + type: integer + tksInfraNodeMax: type: integer - tksNodeCnt: + tksInfraNodeType: + type: string + tksUserNode: type: integer - userpNodeCnt: + tksUserNodeMax: type: integer + tksUserNodeType: + type: string type: object domain.ClusterResponse: properties: @@ -447,23 +468,25 @@ definitions: properties: clusterRegion: type: string - cpNodeMachineType: + sshKeyName: type: string - cpReplicas: + tksCpNode: type: integer - mdMachineType: - type: string - mdMaxSizePerAz: + tksCpNodeMax: type: integer - mdMinSizePerAz: + tksCpNodeType: + type: string + tksInfraNode: type: integer - mdNumOfAz: + tksInfraNodeMax: type: integer - mpNodeMachineType: + tksInfraNodeType: type: string - mpReplicas: + tksUserNode: type: integer - sshKeyName: + tksUserNodeMax: + type: integer + tksUserNodeType: type: string type: object domain.CreateAppGroupRequest: @@ -593,10 +616,6 @@ definitions: properties: cloudAccountId: type: string - cpNodeCnt: - type: integer - cpNodeMachineType: - type: string description: type: string name: @@ -605,13 +624,23 @@ definitions: type: string stackTemplateId: type: string - tksNodeCnt: + tksCpNode: type: integer - tksNodeMachineType: + tksCpNodeMax: + type: integer + tksCpNodeType: type: string - userNodeCnt: + tksInfraNode: + type: integer + tksInfraNodeMax: + type: integer + tksInfraNodeType: + type: string + tksUserNode: + type: integer + tksUserNodeMax: type: integer - userNodeMachineType: + tksUserNodeType: type: string required: - cloudAccountId @@ -644,34 +673,40 @@ definitions: properties: cloudAccountId: type: string - cpNodeCnt: - type: integer - cpNodeMachineType: - type: string description: type: string name: type: string stackTemplateId: type: string - tksNodeCnt: - maximum: 6 - minimum: 3 + tksCpNode: + type: integer + tksCpNodeMax: + type: integer + tksCpNodeType: + type: string + tksInfraNode: + maximum: 3 + minimum: 1 + type: integer + tksInfraNodeMax: type: integer - tksNodeMachineType: + tksInfraNodeType: type: string - userNodeCnt: + tksUserNode: maximum: 100 minimum: 0 type: integer - userNodeMachineType: + tksUserNodeMax: + type: integer + tksUserNodeType: type: string required: - cloudAccountId - name - stackTemplateId - - tksNodeCnt - - userNodeCnt + - tksInfraNode + - tksUserNode type: object domain.CreateStackResponse: properties: @@ -1300,18 +1335,31 @@ definitions: type: object domain.StackConfResponse: properties: - cpNodeCnt: + tksCpNode: type: integer - cpNodeMachineType: + tksCpNodeMax: + type: integer + tksCpNodeType: type: string - tksNodeCnt: + tksInfraNode: + maximum: 3 + minimum: 1 + type: integer + tksInfraNodeMax: type: integer - tksNodeMachineType: + tksInfraNodeType: type: string - userNodeCnt: + tksUserNode: + maximum: 100 + minimum: 0 type: integer - userNodeMachineType: + tksUserNodeMax: + type: integer + tksUserNodeType: type: string + required: + - tksInfraNode + - tksUserNode type: object domain.StackResponse: properties: diff --git a/internal/repository/cluster.go b/internal/repository/cluster.go index 153b2c4a..2b28410c 100644 --- a/internal/repository/cluster.go +++ b/internal/repository/cluster.go @@ -45,28 +45,31 @@ func NewClusterRepository(db *gorm.DB) IClusterRepository { type Cluster struct { gorm.Model - ID domain.ClusterId `gorm:"primarykey"` - Name string `gorm:"index"` - OrganizationId string - Organization Organization `gorm:"foreignKey:OrganizationId"` - Description string `gorm:"index"` - WorkflowId string - Status domain.ClusterStatus - StatusDesc string - CloudAccountId uuid.UUID - CloudAccount CloudAccount `gorm:"foreignKey:CloudAccountId"` - StackTemplateId uuid.UUID - StackTemplate StackTemplate `gorm:"foreignKey:StackTemplateId"` - CpNodeCnt int - CpNodeMachineType string - TksNodeCnt int - TksNodeMachineType string - UserNodeCnt int - UserNodeMachineType string - CreatorId *uuid.UUID `gorm:"type:uuid"` - Creator User `gorm:"foreignKey:CreatorId"` - UpdatorId *uuid.UUID `gorm:"type:uuid"` - Updator User `gorm:"foreignKey:UpdatorId"` + ID domain.ClusterId `gorm:"primarykey"` + Name string `gorm:"index"` + OrganizationId string + Organization Organization `gorm:"foreignKey:OrganizationId"` + Description string `gorm:"index"` + WorkflowId string + Status domain.ClusterStatus + StatusDesc string + CloudAccountId uuid.UUID + CloudAccount CloudAccount `gorm:"foreignKey:CloudAccountId"` + StackTemplateId uuid.UUID + StackTemplate StackTemplate `gorm:"foreignKey:StackTemplateId"` + TksCpNode int + TksCpNodeMax int + TksCpNodeType string + TksInfraNode int + TksInfraNodeMax int + TksInfraNodeType string + TksUserNode int + TksUserNodeMax int + TksUserNodeType string + CreatorId *uuid.UUID `gorm:"type:uuid"` + Creator User `gorm:"foreignKey:CreatorId"` + UpdatorId *uuid.UUID `gorm:"type:uuid"` + Updator User `gorm:"foreignKey:UpdatorId"` } func (c *Cluster) BeforeCreate(tx *gorm.DB) (err error) { @@ -181,20 +184,23 @@ func (r *ClusterRepository) GetByName(organizationId string, name string) (out d func (r *ClusterRepository) Create(dto domain.Cluster) (clusterId domain.ClusterId, err error) { cluster := Cluster{ - OrganizationId: dto.OrganizationId, - Name: dto.Name, - Description: dto.Description, - CloudAccountId: dto.CloudAccountId, - StackTemplateId: dto.StackTemplateId, - CreatorId: dto.CreatorId, - UpdatorId: nil, - Status: domain.ClusterStatus_PENDING, - CpNodeCnt: dto.Conf.CpNodeCnt, - CpNodeMachineType: dto.Conf.CpNodeMachineType, - TksNodeCnt: dto.Conf.TksNodeCnt, - TksNodeMachineType: dto.Conf.TksNodeMachineType, - UserNodeCnt: dto.Conf.UserNodeCnt, - UserNodeMachineType: dto.Conf.UserNodeMachineType, + OrganizationId: dto.OrganizationId, + Name: dto.Name, + Description: dto.Description, + CloudAccountId: dto.CloudAccountId, + StackTemplateId: dto.StackTemplateId, + CreatorId: dto.CreatorId, + UpdatorId: nil, + Status: domain.ClusterStatus_PENDING, + TksCpNode: dto.Conf.TksCpNode, + TksCpNodeMax: dto.Conf.TksCpNodeMax, + TksCpNodeType: dto.Conf.TksCpNodeType, + TksInfraNode: dto.Conf.TksInfraNode, + TksInfraNodeMax: dto.Conf.TksInfraNodeMax, + TksInfraNodeType: dto.Conf.TksInfraNodeType, + TksUserNode: dto.Conf.TksUserNode, + TksUserNodeMax: dto.Conf.TksUserNodeMax, + TksUserNodeType: dto.Conf.TksUserNodeType, } res := r.db.Create(&cluster) if res.Error != nil { @@ -266,12 +272,15 @@ func reflectCluster(cluster Cluster) domain.Cluster { CreatedAt: cluster.CreatedAt, UpdatedAt: cluster.UpdatedAt, Conf: domain.ClusterConf{ - CpNodeCnt: int(cluster.CpNodeCnt), - CpNodeMachineType: cluster.CpNodeMachineType, - TksNodeCnt: int(cluster.TksNodeCnt), - TksNodeMachineType: cluster.TksNodeMachineType, - UserNodeCnt: int(cluster.UserNodeCnt), - UserNodeMachineType: cluster.UserNodeMachineType, + TksCpNode: int(cluster.TksCpNode), + TksCpNodeMax: int(cluster.TksCpNodeMax), + TksCpNodeType: cluster.TksCpNodeType, + TksInfraNode: int(cluster.TksInfraNode), + TksInfraNodeMax: int(cluster.TksInfraNodeMax), + TksInfraNodeType: cluster.TksInfraNodeType, + TksUserNode: int(cluster.TksUserNode), + TksUserNodeMax: int(cluster.TksUserNodeMax), + TksUserNodeType: cluster.TksUserNodeType, }, } } diff --git a/internal/usecase/app-serve-app.go b/internal/usecase/app-serve-app.go index 7082bdea..38e0b702 100644 --- a/internal/usecase/app-serve-app.go +++ b/internal/usecase/app-serve-app.go @@ -162,7 +162,7 @@ func (u *AppServeAppUsecase) CreateAppServeApp(app *domain.AppServeApp) (string, "pv_access_mode=" + app.AppServeAppTasks[0].PvAccessMode, "pv_size=" + app.AppServeAppTasks[0].PvSize, "pv_mount_path=" + app.AppServeAppTasks[0].PvMountPath, - "tks_info_host=" + viper.GetString("external-address"), + "tks_api_url=" + viper.GetString("external-address"), } log.Info("Submitting workflow: ", workflow) @@ -379,7 +379,7 @@ func (u *AppServeAppUsecase) DeleteAppServeApp(appId string) (res string, err er "asa_id=" + app.ID, "asa_task_id=" + taskId, "organization_id=" + app.OrganizationId, - "tks_info_host=" + viper.GetString("external-address"), + "tks_api_url=" + viper.GetString("external-address"), }, }) if err != nil { @@ -507,7 +507,7 @@ func (u *AppServeAppUsecase) UpdateAppServeApp(app *domain.AppServeApp, appTask "pv_access_mode=" + appTask.PvAccessMode, "pv_size=" + appTask.PvSize, "pv_mount_path=" + appTask.PvMountPath, - "tks_info_host=" + viper.GetString("external-address"), + "tks_api_url=" + viper.GetString("external-address"), }, }) if err != nil { @@ -565,7 +565,7 @@ func (u *AppServeAppUsecase) PromoteAppServeApp(appId string) (ret string, err e "asa_id=" + app.ID, "asa_task_id=" + latestTaskId, "strategy=" + strategy, - "tks_info_host=" + viper.GetString("external-address"), + "tks_api_url=" + viper.GetString("external-address"), }, }) if err != nil { @@ -618,7 +618,7 @@ func (u *AppServeAppUsecase) AbortAppServeApp(appId string) (ret string, err err "asa_id=" + app.ID, "asa_task_id=" + latestTaskId, "strategy=" + strategy, - "tks_info_host=" + viper.GetString("external-address"), + "tks_api_url=" + viper.GetString("external-address"), }, }) if err != nil { @@ -691,7 +691,7 @@ func (u *AppServeAppUsecase) RollbackAppServeApp(appId string, taskId string) (r "asa_id=" + app.ID, "asa_task_id=" + newTaskId, "helm_revision=" + strconv.Itoa(int(targetRev)), - "tks_info_host=" + viper.GetString("external-address"), + "tks_api_url=" + viper.GetString("external-address"), }, }) if err != nil { diff --git a/internal/usecase/cluster.go b/internal/usecase/cluster.go index 8048c068..3551a69d 100644 --- a/internal/usecase/cluster.go +++ b/internal/usecase/cluster.go @@ -177,7 +177,7 @@ func (u *ClusterUsecase) Create(ctx context.Context, dto domain.Cluster) (cluste "create-tks-usercluster", argowf.SubmitOptions{ Parameters: []string{ - fmt.Sprintf("tks_info_host=%s", viper.GetString("external-address")), + fmt.Sprintf("tks_api_url=%s", viper.GetString("external-address")), "contract_id=" + dto.OrganizationId, "cluster_id=" + clusterId.String(), "site_name=" + clusterId.String(), @@ -248,7 +248,7 @@ func (u *ClusterUsecase) Delete(ctx context.Context, clusterId domain.ClusterId) argowf.SubmitOptions{ Parameters: []string{ "app_group=tks-cluster-aws", - "tks_info_host=http://tks-api.tks.svc:9110", + "tks_api_url=http://tks-api.tks.svc:9110", "cluster_id=" + clusterId.String(), "cloud_account_id=" + tksCloudAccountId, }, @@ -268,17 +268,17 @@ func (u *ClusterUsecase) Delete(ctx context.Context, clusterId domain.ClusterId) } func (u *ClusterUsecase) GetClusterSiteValues(ctx context.Context, clusterId domain.ClusterId) (out domain.ClusterSiteValuesResponse, err error) { - cluster, err := u.Get(ctx, clusterId) + cluster, err := u.repo.Get(clusterId) if err != nil { return domain.ClusterSiteValuesResponse{}, errors.Wrap(err, "Failed to get cluster") } out.SshKeyName = "tks-seoul" out.ClusterRegion = "ap-northeast-2" - out.CpReplicas = cluster.Conf.CpNodeCnt - out.CpNodeMachineType = cluster.Conf.CpNodeMachineType - out.MpReplicas = cluster.Conf.TksNodeCnt - out.MpNodeMachineType = cluster.Conf.TksNodeMachineType + + if err := domain.Map(cluster.Conf, &out); err != nil { + log.ErrorWithContext(ctx, err) + } /* // 기능 변경 : 20230614 : machine deployment 사용하지 않음. 단, aws-standard 는 사용할 여지가 있으므로 주석처리해둔다. @@ -293,12 +293,6 @@ func (u *ClusterUsecase) GetClusterSiteValues(ctx context.Context, clusterId dom out.MdMaxSizePerAz = cluster.Conf.UserNodeCnt * 5 } */ - - out.MdMachineType = cluster.Conf.UserNodeMachineType - out.MdNumOfAz = cluster.Conf.UserNodeCnt - out.MdMinSizePerAz = 1 - out.MdMaxSizePerAz = cluster.Conf.UserNodeCnt - return } diff --git a/internal/usecase/stack.go b/internal/usecase/stack.go index 398e3f6d..7e729d90 100644 --- a/internal/usecase/stack.go +++ b/internal/usecase/stack.go @@ -681,9 +681,15 @@ func reflectClusterToStack(cluster domain.Cluster, appGroups []domain.AppGroup) CreatedAt: cluster.CreatedAt, UpdatedAt: cluster.UpdatedAt, Conf: domain.StackConf{ - CpNodeCnt: cluster.Conf.CpNodeCnt, - TksNodeCnt: cluster.Conf.TksNodeCnt, - UserNodeCnt: cluster.Conf.UserNodeCnt, + TksCpNode: cluster.Conf.TksCpNode, + TksCpNodeMax: cluster.Conf.TksCpNodeMax, + TksCpNodeType: cluster.Conf.TksCpNodeType, + TksInfraNode: cluster.Conf.TksInfraNode, + TksInfraNodeMax: cluster.Conf.TksInfraNodeMax, + TksInfraNodeType: cluster.Conf.TksInfraNodeType, + TksUserNode: cluster.Conf.TksUserNode, + TksUserNodeMax: cluster.Conf.TksUserNodeMax, + TksUserNodeType: cluster.Conf.TksUserNodeType, }, } } diff --git a/pkg/domain/cluster.go b/pkg/domain/cluster.go index ab9264ff..5fabed98 100644 --- a/pkg/domain/cluster.go +++ b/pkg/domain/cluster.go @@ -72,48 +72,63 @@ type Cluster struct { } type ClusterConf struct { - CpNodeCnt int - CpNodeMachineType string - TksNodeCnt int - TksNodeMachineType string - UserNodeCnt int - UserNodeMachineType string + TksCpNode int + TksCpNodeMax int + TksCpNodeType string + TksInfraNode int + TksInfraNodeMax int + TksInfraNodeType string + TksUserNode int + TksUserNodeMax int + TksUserNodeType string } // [TODO] annotaion 으로 가능하려나? func (m *ClusterConf) SetDefault() { - if m.CpNodeCnt == 0 { - m.CpNodeCnt = 3 + if m.TksCpNode == 0 { + m.TksCpNode = 3 } - if m.TksNodeCnt == 0 { - m.TksNodeCnt = 3 + if m.TksCpNodeMax == 0 { + m.TksCpNodeMax = m.TksCpNode } - if m.UserNodeCnt == 0 { - m.UserNodeCnt = 1 + if m.TksInfraNode == 0 { + m.TksInfraNode = 3 } - if m.CpNodeMachineType == "" { - m.CpNodeMachineType = "t3.xlarge" + if m.TksInfraNodeMax == 0 { + m.TksInfraNodeMax = m.TksInfraNode } - if m.TksNodeMachineType == "" { - m.TksNodeMachineType = "t3.2xlarge" + if m.TksUserNode == 0 { + m.TksUserNode = 1 } - if m.UserNodeMachineType == "" { - m.UserNodeMachineType = "t3.large" + if m.TksUserNodeMax == 0 { + m.TksUserNodeMax = m.TksUserNode + } + if m.TksCpNodeType == "" { + m.TksCpNodeType = "t3.xlarge" + } + if m.TksInfraNodeType == "" { + m.TksInfraNodeType = "t3.2xlarge" + } + if m.TksUserNodeType == "" { + m.TksUserNodeType = "t3.large" } } type CreateClusterRequest struct { - OrganizationId string `json:"organizationId" validate:"required"` - StackTemplateId string `json:"stackTemplateId" validate:"required"` - Name string `json:"name" validate:"required,name"` - Description string `json:"description"` - CloudAccountId string `json:"cloudAccountId" validate:"required"` - CpNodeCnt int `json:"cpNodeCnt,omitempty"` - CpNodeMachineType string `json:"cpNodeMachineType,omitempty"` - TksNodeCnt int `json:"tksNodeCnt,omitempty"` - TksNodeMachineType string `json:"tksNodeMachineType,omitempty"` - UserNodeCnt int `json:"userNodeCnt,omitempty"` - UserNodeMachineType string `json:"userNodeMachineType,omitempty"` + OrganizationId string `json:"organizationId" validate:"required"` + StackTemplateId string `json:"stackTemplateId" validate:"required"` + Name string `json:"name" validate:"required,name"` + Description string `json:"description"` + CloudAccountId string `json:"cloudAccountId" validate:"required"` + TksCpNode int `json:"tksCpNode"` + TksCpNodeMax int `json:"tksCpNodeMax,omitempty"` + TksCpNodeType string `json:"tksCpNodeType,omitempty"` + TksInfraNode int `json:"tksInfraNode"` + TksInfraNodeMax int `json:"tksInfraNodeMax,omitempty"` + TksInfraNodeType string `json:"tksInfraNodeType,omitempty"` + TksUserNode int `json:"tksUserNode"` + TksUserNodeMax int `json:"tksUserNodeMax,omitempty"` + TksUserNodeType string `json:"tksUserNodeType,omitempty"` } type CreateClusterResponse struct { @@ -121,9 +136,15 @@ type CreateClusterResponse struct { } type ClusterConfResponse struct { - CpNodeCnt int `json:"cpNodeCnt"` - TksNodeCnt int `json:"tksNodeCnt"` - UserNodeCnt int `json:"userpNodeCnt"` + TksCpNode int `json:"tksCpNode"` + TksCpNodeMax int `json:"tksCpNodeMax,omitempty"` + TksCpNodeType string `json:"tksCpNodeType,omitempty"` + TksInfraNode int `json:"tksInfraNode"` + TksInfraNodeMax int `json:"tksInfraNodeMax,omitempty"` + TksInfraNodeType string `json:"tksInfraNodeType,omitempty"` + TksUserNode int `json:"tksUserNode"` + TksUserNodeMax int `json:"tksUserNodeMax,omitempty"` + TksUserNodeType string `json:"tksUserNodeType,omitempty"` } type ClusterResponse struct { @@ -149,16 +170,17 @@ type SimpleClusterResponse struct { } type ClusterSiteValuesResponse struct { - SshKeyName string `json:"sshKeyName"` - ClusterRegion string `json:"clusterRegion"` - CpReplicas int `json:"cpReplicas"` - CpNodeMachineType string `json:"cpNodeMachineType"` - MpReplicas int `json:"mpReplicas"` - MpNodeMachineType string `json:"mpNodeMachineType"` - MdNumOfAz int `json:"mdNumOfAz"` - MdMinSizePerAz int `json:"mdMinSizePerAz"` - MdMaxSizePerAz int `json:"mdMaxSizePerAz"` - MdMachineType string `json:"mdMachineType"` + SshKeyName string `json:"sshKeyName"` + ClusterRegion string `json:"clusterRegion"` + TksCpNode int `json:"tksCpNode"` + TksCpNodeMax int `json:"tksCpNodeMax,omitempty"` + TksCpNodeType string `json:"tksCpNodeType,omitempty"` + TksInfraNode int `json:"tksInfraNode"` + TksInfraNodeMax int `json:"tksInfraNodeMax,omitempty"` + TksInfraNodeType string `json:"tksInfraNodeType,omitempty"` + TksUserNode int `json:"tksUserNode"` + TksUserNodeMax int `json:"tksUserNodeMax,omitempty"` + TksUserNodeType string `json:"tksUserNodeType,omitempty"` } type GetClustersResponse struct { diff --git a/pkg/domain/stack.go b/pkg/domain/stack.go index f405ad99..a325bcdb 100644 --- a/pkg/domain/stack.go +++ b/pkg/domain/stack.go @@ -93,12 +93,15 @@ type Stack = struct { } type StackConf struct { - CpNodeCnt int - CpNodeMachineType string - TksNodeCnt int - TksNodeMachineType string - UserNodeCnt int - UserNodeMachineType string + TksCpNode int + TksCpNodeMax int + TksCpNodeType string + TksInfraNode int + TksInfraNodeMax int + TksInfraNodeType string + TksUserNode int + TksUserNodeMax int + TksUserNodeType string } type StackStepStatus struct { @@ -109,16 +112,19 @@ type StackStepStatus struct { } type CreateStackRequest struct { - Name string `json:"name" validate:"required,name,rfc1123"` - Description string `json:"description"` - StackTemplateId string `json:"stackTemplateId" validate:"required"` - CloudAccountId string `json:"cloudAccountId" validate:"required"` - CpNodeCnt int `json:"cpNodeCnt,omitempty"` - CpNodeMachineType string `json:"cpNodeMachineType,omitempty"` - TksNodeCnt int `json:"tksNodeCnt" validate:"required,min=3,max=6"` - TksNodeMachineType string `json:"tksNodeMachineType,omitempty"` - UserNodeCnt int `json:"userNodeCnt" validate:"required,min=0,max=100"` - UserNodeMachineType string `json:"userNodeMachineType,omitempty"` + Name string `json:"name" validate:"required,name,rfc1123"` + Description string `json:"description"` + StackTemplateId string `json:"stackTemplateId" validate:"required"` + CloudAccountId string `json:"cloudAccountId" validate:"required"` + TksCpNode int `json:"tksCpNode,omitempty"` + TksCpNodeMax int `json:"tksCpNodeMax,omitempty"` + TksCpNodeType string `json:"tksCpNodeType,omitempty"` + TksInfraNode int `json:"tksInfraNode" validate:"required,min=1,max=3"` + TksInfraNodeMax int `json:"tksInfraNodeMax,omitempty"` + TksInfraNodeType string `json:"tksInfraNodeType,omitempty"` + TksUserNode int `json:"tksUserNode" validate:"required,min=0,max=100"` + TksUserNodeMax int `json:"tksUserNodeMax,omitempty"` + TksUserNodeType string `json:"tksUserNodeType,omitempty"` } type CreateStackResponse struct { @@ -126,12 +132,15 @@ type CreateStackResponse struct { } type StackConfResponse struct { - CpNodeCnt int `json:"cpNodeCnt"` - CpNodeMachineType string `json:"cpNodeMachineType,omitempty"` - TksNodeCnt int `json:"tksNodeCnt"` - TksNodeMachineType string `json:"tksNodeMachineType,omitempty"` - UserNodeCnt int `json:"userNodeCnt"` - UserNodeMachineType string `json:"userNodeMachineType,omitempty"` + TksCpNode int `json:"tksCpNode,omitempty"` + TksCpNodeMax int `json:"tksCpNodeMax,omitempty"` + TksCpNodeType string `json:"tksCpNodeType,omitempty"` + TksInfraNode int `json:"tksInfraNode" validate:"required,min=1,max=3"` + TksInfraNodeMax int `json:"tksInfraNodeMax,omitempty"` + TksInfraNodeType string `json:"tksInfraNodeType,omitempty"` + TksUserNode int `json:"tksUserNode" validate:"required,min=0,max=100"` + TksUserNodeMax int `json:"tksUserNodeMax,omitempty"` + TksUserNodeType string `json:"tksUserNodeType,omitempty"` } type StackResponse struct { From 0458421a391012978cede9f86ada27f623dd4443 Mon Sep 17 00:00:00 2001 From: Taekyu Date: Fri, 8 Sep 2023 13:19:22 +0900 Subject: [PATCH 2/2] trivial. minor bug fix --- pkg/domain/cluster.go | 18 ++++++------------ pkg/domain/stack.go | 4 ++-- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/pkg/domain/cluster.go b/pkg/domain/cluster.go index 5fabed98..ea7df469 100644 --- a/pkg/domain/cluster.go +++ b/pkg/domain/cluster.go @@ -85,24 +85,18 @@ type ClusterConf struct { // [TODO] annotaion 으로 가능하려나? func (m *ClusterConf) SetDefault() { - if m.TksCpNode == 0 { - m.TksCpNode = 3 - } - if m.TksCpNodeMax == 0 { - m.TksCpNodeMax = m.TksCpNode - } + m.TksCpNodeMax = m.TksCpNode + if m.TksInfraNode == 0 { m.TksInfraNode = 3 } - if m.TksInfraNodeMax == 0 { - m.TksInfraNodeMax = m.TksInfraNode - } + m.TksInfraNodeMax = m.TksInfraNode + if m.TksUserNode == 0 { m.TksUserNode = 1 } - if m.TksUserNodeMax == 0 { - m.TksUserNodeMax = m.TksUserNode - } + m.TksUserNodeMax = m.TksUserNode + if m.TksCpNodeType == "" { m.TksCpNodeType = "t3.xlarge" } diff --git a/pkg/domain/stack.go b/pkg/domain/stack.go index a325bcdb..6c344652 100644 --- a/pkg/domain/stack.go +++ b/pkg/domain/stack.go @@ -116,7 +116,7 @@ type CreateStackRequest struct { Description string `json:"description"` StackTemplateId string `json:"stackTemplateId" validate:"required"` CloudAccountId string `json:"cloudAccountId" validate:"required"` - TksCpNode int `json:"tksCpNode,omitempty"` + TksCpNode int `json:"tksCpNode"` TksCpNodeMax int `json:"tksCpNodeMax,omitempty"` TksCpNodeType string `json:"tksCpNodeType,omitempty"` TksInfraNode int `json:"tksInfraNode" validate:"required,min=1,max=3"` @@ -132,7 +132,7 @@ type CreateStackResponse struct { } type StackConfResponse struct { - TksCpNode int `json:"tksCpNode,omitempty"` + TksCpNode int `json:"tksCpNode"` TksCpNodeMax int `json:"tksCpNodeMax,omitempty"` TksCpNodeType string `json:"tksCpNodeType,omitempty"` TksInfraNode int `json:"tksInfraNode" validate:"required,min=1,max=3"`