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

Release #176

Merged
merged 12 commits into from
Oct 26, 2023
86 changes: 85 additions & 1 deletion 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 Expand Up @@ -6758,7 +6842,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",
Expand Down
86 changes: 85 additions & 1 deletion api/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down 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
56 changes: 55 additions & 1 deletion 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 @@ -1949,7 +1979,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
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
4 changes: 2 additions & 2 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -91,7 +91,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 *** ")
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
Loading
Loading