Skip to content

Commit

Permalink
feature. implementation byoh
Browse files Browse the repository at this point in the history
  • Loading branch information
ktkfree committed Oct 12, 2023
1 parent eb016b5 commit e1f2e74
Show file tree
Hide file tree
Showing 13 changed files with 312 additions and 18 deletions.
46 changes: 46 additions & 0 deletions api/swagger/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,40 @@ const docTemplate = `{
}
}
},
"/clusters/{clusterId}/install": {
"post": {
"security": [
{
"JWT": []
}
],
"description": "Install cluster on tks cluster",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Clusters"
],
"summary": "Install cluster on tks cluster",
"parameters": [
{
"type": "string",
"description": "clusterId",
"name": "clusterId",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/clusters/{clusterId}/site-values": {
"get": {
"security": [
Expand Down Expand Up @@ -4303,6 +4337,9 @@ const docTemplate = `{
"id": {
"type": "string"
},
"isStack": {
"type": "boolean"
},
"name": {
"type": "string"
},
Expand Down Expand Up @@ -4423,6 +4460,9 @@ const docTemplate = `{
"id": {
"type": "string"
},
"isStack": {
"type": "boolean"
},
"name": {
"type": "string"
},
Expand Down Expand Up @@ -4689,6 +4729,9 @@ const docTemplate = `{
"description": {
"type": "string"
},
"isStack": {
"type": "boolean"
},
"name": {
"type": "string"
},
Expand Down Expand Up @@ -4779,6 +4822,9 @@ const docTemplate = `{
"BYOH"
]
},
"clusterId": {
"type": "string"
},
"description": {
"type": "string"
},
Expand Down
46 changes: 46 additions & 0 deletions api/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,40 @@
}
}
},
"/clusters/{clusterId}/install": {
"post": {
"security": [
{
"JWT": []
}
],
"description": "Install cluster on tks cluster",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Clusters"
],
"summary": "Install cluster on tks cluster",
"parameters": [
{
"type": "string",
"description": "clusterId",
"name": "clusterId",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/clusters/{clusterId}/site-values": {
"get": {
"security": [
Expand Down Expand Up @@ -4296,6 +4330,9 @@
"id": {
"type": "string"
},
"isStack": {
"type": "boolean"
},
"name": {
"type": "string"
},
Expand Down Expand Up @@ -4416,6 +4453,9 @@
"id": {
"type": "string"
},
"isStack": {
"type": "boolean"
},
"name": {
"type": "string"
},
Expand Down Expand Up @@ -4682,6 +4722,9 @@
"description": {
"type": "string"
},
"isStack": {
"type": "boolean"
},
"name": {
"type": "string"
},
Expand Down Expand Up @@ -4772,6 +4815,9 @@
"BYOH"
]
},
"clusterId": {
"type": "string"
},
"description": {
"type": "string"
},
Expand Down
29 changes: 29 additions & 0 deletions api/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ definitions:
type: boolean
id:
type: string
isStack:
type: boolean
name:
type: string
organizationId:
Expand Down Expand Up @@ -461,6 +463,8 @@ definitions:
type: string
id:
type: string
isStack:
type: boolean
name:
type: string
organizationId:
Expand Down Expand Up @@ -639,6 +643,8 @@ definitions:
type: string
description:
type: string
isStack:
type: boolean
name:
type: string
organizationId:
Expand Down Expand Up @@ -701,6 +707,8 @@ definitions:
- AWS
- BYOH
type: string
clusterId:
type: string
description:
type: string
name:
Expand Down Expand Up @@ -2369,6 +2377,27 @@ paths:
summary: Get cluster
tags:
- Clusters
/clusters/{clusterId}/install:
post:
consumes:
- application/json
description: Install cluster on tks cluster
parameters:
- description: clusterId
in: path
name: clusterId
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
security:
- JWT: []
summary: Install cluster on tks cluster
tags:
- Clusters
/clusters/{clusterId}/site-values:
get:
consumes:
Expand Down
31 changes: 29 additions & 2 deletions internal/delivery/http/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (h *ClusterHandler) GetClusterSiteValues(w http.ResponseWriter, r *http.Req
ResponseJSON(w, r, http.StatusOK, out)
}

// GetCluster godoc
// CreateCluster godoc
// @Tags Clusters
// @Summary Create cluster
// @Description Create cluster
Expand Down Expand Up @@ -166,7 +166,7 @@ func (h *ClusterHandler) CreateCluster(w http.ResponseWriter, r *http.Request) {
//txHandle := r.Context().Value("txHandle").(*gorm.DB)
clusterId := domain.ClusterId("")
if input.CloudService == domain.CloudService_BYOH {
clusterId, err = h.usecase.CreateByoh(r.Context(), dto)
clusterId, err = h.usecase.Bootstrap(r.Context(), dto)
if err != nil {
ErrorJSON(w, r, err)
return
Expand All @@ -186,6 +186,33 @@ func (h *ClusterHandler) CreateCluster(w http.ResponseWriter, r *http.Request) {
ResponseJSON(w, r, http.StatusOK, out)
}

// InstallCluster godoc
// @Tags Clusters
// @Summary Install cluster on tks cluster
// @Description Install cluster on tks cluster
// @Accept json
// @Produce json
// @Param clusterId path string true "clusterId"
// @Success 200 {object} nil
// @Router /clusters/{clusterId}/install [post]
// @Security JWT
func (h *ClusterHandler) InstallCluster(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
clusterId, ok := vars["clusterId"]
if !ok {
ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("Invalid clusterId"), "C_INVALID_CLUSTER_ID", ""))
return
}

err := h.usecase.Install(r.Context(), domain.ClusterId(clusterId))
if err != nil {
ErrorJSON(w, r, err)
return
}

ResponseJSON(w, r, http.StatusOK, nil)
}

// DeleteCluster godoc
// @Tags Clusters
// @Summary Delete cluster
Expand Down
19 changes: 18 additions & 1 deletion internal/delivery/http/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ func (h *StackHandler) CreateStack(w http.ResponseWriter, r *http.Request) {
log.InfoWithContext(r.Context(), err)
}
dto.OrganizationId = organizationId

stackId, err := h.usecase.Create(r.Context(), dto)
if err != nil {
ErrorJSON(w, r, err)
Expand All @@ -72,6 +71,24 @@ func (h *StackHandler) CreateStack(w http.ResponseWriter, r *http.Request) {
ResponseJSON(w, r, http.StatusOK, out)
}

// SYSTEM-API
func (h *StackHandler) InstallStack(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
stackId, ok := vars["stackId"]
if !ok {
ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("Invalid stackId"), "S_INVALID_STACK_ID", ""))
return
}

err := h.usecase.Install(r.Context(), domain.StackId(stackId))
if err != nil {
ErrorJSON(w, r, err)
return
}

ResponseJSON(w, r, http.StatusOK, nil)
}

// GetStack godoc
// @Tags Stacks
// @Summary Get Stacks
Expand Down
2 changes: 2 additions & 0 deletions internal/repository/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type Cluster struct {
Favorites *[]ClusterFavorite
ClusterType domain.ClusterType `gorm:"default:0"`
ClusterEndpoint string
IsStack bool `gorm:"default:false"`
TksCpNode int
TksCpNodeMax int
TksCpNodeType string
Expand Down Expand Up @@ -224,6 +225,7 @@ func (r *ClusterRepository) Create(dto domain.Cluster) (clusterId domain.Cluster
ClusterType: dto.ClusterType,
CloudService: dto.CloudService,
ClusterEndpoint: dto.ClusterEndpoint,
IsStack: dto.IsStack,
TksCpNode: dto.Conf.TksCpNode,
TksCpNodeMax: dto.Conf.TksCpNodeMax,
TksCpNodeType: dto.Conf.TksCpNodeType,
Expand Down
4 changes: 3 additions & 1 deletion internal/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ func SetupRouter(db *gorm.DB, argoClient argowf.ArgoClient, kc keycloak.IKeycloa
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/{clusterId}", authMiddleware.Handle(http.HandlerFunc(clusterHandler.GetCluster))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/clusters/{clusterId}/site-values", authMiddleware.Handle(http.HandlerFunc(clusterHandler.GetClusterSiteValues))).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)
r.Handle(API_PREFIX+API_VERSION+"/clusters/{clusterId}/install", authMiddleware.Handle(http.HandlerFunc(clusterHandler.InstallCluster))).Methods(http.MethodPost)

appGroupHandler := delivery.NewAppGroupHandler(usecase.NewAppGroupUsecase(repoFactory, argoClient))
r.Handle(API_PREFIX+API_VERSION+"/app-groups", authMiddleware.Handle(http.HandlerFunc(appGroupHandler.CreateAppGroup))).Methods(http.MethodPost)
Expand Down Expand Up @@ -185,6 +186,7 @@ func SetupRouter(db *gorm.DB, argoClient argowf.ArgoClient, kc keycloak.IKeycloa
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/stacks/{stackId}/favorite", authMiddleware.Handle(http.HandlerFunc(stackHandler.SetFavorite))).Methods(http.MethodPost)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/stacks/{stackId}/favorite", authMiddleware.Handle(http.HandlerFunc(stackHandler.DeleteFavorite))).Methods(http.MethodDelete)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/stacks/{stackId}/nodes", authMiddleware.Handle(http.HandlerFunc(stackHandler.GetNodes))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/stacks/{stackId}/install", authMiddleware.Handle(http.HandlerFunc(stackHandler.InstallStack))).Methods(http.MethodPost)

r.HandleFunc(API_PREFIX+API_VERSION+"/alerttest", alertHandler.CreateAlert).Methods(http.MethodPost)
// assets
Expand Down
Loading

0 comments on commit e1f2e74

Please sign in to comment.