Skip to content

Commit

Permalink
feature. add policy when stack create
Browse files Browse the repository at this point in the history
  • Loading branch information
ktkfree committed Apr 8, 2024
1 parent f86cffd commit 5ab83d6
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 23 deletions.
6 changes: 6 additions & 0 deletions api/swagger/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10746,6 +10746,12 @@ const docTemplate = `{
"organizationId": {
"type": "string"
},
"policyIds": {
"type": "array",
"items": {
"type": "string"
}
},
"stackTemplateId": {
"type": "string"
},
Expand Down
6 changes: 6 additions & 0 deletions api/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -10740,6 +10740,12 @@
"organizationId": {
"type": "string"
},
"policyIds": {
"type": "array",
"items": {
"type": "string"
}
},
"stackTemplateId": {
"type": "string"
},
Expand Down
4 changes: 4 additions & 0 deletions api/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,10 @@ definitions:
type: string
organizationId:
type: string
policyIds:
items:
type: string
type: array
stackTemplateId:
type: string
tksCpNode:
Expand Down
1 change: 1 addition & 0 deletions internal/model/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Cluster struct {
TksUserNodeMax int
TksUserNodeType string
Kubeconfig []byte `gorm:"-:all"`
PolicyIds []string `gorm:"-:all"`
CreatorId *uuid.UUID `gorm:"type:uuid"`
Creator User `gorm:"foreignKey:CreatorId"`
UpdatorId *uuid.UUID `gorm:"type:uuid"`
Expand Down
1 change: 1 addition & 0 deletions internal/model/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Stack = struct {
Favorited bool
ClusterEndpoint string
Resource domain.DashboardStack
PolicyIds []string
}

type StackConf struct {
Expand Down
7 changes: 5 additions & 2 deletions internal/usecase/stack-template.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,13 @@ func (u *StackTemplateUsecase) Create(ctx context.Context, dto model.StackTempla
}

services := "["
for _, serviceId := range dto.ServiceIds {
for i, serviceId := range dto.ServiceIds {
if i > 1 {
services = services + ","
}
switch serviceId {
case "LMA":
services = services + internal.SERVICE_LMA + ","
services = services + internal.SERVICE_LMA
case "SERVICE_MESH":
services = services + internal.SERVICE_SERVICE_MESH
}
Expand Down
1 change: 1 addition & 0 deletions internal/usecase/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func (u *StackUsecase) Create(ctx context.Context, dto model.Stack) (stackId dom
"infra_conf=" + strings.Replace(helper.ModelToJson(stackConf), "\"", "\\\"", -1),
"cloud_service=" + dto.CloudService,
"cluster_endpoint=" + dto.ClusterEndpoint,
"policy_ids=" + strings.Join(dto.PolicyIds, ","),
},
})
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/usecase/system-notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ func (u *SystemNotificationUsecase) makeGrafanaUrl(ctx context.Context, primaryC
case "pvc-full":
url = primaryGrafanaEndpoint + "/d/tks_cluster_dashboard/tks-kubernetes-view-cluster-global?var-taco_cluster=" + clusterId.String() + "&kiosk"
default:
url = ""
url = "/d/tks_cluster_dashboard"
}

return
return url
}
39 changes: 20 additions & 19 deletions pkg/domain/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,25 +140,26 @@ func (m *ClusterConf) SetDefault() {
}

type CreateClusterRequest struct {
OrganizationId string `json:"organizationId" validate:"required"`
CloudService string `json:"cloudService" validate:"required,oneof=AWS BYOH"`
StackTemplateId string `json:"stackTemplateId" validate:"required"`
Name string `json:"name" validate:"required,name"`
Description string `json:"description"`
CloudAccountId string `json:"cloudAccountId"`
ClusterType string `json:"clusterType"`
ByoClusterEndpointHost string `json:"byoClusterEndpointHost,omitempty"`
ByoClusterEndpointPort int `json:"byoClusterEndpointPort,omitempty"`
IsStack bool `json:"isStack,omitempty"`
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"`
OrganizationId string `json:"organizationId" validate:"required"`
CloudService string `json:"cloudService" validate:"required,oneof=AWS BYOH"`
StackTemplateId string `json:"stackTemplateId" validate:"required"`
Name string `json:"name" validate:"required,name"`
Description string `json:"description"`
CloudAccountId string `json:"cloudAccountId"`
ClusterType string `json:"clusterType"`
ByoClusterEndpointHost string `json:"byoClusterEndpointHost,omitempty"`
ByoClusterEndpointPort int `json:"byoClusterEndpointPort,omitempty"`
IsStack bool `json:"isStack,omitempty"`
PolicyIds []string `json:"policyIds,omitempty"`
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 ImportClusterRequest struct {
Expand Down

0 comments on commit 5ab83d6

Please sign in to comment.