Skip to content

Commit

Permalink
Merge pull request #155 from openinfradev/TKS-874
Browse files Browse the repository at this point in the history
feature. add api stack-nodes. ( integration test )
  • Loading branch information
Siyeop authored Sep 27, 2023
2 parents e9e07af + c51e765 commit 962fd9c
Show file tree
Hide file tree
Showing 6 changed files with 327 additions and 0 deletions.
84 changes: 84 additions & 0 deletions api/swagger/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3003,6 +3003,50 @@ const docTemplate = `{
}
}
},
"/organizations/{organizationId}/stacks/{stackId}/nodes": {
"get": {
"security": [
{
"JWT": []
}
],
"description": "Get nodes information for BYOH",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Stacks"
],
"summary": "Get nodes information for BYOH",
"parameters": [
{
"type": "string",
"description": "organizationId",
"name": "organizationId",
"in": "path",
"required": true
},
{
"type": "string",
"description": "stackId",
"name": "stackId",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/domain.GetStackNodesResponse"
}
}
}
}
},
"/organizations/{organizationId}/stacks/{stackId}/status": {
"get": {
"security": [
Expand Down Expand Up @@ -5292,6 +5336,20 @@ const docTemplate = `{
}
}
},
"domain.GetStackNodesResponse": {
"type": "object",
"properties": {
"nodeStatus": {
"type": "string"
},
"nodes": {
"type": "array",
"items": {
"$ref": "#/definitions/domain.StackNodeResponse"
}
}
}
},
"domain.GetStackResponse": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -5775,6 +5833,32 @@ const docTemplate = `{
}
}
},
"domain.StackNodeResponse": {
"type": "object",
"properties": {
"command": {
"type": "string"
},
"id": {
"type": "string"
},
"registered": {
"type": "integer"
},
"status": {
"type": "string"
},
"targeted": {
"type": "integer"
},
"type": {
"type": "string"
},
"validity": {
"type": "integer"
}
}
},
"domain.StackResponse": {
"type": "object",
"properties": {
Expand Down
84 changes: 84 additions & 0 deletions api/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2996,6 +2996,50 @@
}
}
},
"/organizations/{organizationId}/stacks/{stackId}/nodes": {
"get": {
"security": [
{
"JWT": []
}
],
"description": "Get nodes information for BYOH",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Stacks"
],
"summary": "Get nodes information for BYOH",
"parameters": [
{
"type": "string",
"description": "organizationId",
"name": "organizationId",
"in": "path",
"required": true
},
{
"type": "string",
"description": "stackId",
"name": "stackId",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/domain.GetStackNodesResponse"
}
}
}
}
},
"/organizations/{organizationId}/stacks/{stackId}/status": {
"get": {
"security": [
Expand Down Expand Up @@ -5285,6 +5329,20 @@
}
}
},
"domain.GetStackNodesResponse": {
"type": "object",
"properties": {
"nodeStatus": {
"type": "string"
},
"nodes": {
"type": "array",
"items": {
"$ref": "#/definitions/domain.StackNodeResponse"
}
}
}
},
"domain.GetStackResponse": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -5768,6 +5826,32 @@
}
}
},
"domain.StackNodeResponse": {
"type": "object",
"properties": {
"command": {
"type": "string"
},
"id": {
"type": "string"
},
"registered": {
"type": "integer"
},
"status": {
"type": "string"
},
"targeted": {
"type": "integer"
},
"type": {
"type": "string"
},
"validity": {
"type": "integer"
}
}
},
"domain.StackResponse": {
"type": "object",
"properties": {
Expand Down
54 changes: 54 additions & 0 deletions api/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,15 @@ definitions:
kubeConfig:
type: string
type: object
domain.GetStackNodesResponse:
properties:
nodeStatus:
type: string
nodes:
items:
$ref: '#/definitions/domain.StackNodeResponse'
type: array
type: object
domain.GetStackResponse:
properties:
stack:
Expand Down Expand Up @@ -1411,6 +1420,23 @@ definitions:
- tksInfraNode
- tksUserNode
type: object
domain.StackNodeResponse:
properties:
command:
type: string
id:
type: string
registered:
type: integer
status:
type: string
targeted:
type: integer
type:
type: string
validity:
type: integer
type: object
domain.StackResponse:
properties:
adminClusterUrl:
Expand Down Expand Up @@ -3747,6 +3773,34 @@ paths:
summary: Get KubeConfig by stack
tags:
- Stacks
/organizations/{organizationId}/stacks/{stackId}/nodes:
get:
consumes:
- application/json
description: Get nodes information for BYOH
parameters:
- description: organizationId
in: path
name: organizationId
required: true
type: string
- description: stackId
in: path
name: stackId
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/domain.GetStackNodesResponse'
security:
- JWT: []
summary: Get nodes information for BYOH
tags:
- Stacks
/organizations/{organizationId}/stacks/{stackId}/status:
get:
consumes:
Expand Down
61 changes: 61 additions & 0 deletions internal/delivery/http/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,3 +432,64 @@ func (h *StackHandler) DeleteFavorite(w http.ResponseWriter, r *http.Request) {
}
ResponseJSON(w, r, http.StatusOK, nil)
}

// GetNodes godoc
// @Tags Stacks
// @Summary Get nodes information for BYOH
// @Description Get nodes information for BYOH
// @Accept json
// @Produce json
// @Param organizationId path string true "organizationId"
// @Param stackId path string true "stackId"
// @Success 200 {object} domain.GetStackNodesResponse
// @Router /organizations/{organizationId}/stacks/{stackId}/nodes [get]
// @Security JWT
func (h *StackHandler) GetNodes(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
strId, ok := vars["stackId"]
if !ok {
ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("Invalid organizationId"), "C_INVALID_ORGANIZATION_ID", ""))
return
}
stackId := domain.StackId(strId)
if !stackId.Validate() {
ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("Invalid stackId"), "C_INVALID_STACK_ID", ""))
return
}

// [TODO] for integration
out := domain.GetStackNodesResponse{
NodeStatus: "INPROGRESS",
Nodes: []domain.StackNodeResponse{
{
ID: "1",
Type: "TKS_CP_NODE",
Targeted: 3,
Registered: 1,
Status: "INPROGRESS",
Command: "curl -fL http://192.168.0.77/tks-byoh-hostagent-install.sh | sh -s CLUSTER-ID-control-plane",
Validity: 3000,
},
{
ID: "2",
Type: "TKS_INFRA_NODE",
Targeted: 0,
Registered: 0,
Status: "PENDING",
Command: "curl -fL http://192.168.0.77/tks-byoh-hostagent-install.sh | sh -s CLUSTER-ID-control-plane",
Validity: 3000,
},
{
ID: "3",
Type: "TKS_USER_NODE",
Targeted: 3,
Registered: 3,
Status: "COMPLETED",
Command: "curl -fL http://192.168.0.77/tks-byoh-hostagent-install.sh | sh -s CLUSTER-ID-control-plane",
Validity: 3000,
},
},
}

ResponseJSON(w, r, http.StatusOK, out)
}
1 change: 1 addition & 0 deletions internal/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ func SetupRouter(db *gorm.DB, argoClient argowf.ArgoClient, kc keycloak.IKeycloa
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/stacks/{stackId}/status", authMiddleware.Handle(http.HandlerFunc(stackHandler.GetStackStatus))).Methods(http.MethodGet)
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.HandleFunc(API_PREFIX+API_VERSION+"/alerttest", alertHandler.CreateAlert).Methods(http.MethodPost)
// assets
Expand Down
Loading

0 comments on commit 962fd9c

Please sign in to comment.