Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature. implementation importing cluster #171

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions api/swagger/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -4398,6 +4437,12 @@ const docTemplate = `{
"isStack": {
"type": "boolean"
},
"kubeconfig": {
"type": "array",
"items": {
"type": "integer"
}
},
"name": {
"type": "string"
},
Expand Down Expand Up @@ -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": {
Expand Down
84 changes: 84 additions & 0 deletions api/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -4391,6 +4430,12 @@
"isStack": {
"type": "boolean"
},
"kubeconfig": {
"type": "array",
"items": {
"type": "integer"
}
},
"name": {
"type": "string"
},
Expand Down Expand Up @@ -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": {
Expand Down
54 changes: 54 additions & 0 deletions api/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,10 @@ definitions:
type: string
isStack:
type: boolean
kubeconfig:
items:
type: integer
type: array
name:
type: string
organizationId:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
44 changes: 44 additions & 0 deletions internal/delivery/http/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/repository/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
1 change: 1 addition & 0 deletions internal/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading
Loading