From 7cc9b314408f60a56aefe10283c111e7dae3ee59 Mon Sep 17 00:00:00 2001 From: "taekyu.kang" Date: Fri, 15 Sep 2023 10:36:37 +0900 Subject: [PATCH 1/6] trivial. change swagger url for ft env --- api/swagger/docs.go | 2 +- api/swagger/swagger.json | 2 +- api/swagger/swagger.yaml | 2 +- cmd/server/main.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api/swagger/docs.go b/api/swagger/docs.go index fbfc0d1a..488f3903 100644 --- a/api/swagger/docs.go +++ b/api/swagger/docs.go @@ -6184,7 +6184,7 @@ const docTemplate = `{ // SwaggerInfo holds exported Swagger Info so clients can modify it var SwaggerInfo = &swag.Spec{ Version: "1.0", - Host: "tks-api-dev.taco-cat.xyz", + Host: "tks-api-ft.taco-cat.xyz", BasePath: "/api/1.0/", Schemes: []string{}, Title: "tks-api service", diff --git a/api/swagger/swagger.json b/api/swagger/swagger.json index 7682a695..301f30b9 100644 --- a/api/swagger/swagger.json +++ b/api/swagger/swagger.json @@ -13,7 +13,7 @@ }, "version": "1.0" }, - "host": "tks-api-dev.taco-cat.xyz", + "host": "tks-api-ft.taco-cat.xyz", "basePath": "/api/1.0/", "paths": { "/app-groups": { diff --git a/api/swagger/swagger.yaml b/api/swagger/swagger.yaml index 5f015d41..72553ea4 100644 --- a/api/swagger/swagger.yaml +++ b/api/swagger/swagger.yaml @@ -1755,7 +1755,7 @@ definitions: text: type: string type: object -host: tks-api-dev.taco-cat.xyz +host: tks-api-ft.taco-cat.xyz info: contact: email: taekyu.kang@sk.com diff --git a/cmd/server/main.go b/cmd/server/main.go index 854f4b34..2650ba84 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -84,7 +84,7 @@ func init() { // @in header // @name Authorization -// @host tks-api-dev.taco-cat.xyz +// @host tks-api-ft.taco-cat.xyz // @BasePath /api/1.0/ func main() { log.Info("*** Arguments *** ") From 194c667292042de213d3500f12cc0398d880bd37 Mon Sep 17 00:00:00 2001 From: "taekyu.kang" Date: Tue, 24 Oct 2023 20:36:40 +0900 Subject: [PATCH 2/6] feature. implementation importing cluster --- api/swagger/docs.go | 84 +++++++++++++++++++++++++++++++ api/swagger/swagger.json | 84 +++++++++++++++++++++++++++++++ api/swagger/swagger.yaml | 54 ++++++++++++++++++++ internal/delivery/http/cluster.go | 44 ++++++++++++++++ internal/repository/cluster.go | 2 +- internal/route/route.go | 1 + internal/usecase/cluster.go | 65 ++++++++++++++++++++++++ pkg/domain/cluster.go | 14 ++++++ pkg/httpErrors/errorCode.go | 1 + 9 files changed, 348 insertions(+), 1 deletion(-) diff --git a/api/swagger/docs.go b/api/swagger/docs.go index 0849170b..aac81160 100644 --- a/api/swagger/docs.go +++ b/api/swagger/docs.go @@ -634,6 +634,45 @@ const docTemplate = `{ } } }, + "/clusters/import": { + "post": { + "security": [ + { + "JWT": [] + } + ], + "description": "Import cluster", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Clusters" + ], + "summary": "Import cluster", + "parameters": [ + { + "description": "import cluster request", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/domain.ImportClusterRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/domain.ImportClusterResponse" + } + } + } + } + }, "/clusters/{clusterId}": { "get": { "security": [ @@ -4398,6 +4437,12 @@ const docTemplate = `{ "isStack": { "type": "boolean" }, + "kubeconfig": { + "type": "array", + "items": { + "type": "integer" + } + }, "name": { "type": "string" }, @@ -5661,6 +5706,45 @@ const docTemplate = `{ } } }, + "domain.ImportClusterRequest": { + "type": "object", + "required": [ + "name", + "organizationId", + "stackTemplateId" + ], + "properties": { + "clusterType": { + "type": "string" + }, + "description": { + "type": "string" + }, + "kubeconfig": { + "type": "array", + "items": { + "type": "integer" + } + }, + "name": { + "type": "string" + }, + "organizationId": { + "type": "string" + }, + "stackTemplateId": { + "type": "string" + } + } + }, + "domain.ImportClusterResponse": { + "type": "object", + "properties": { + "id": { + "type": "string" + } + } + }, "domain.ListOrganizationBody": { "type": "object", "properties": { diff --git a/api/swagger/swagger.json b/api/swagger/swagger.json index 77cf3a4a..508f52e8 100644 --- a/api/swagger/swagger.json +++ b/api/swagger/swagger.json @@ -627,6 +627,45 @@ } } }, + "/clusters/import": { + "post": { + "security": [ + { + "JWT": [] + } + ], + "description": "Import cluster", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Clusters" + ], + "summary": "Import cluster", + "parameters": [ + { + "description": "import cluster request", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/domain.ImportClusterRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/domain.ImportClusterResponse" + } + } + } + } + }, "/clusters/{clusterId}": { "get": { "security": [ @@ -4391,6 +4430,12 @@ "isStack": { "type": "boolean" }, + "kubeconfig": { + "type": "array", + "items": { + "type": "integer" + } + }, "name": { "type": "string" }, @@ -5654,6 +5699,45 @@ } } }, + "domain.ImportClusterRequest": { + "type": "object", + "required": [ + "name", + "organizationId", + "stackTemplateId" + ], + "properties": { + "clusterType": { + "type": "string" + }, + "description": { + "type": "string" + }, + "kubeconfig": { + "type": "array", + "items": { + "type": "integer" + } + }, + "name": { + "type": "string" + }, + "organizationId": { + "type": "string" + }, + "stackTemplateId": { + "type": "string" + } + } + }, + "domain.ImportClusterResponse": { + "type": "object", + "properties": { + "id": { + "type": "string" + } + } + }, "domain.ListOrganizationBody": { "type": "object", "properties": { diff --git a/api/swagger/swagger.yaml b/api/swagger/swagger.yaml index 04de5300..54406791 100644 --- a/api/swagger/swagger.yaml +++ b/api/swagger/swagger.yaml @@ -391,6 +391,10 @@ definitions: type: string isStack: type: boolean + kubeconfig: + items: + type: integer + type: array name: type: string organizationId: @@ -1232,6 +1236,32 @@ definitions: type: string type: object type: object + domain.ImportClusterRequest: + properties: + clusterType: + type: string + description: + type: string + kubeconfig: + items: + type: integer + type: array + name: + type: string + organizationId: + type: string + stackTemplateId: + type: string + required: + - name + - organizationId + - stackTemplateId + type: object + domain.ImportClusterResponse: + properties: + id: + type: string + type: object domain.ListOrganizationBody: properties: createdAt: @@ -2502,6 +2532,30 @@ paths: summary: Get cluster site values for creating tags: - Clusters + /clusters/import: + post: + consumes: + - application/json + description: Import cluster + parameters: + - description: import cluster request + in: body + name: body + required: true + schema: + $ref: '#/definitions/domain.ImportClusterRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/domain.ImportClusterResponse' + security: + - JWT: [] + summary: Import cluster + tags: + - Clusters /organizations: get: consumes: diff --git a/internal/delivery/http/cluster.go b/internal/delivery/http/cluster.go index cb8b8f6e..28a850a8 100644 --- a/internal/delivery/http/cluster.go +++ b/internal/delivery/http/cluster.go @@ -4,6 +4,7 @@ import ( "fmt" "net/http" + "github.com/google/uuid" "github.com/gorilla/mux" "github.com/openinfradev/tks-api/internal/pagination" "github.com/openinfradev/tks-api/internal/serializer" @@ -190,6 +191,49 @@ func (h *ClusterHandler) CreateCluster(w http.ResponseWriter, r *http.Request) { ResponseJSON(w, r, http.StatusOK, out) } +// ImportCluster godoc +// @Tags Clusters +// @Summary Import cluster +// @Description Import cluster +// @Accept json +// @Produce json +// @Param body body domain.ImportClusterRequest true "import cluster request" +// @Success 200 {object} domain.ImportClusterResponse +// @Router /clusters/import [post] +// @Security JWT +func (h *ClusterHandler) ImportCluster(w http.ResponseWriter, r *http.Request) { + input := domain.ImportClusterRequest{} + err := UnmarshalRequestInput(r, &input) + if err != nil { + ErrorJSON(w, r, err) + return + } + + var dto domain.Cluster + if err = serializer.Map(input, &dto); err != nil { + log.InfoWithContext(r.Context(), err) + } + + if err = serializer.Map(input, &dto.Conf); err != nil { + log.InfoWithContext(r.Context(), err) + } + dto.Conf.SetDefault() + log.InfoWithContext(r.Context(), dto.Conf) + + dto.CloudService = "AWS" + dto.CloudAccountId = uuid.Nil + clusterId, err := h.usecase.Import(r.Context(), dto) + if err != nil { + ErrorJSON(w, r, err) + return + } + + var out domain.ImportClusterResponse + out.ID = clusterId.String() + + ResponseJSON(w, r, http.StatusOK, out) +} + // InstallCluster godoc // @Tags Clusters // @Summary Install cluster on tks cluster diff --git a/internal/repository/cluster.go b/internal/repository/cluster.go index 570bc795..a34b87af 100644 --- a/internal/repository/cluster.go +++ b/internal/repository/cluster.go @@ -215,7 +215,7 @@ func (r *ClusterRepository) GetByName(organizationId string, name string) (out d func (r *ClusterRepository) Create(dto domain.Cluster) (clusterId domain.ClusterId, err error) { var cloudAccountId *uuid.UUID cloudAccountId = &dto.CloudAccountId - if dto.CloudService == domain.CloudService_BYOH { + if dto.CloudService == domain.CloudService_BYOH || dto.CloudAccountId == uuid.Nil { cloudAccountId = nil } cluster := Cluster{ diff --git a/internal/route/route.go b/internal/route/route.go index 7edbd419..f5ecbd4a 100644 --- a/internal/route/route.go +++ b/internal/route/route.go @@ -111,6 +111,7 @@ func SetupRouter(db *gorm.DB, argoClient argowf.ArgoClient, kc keycloak.IKeycloa clusterHandler := delivery.NewClusterHandler(usecase.NewClusterUsecase(repoFactory, argoClient, cache)) r.Handle(API_PREFIX+API_VERSION+"/clusters", authMiddleware.Handle(http.HandlerFunc(clusterHandler.CreateCluster))).Methods(http.MethodPost) r.Handle(API_PREFIX+API_VERSION+"/clusters", authMiddleware.Handle(http.HandlerFunc(clusterHandler.GetClusters))).Methods(http.MethodGet) + r.Handle(API_PREFIX+API_VERSION+"/clusters/import", authMiddleware.Handle(http.HandlerFunc(clusterHandler.ImportCluster))).Methods(http.MethodPost) r.Handle(API_PREFIX+API_VERSION+"/clusters/{clusterId}", authMiddleware.Handle(http.HandlerFunc(clusterHandler.GetCluster))).Methods(http.MethodGet) r.Handle(API_PREFIX+API_VERSION+"/clusters/{clusterId}", authMiddleware.Handle(http.HandlerFunc(clusterHandler.DeleteCluster))).Methods(http.MethodDelete) r.Handle(API_PREFIX+API_VERSION+"/clusters/{clusterId}/site-values", authMiddleware.Handle(http.HandlerFunc(clusterHandler.GetClusterSiteValues))).Methods(http.MethodGet) diff --git a/internal/usecase/cluster.go b/internal/usecase/cluster.go index 13d2be0b..de929b82 100644 --- a/internal/usecase/cluster.go +++ b/internal/usecase/cluster.go @@ -2,6 +2,7 @@ package usecase import ( "context" + "encoding/base64" "encoding/json" "fmt" "strings" @@ -33,6 +34,7 @@ type IClusterUsecase interface { Fetch(ctx context.Context, organizationId string, pg *pagination.Pagination) ([]domain.Cluster, error) FetchByCloudAccountId(ctx context.Context, cloudAccountId uuid.UUID, pg *pagination.Pagination) (out []domain.Cluster, err error) Create(ctx context.Context, dto domain.Cluster) (clusterId domain.ClusterId, err error) + Import(ctx context.Context, dto domain.Cluster) (clusterId domain.ClusterId, err error) Bootstrap(ctx context.Context, dto domain.Cluster) (clusterId domain.ClusterId, err error) Install(ctx context.Context, clusterId domain.ClusterId) (err error) Get(ctx context.Context, clusterId domain.ClusterId) (out domain.Cluster, err error) @@ -48,6 +50,7 @@ type ClusterUsecase struct { appGroupRepo repository.IAppGroupRepository cloudAccountRepo repository.ICloudAccountRepository stackTemplateRepo repository.IStackTemplateRepository + organizationRepo repository.IOrganizationRepository argo argowf.ArgoClient cache *gcache.Cache } @@ -58,6 +61,7 @@ func NewClusterUsecase(r repository.Repository, argoClient argowf.ArgoClient, ca appGroupRepo: r.AppGroup, cloudAccountRepo: r.CloudAccount, stackTemplateRepo: r.StackTemplate, + organizationRepo: r.Organization, argo: argoClient, cache: cache, } @@ -209,6 +213,67 @@ func (u *ClusterUsecase) Create(ctx context.Context, dto domain.Cluster) (cluste return clusterId, nil } +func (u *ClusterUsecase) Import(ctx context.Context, dto domain.Cluster) (clusterId domain.ClusterId, err error) { + user, ok := request.UserFrom(ctx) + if !ok { + return "", httpErrors.NewBadRequestError(fmt.Errorf("Invalid token"), "", "") + } + + _, err = u.repo.GetByName(dto.OrganizationId, dto.Name) + if err == nil { + return "", httpErrors.NewBadRequestError(httpErrors.DuplicateResource, "", "") + } + + _, err = u.organizationRepo.Get(dto.OrganizationId) + if err != nil { + return "", httpErrors.NewBadRequestError(fmt.Errorf("Invalid organizationId"), "", "") + } + + // check stackTemplate + stackTemplate, err := u.stackTemplateRepo.Get(dto.StackTemplateId) + if err != nil { + return "", httpErrors.NewBadRequestError(errors.Wrap(err, "Invalid stackTemplateId"), "", "") + } + if stackTemplate.CloudService != dto.CloudService { + return "", httpErrors.NewBadRequestError(fmt.Errorf("Invalid cloudService for stackTemplate "), "", "") + } + + userId := user.GetUserId() + dto.CreatorId = &userId + clusterId, err = u.repo.Create(dto) + if err != nil { + return "", errors.Wrap(err, "Failed to create cluster") + } + + kubeconfigBase64 := base64.StdEncoding.EncodeToString([]byte(dto.Kubeconfig)) + + workflowId, err := u.argo.SumbitWorkflowFromWftpl( + "import-tks-usercluster", + argowf.SubmitOptions{ + Parameters: []string{ + fmt.Sprintf("tks_api_url=%s", viper.GetString("external-address")), + "contract_id=" + dto.OrganizationId, + "cluster_id=" + clusterId.String(), + "template_name=" + stackTemplate.Template, + "kubeconfig=" + kubeconfigBase64, + "git_account=" + viper.GetString("git-account"), + "keycloak_url=" + strings.TrimSuffix(viper.GetString("keycloak-address"), "/auth"), + "base_repo_branch=" + viper.GetString("revision"), + }, + }) + if err != nil { + log.ErrorWithContext(ctx, "failed to submit argo workflow template. err : ", err) + return "", err + } + log.InfoWithContext(ctx, "Successfully submited workflow: ", workflowId) + + if err := u.repo.InitWorkflow(clusterId, workflowId, domain.ClusterStatus_INSTALLING); err != nil { + return "", errors.Wrap(err, "Failed to initialize status") + } + + return clusterId, nil +} + func (u *ClusterUsecase) Bootstrap(ctx context.Context, dto domain.Cluster) (clusterId domain.ClusterId, err error) { user, ok := request.UserFrom(ctx) if !ok { diff --git a/pkg/domain/cluster.go b/pkg/domain/cluster.go index 6964a83a..2752eee0 100644 --- a/pkg/domain/cluster.go +++ b/pkg/domain/cluster.go @@ -107,6 +107,7 @@ type Cluster struct { ByoClusterEndpointHost string ByoClusterEndpointPort int IsStack bool + Kubeconfig []byte } type ClusterConf struct { @@ -188,10 +189,23 @@ type CreateClusterRequest struct { TksUserNodeType string `json:"tksUserNodeType,omitempty"` } +type ImportClusterRequest struct { + OrganizationId string `json:"organizationId" validate:"required"` + StackTemplateId string `json:"stackTemplateId" validate:"required"` + Name string `json:"name" validate:"required,name"` + Description string `json:"description"` + ClusterType string `json:"clusterType"` + Kubeconfig []byte `json:"kubeconfig"` +} + type CreateClusterResponse struct { ID string `json:"id"` } +type ImportClusterResponse struct { + ID string `json:"id"` +} + type ClusterConfResponse struct { TksCpNode int `json:"tksCpNode"` TksCpNodeMax int `json:"tksCpNodeMax,omitempty"` diff --git a/pkg/httpErrors/errorCode.go b/pkg/httpErrors/errorCode.go index ff6b05ae..0fa40986 100644 --- a/pkg/httpErrors/errorCode.go +++ b/pkg/httpErrors/errorCode.go @@ -46,6 +46,7 @@ var errorMap = map[ErrorCode]string{ // Cluster "CL_INVALID_BYOH_CLUSTER_ENDPOINT": "BYOH 타입의 클러스터 생성을 위한 cluster endpoint 가 유효하지 않습니다.", + "CL_INVALID_CLUSTER_TYPE_AWS": "클러스터 타입이 유효하지 않습니다.", // Stack "S_INVALID_STACK_TEMPLATE": "스택 템플릿을 가져올 수 없습니다.", From 2fc1238a6381f491f42992807c6e4c6e92acf9a9 Mon Sep 17 00:00:00 2001 From: "taekyu.kang" Date: Thu, 26 Oct 2023 11:10:34 +0900 Subject: [PATCH 3/6] trivial. set deveult paramter kubeconfigPath to empty --- cmd/server/main.go | 2 +- scripts/init_postgres.sql | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/server/main.go b/cmd/server/main.go index 49f130fa..eea9f26d 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -29,7 +29,7 @@ func init() { flag.String("dbport", "5432", "port of postgreSQL") flag.String("dbuser", "postgres", "postgreSQL user") flag.String("dbpassword", "password", "password for postgreSQL user") - flag.String("kubeconfig-path", "/Users/1110640/.kube/config_dev", "path of kubeconfig. used development only!") + flag.String("kubeconfig-path", "", "path of kubeconfig. used development only!") flag.String("jwt-secret", "tks-api-secret", "secret value of jwt") flag.String("git-base-url", "https://github.com", "git base url") flag.String("git-account", "decapod10", "git account of admin cluster") diff --git a/scripts/init_postgres.sql b/scripts/init_postgres.sql index a335c9a5..6483db04 100644 --- a/scripts/init_postgres.sql +++ b/scripts/init_postgres.sql @@ -30,4 +30,8 @@ values ( '39f18a09-5b94-4772-bdba-e4c32ee002f7', 'master', 'EKS MSA Standard (x8 insert into stack_templates ( id, organization_id, name, description, version, cloud_service, platform, template, template_type, kube_version, kube_type, created_at, updated_at, services ) values ( '5678bf11-256f-4d2c-a673-f2fedb82de5b', 'master', 'BYOH Standard', 'included LMA', 'v1', 'AWS', 'x86', 'eks-reference', 'STANDARD', 'v1.25', 'AWS', now(), now(), '[{"name":"Logging,Monitoring,Alerting","type":"LMA","applications":[{"name":"thanos","version":"0.30.2","description":"다중클러스터의 모니터링 데이터 통합 질의처리"},{"name":"prometheus-stack","version":"v0.66.0","description":"모니터링 데이터 수집/저장 및 질의처리"},{"name":"alertmanager","version":"v0.25.0","description":"알람 처리를 위한 노티피케이션 서비스"},{"name":"loki","version":"2.6.1","description":"로그데이터 저장 및 질의처리"},{"name":"grafana","version":"8.3.3","description":"모니터링/로그 통합대시보드"}]}]' ); insert into stack_templates ( id, organization_id, name, description, version, cloud_service, platform, template, template_type, kube_version, kube_type, created_at, updated_at, services ) -values ( '92f5e5ce-7ffd-4c3e-aff6-9b7fb03dd881', 'master', 'BYOH MSA Standard', 'included LMA, SERVICE MESH', 'v1', 'AWS', 'x86', 'eks-msa-reference', 'MSA', 'v1.25', 'AWS', now(), now(), '[{"name":"Logging,Monitoring,Alerting","type":"LMA","applications":[{"name":"thanos","version":"0.30.2","description":"다중클러스터의 모니터링 데이터 통합 질의처리"},{"name":"prometheus-stack","version":"v0.66.0","description":"모니터링 데이터 수집/저장 및 질의처리"},{"name":"alertmanager","version":"v0.25.0","description":"알람 처리를 위한 노티피케이션 서비스"},{"name":"loki","version":"2.6.1","description":"로그데이터 저장 및 질의처리"},{"name":"grafana","version":"8.3.3","description":"모니터링/로그 통합대시보드"}]},{"name":"MSA","type":"SERVICE_MESH","applications":[{"name":"istio","version":"v1.17.2","description":"MSA 플랫폼"},{"name":"jagger","version":"1.35.0","description":"분산 서비스간 트랜잭션 추적을 위한 플랫폼"},{"name":"kiali","version":"v1.63.0","description":"MSA 구조 및 성능을 볼 수 있는 Dashboard"},{"name":"k8ssandra","version":"1.6.0","description":"분산 서비스간 호출 로그를 저장하는 스토리지"}]}]' ); \ No newline at end of file +values ( '92f5e5ce-7ffd-4c3e-aff6-9b7fb03dd881', 'master', 'BYOH MSA Standard', 'included LMA, SERVICE MESH', 'v1', 'AWS', 'x86', 'eks-msa-reference', 'MSA', 'v1.25', 'AWS', now(), now(), '[{"name":"Logging,Monitoring,Alerting","type":"LMA","applications":[{"name":"thanos","version":"0.30.2","description":"다중클러스터의 모니터링 데이터 통합 질의처리"},{"name":"prometheus-stack","version":"v0.66.0","description":"모니터링 데이터 수집/저장 및 질의처리"},{"name":"alertmanager","version":"v0.25.0","description":"알람 처리를 위한 노티피케이션 서비스"},{"name":"loki","version":"2.6.1","description":"로그데이터 저장 및 질의처리"},{"name":"grafana","version":"8.3.3","description":"모니터링/로그 통합대시보드"}]},{"name":"MSA","type":"SERVICE_MESH","applications":[{"name":"istio","version":"v1.17.2","description":"MSA 플랫폼"},{"name":"jagger","version":"1.35.0","description":"분산 서비스간 트랜잭션 추적을 위한 플랫폼"},{"name":"kiali","version":"v1.63.0","description":"MSA 구조 및 성능을 볼 수 있는 Dashboard"},{"name":"k8ssandra","version":"1.6.0","description":"분산 서비스간 호출 로그를 저장하는 스토리지"}]}]' ); + +insert into stack_templates ( id, organization_id, name, description, version, cloud_service, platform, template, template_type, kube_version, kube_type, created_at, updated_at, services ) +values ( 'f4c74dec-3444-481b-9597-bacb7596e7e7', 'master', 'BYOH MSA Standard (BTV STG)', 'included LMA', 'v1', 'BYOH', 'x86', 'byoh-stage-reference', 'MSA', 'v1.25', 'BYOH', now(), now(), '[{"name":"Logging,Monitoring,Alerting","type":"LMA","applications":[{"name":"thanos","version":"0.30.2","description":"다중클러스터의 모니터링 데이터 통합 질의처리"},{"name":"prometheus-stack","version":"v0.66.0","description":"모니터링 데이터 수집/저장 및 질의처리"},{"name":"alertmanager","version":"v0.25.0","description":"알람 처리를 위한 노티피케이션 서비스"},{"name":"loki","version":"2.6.1","description":"로그데이터 저장 및 질의처리"},{"name":"grafana","version":"8.3.3","description":"모니터링/로그 통합대시보드"}]}]' ); + From 435fddcab34520207708db779c57c47b4cfd3b32 Mon Sep 17 00:00:00 2001 From: "taekyu.kang" Date: Thu, 26 Oct 2023 13:49:29 +0900 Subject: [PATCH 4/6] trivial. minor fix --- internal/usecase/cluster.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/usecase/cluster.go b/internal/usecase/cluster.go index de929b82..a5c65f7d 100644 --- a/internal/usecase/cluster.go +++ b/internal/usecase/cluster.go @@ -650,10 +650,10 @@ func (u *ClusterUsecase) GetNodes(ctx context.Context, clusterId domain.ClusterI continue } clusterId := arr[0] - role := label[10:] - if label[9] != '-' || clusterId != string(cluster.ID) { + if len(arr) < 12 || label[9] != '-' || clusterId != string(cluster.ID) { continue } + role := label[10:] /* if host.Name == "ip-10-0-12-87.ap-northeast-2.compute.internal" { continue From 26518ceabdfdb8dd3128dac1bd6b885cc39604d3 Mon Sep 17 00:00:00 2001 From: "taekyu.kang" Date: Thu, 26 Oct 2023 14:31:39 +0900 Subject: [PATCH 5/6] trivial. minor fix --- internal/usecase/cluster.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/usecase/cluster.go b/internal/usecase/cluster.go index a5c65f7d..d07d614e 100644 --- a/internal/usecase/cluster.go +++ b/internal/usecase/cluster.go @@ -645,12 +645,16 @@ func (u *ClusterUsecase) GetNodes(ctx context.Context, clusterId domain.ClusterI tksUserNodeRegistered, tksUserNodeRegistering, tksUserHosts := 0, 0, make([]domain.ClusterHost, 0) for _, host := range hosts.Items { label := host.Labels["role"] - arr := strings.Split(host.Labels["role"], "-") + log.InfoWithContext(ctx, "label : ", label) + if len(label) < 12 { + continue + } + arr := strings.Split(label, "-") if len(arr) < 2 { continue } clusterId := arr[0] - if len(arr) < 12 || label[9] != '-' || clusterId != string(cluster.ID) { + if label[9] != '-' || clusterId != string(cluster.ID) { continue } role := label[10:] @@ -671,8 +675,6 @@ func (u *ClusterUsecase) GetNodes(ctx context.Context, clusterId domain.ClusterI registering = 1 } - log.Info(role) - switch role { case "control-plane": tksCpNodeRegistered = tksCpNodeRegistered + registered From 40a90f6ce8c46a669f41f802bbeb147157512b3d Mon Sep 17 00:00:00 2001 From: "taekyu.kang" Date: Thu, 26 Oct 2023 16:33:02 +0900 Subject: [PATCH 6/6] bugfix. fix cloudaccount error when appgroup creating --- internal/usecase/app-group.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/usecase/app-group.go b/internal/usecase/app-group.go index 1595bafa..32e61ce8 100644 --- a/internal/usecase/app-group.go +++ b/internal/usecase/app-group.go @@ -86,10 +86,11 @@ func (u *AppGroupUsecase) Create(ctx context.Context, dto domain.AppGroup) (id d if err != nil { return "", httpErrors.NewBadRequestError(fmt.Errorf("Failed to get cloudAccounts"), "", "") } - tksCloudAccountId = cluster.CloudAccountId.String() + tksCloudAccountId = cluster.CloudAccount.ID.String() + isExist := false for _, ca := range cloudAccounts { - if ca.ID == cluster.CloudAccountId { + if ca.ID == cluster.CloudAccount.ID { // FOR TEST. ADD MAGIC KEYWORD if strings.Contains(ca.Name, domain.CLOUD_ACCOUNT_INCLUSTER) {