diff --git a/assets/k8sclusterinfo.yaml b/assets/k8sclusterinfo.yaml new file mode 100644 index 000000000..d93f92378 --- /dev/null +++ b/assets/k8sclusterinfo.yaml @@ -0,0 +1,80 @@ +# Configuration for Cluster(Kubernetes) of Cloud Service Providers (CSPs) +# This file is used to define the feature of clusters + +# The file is in YAML format and contains the following fields: +# k8scluster: Top level key +# : Name of the CSP +# nodegroupsWithCluster: +# version: +# - region: [region1, region2, all(special keyword)] + +k8scluster: + nhncloud: + nodegroupsWithCluster: true + version: + - region: [kr1, kr2] + available: + - name: 1.28 + id: 1.28.9-aliyun.1 + - name: 1.26 + id: 1.26.15-aliyun.1 + - name: 1.24 + id: 1.24.6-aliyun.1 + - region: [jp1] + nodeImage: + - region: [kr1] + available: + - name: default + id: default + - name: aliyun 3.9 + id: aliyun_3_9_x64_20G_alibase_20231219.vhd + - region: [kr2] + available: + - name: default + id: default + - name: aliyun 3.9 + id: aliyun_3_9_x64_20G_alibase_20231219.vhd + - region: [jp1] + rootDisk: + - region: [all] + type: + - name: default + id: default + - name: basic + id: CLOUD_BASIC + size: + min: 10 + max: 40 + alibaba: + nodegroupsWithCluster: true + version: + - region: [all] + available: + - name: 1.28 + id: 1.28.9-aliyun.1 + - name: 1.26 + id: 1.26.15-aliyun.1 + - name: 1.24 + id: 1.24.6-aliyun.1 + nodeImage: + - region: [eu-west-1] + #configurable: true + available: + - name: default + id: default + - name: aliyun 3.9 + id: aliyun_3_9_x64_20G_alibase_20231219.vhd + - region: [eu-west-2,kr2] + rootDisk: + - region: [eu-west-1] + type: + #configurable: true + - name: default + id: default + - name: basic + id: CLOUD_BASIC + size: + #configurable: true + min: 10 + max: 40 + diff --git a/src/api/rest/docs/docs.go b/src/api/rest/docs/docs.go index d57ca2e11..39be8b2eb 100644 --- a/src/api/rest/docs/docs.go +++ b/src/api/rest/docs/docs.go @@ -23,6 +23,110 @@ const docTemplate = `{ "host": "{{.Host}}", "basePath": "{{.BasePath}}", "paths": { + "/availableK8sClusterNodeImage": { + "get": { + "description": "Get available kubernetes cluster node image", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "[Infra resource] Cluster management" + ], + "summary": "Get available kubernetes cluster node image", + "operationId": "GetAvailableK8sClusterNodeImage", + "parameters": [ + { + "type": "string", + "description": "Name of the CSP to retrieve", + "name": "providerName", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "Name of region to retrieve", + "name": "regionName", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/common.K8sClusterNodeImageDetailAvailable" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + } + } + } + }, + "/availableK8sClusterVersion": { + "get": { + "description": "Get available kubernetes cluster version", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "[Infra resource] Cluster management" + ], + "summary": "Get available kubernetes cluster version", + "operationId": "GetAvailableK8sClusterVersion", + "parameters": [ + { + "type": "string", + "description": "Name of the CSP to retrieve", + "name": "providerName", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "Name of region to retrieve", + "name": "regionName", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/common.K8sClusterVersionDetailAvailable" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + } + } + } + }, "/cloudInfo": { "get": { "description": "Get cloud information", @@ -564,6 +668,42 @@ const docTemplate = `{ } } }, + "/k8sClusterInfo": { + "get": { + "description": "Get kubernetes cluster information", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "[Admin] Multi-Cloud environment configuration" + ], + "summary": "Get kubernetes cluster information", + "operationId": "GetK8sClusterInfo", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/common.K8sClusterInfo" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + } + } + } + }, "/loadCommonResource": { "get": { "description": "Load Common Resources from internal asset files (Spec, Image)", @@ -1349,6 +1489,7 @@ const docTemplate = `{ "[Infra resource] Cluster management" ], "summary": "List all Clusters or Clusters' ID", + "operationId": "GetAllCluster", "parameters": [ { "type": "string", @@ -1428,6 +1569,7 @@ const docTemplate = `{ "[Infra resource] Cluster management" ], "summary": "Create Cluster", + "operationId": "PostCluster", "parameters": [ { "type": "string", @@ -1489,6 +1631,7 @@ const docTemplate = `{ "[Infra resource] Cluster management" ], "summary": "Delete all Clusters", + "operationId": "DeleteAllCluster", "parameters": [ { "type": "string", @@ -1535,6 +1678,7 @@ const docTemplate = `{ "[Infra resource] Cluster management" ], "summary": "Get Cluster", + "operationId": "GetCluster", "parameters": [ { "type": "string", @@ -1586,6 +1730,7 @@ const docTemplate = `{ "[Infra resource] Cluster management" ], "summary": "Delete Cluster", + "operationId": "DeleteCluster", "parameters": [ { "type": "string", @@ -1632,6 +1777,7 @@ const docTemplate = `{ "[Infra resource] Cluster management" ], "summary": "Add a NodeGroup", + "operationId": "PostNodeGroup", "parameters": [ { "type": "string", @@ -1693,6 +1839,7 @@ const docTemplate = `{ "[Infra resource] Cluster management" ], "summary": "Remove a NodeGroup", + "operationId": "DeleteNodeGroup", "parameters": [ { "type": "string", @@ -1746,6 +1893,7 @@ const docTemplate = `{ "[Infra resource] Cluster management" ], "summary": "Change a NodeGroup's Autoscale Size", + "operationId": "PutChangeAutoscaleSize", "parameters": [ { "type": "string", @@ -1805,6 +1953,7 @@ const docTemplate = `{ "[Infra resource] Cluster management" ], "summary": "Set a NodeGroup's Autoscaling On/Off", + "operationId": "PutSetAutoscaling", "parameters": [ { "type": "string", @@ -1864,6 +2013,7 @@ const docTemplate = `{ "[Infra resource] Cluster management" ], "summary": "Upgrade a Cluster's version", + "operationId": "PutClusterUpgrade", "parameters": [ { "type": "string", @@ -8771,6 +8921,141 @@ const docTemplate = `{ "common.JSONResult": { "type": "object" }, + "common.K8sClusterDetail": { + "type": "object", + "properties": { + "node_images": { + "type": "array", + "items": { + "$ref": "#/definitions/common.K8sClusterNodeImageDetail" + } + }, + "nodegroups_with_cluster": { + "type": "boolean" + }, + "root_disks": { + "type": "array", + "items": { + "$ref": "#/definitions/common.K8sClusterRootDiskDetail" + } + }, + "versions": { + "type": "array", + "items": { + "$ref": "#/definitions/common.K8sClusterVersionDetail" + } + } + } + }, + "common.K8sClusterInfo": { + "type": "object", + "properties": { + "k8s_cluster": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/common.K8sClusterDetail" + } + } + } + }, + "common.K8sClusterNodeImageDetail": { + "type": "object", + "properties": { + "availables": { + "type": "array", + "items": { + "$ref": "#/definitions/common.K8sClusterNodeImageDetailAvailable" + } + }, + "region": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "common.K8sClusterNodeImageDetailAvailable": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + } + } + }, + "common.K8sClusterRootDiskDetail": { + "type": "object", + "properties": { + "region": { + "type": "array", + "items": { + "type": "string" + } + }, + "size": { + "$ref": "#/definitions/common.K8sClusterRootDiskDetailSize" + }, + "type": { + "type": "array", + "items": { + "$ref": "#/definitions/common.K8sClusterRootDiskDetailType" + } + } + } + }, + "common.K8sClusterRootDiskDetailSize": { + "type": "object", + "properties": { + "max": { + "type": "integer" + }, + "min": { + "type": "integer" + } + } + }, + "common.K8sClusterRootDiskDetailType": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + } + } + }, + "common.K8sClusterVersionDetail": { + "type": "object", + "properties": { + "availables": { + "type": "array", + "items": { + "$ref": "#/definitions/common.K8sClusterVersionDetailAvailable" + } + }, + "region": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "common.K8sClusterVersionDetailAvailable": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + } + } + }, "common.KeyValue": { "type": "object", "properties": { diff --git a/src/api/rest/docs/swagger.json b/src/api/rest/docs/swagger.json index e2c4a4687..1b0f2dc82 100644 --- a/src/api/rest/docs/swagger.json +++ b/src/api/rest/docs/swagger.json @@ -16,6 +16,110 @@ }, "basePath": "/tumblebug", "paths": { + "/availableK8sClusterNodeImage": { + "get": { + "description": "Get available kubernetes cluster node image", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "[Infra resource] Cluster management" + ], + "summary": "Get available kubernetes cluster node image", + "operationId": "GetAvailableK8sClusterNodeImage", + "parameters": [ + { + "type": "string", + "description": "Name of the CSP to retrieve", + "name": "providerName", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "Name of region to retrieve", + "name": "regionName", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/common.K8sClusterNodeImageDetailAvailable" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + } + } + } + }, + "/availableK8sClusterVersion": { + "get": { + "description": "Get available kubernetes cluster version", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "[Infra resource] Cluster management" + ], + "summary": "Get available kubernetes cluster version", + "operationId": "GetAvailableK8sClusterVersion", + "parameters": [ + { + "type": "string", + "description": "Name of the CSP to retrieve", + "name": "providerName", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "Name of region to retrieve", + "name": "regionName", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/common.K8sClusterVersionDetailAvailable" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + } + } + } + }, "/cloudInfo": { "get": { "description": "Get cloud information", @@ -557,6 +661,42 @@ } } }, + "/k8sClusterInfo": { + "get": { + "description": "Get kubernetes cluster information", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "[Admin] Multi-Cloud environment configuration" + ], + "summary": "Get kubernetes cluster information", + "operationId": "GetK8sClusterInfo", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/common.K8sClusterInfo" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + } + } + } + }, "/loadCommonResource": { "get": { "description": "Load Common Resources from internal asset files (Spec, Image)", @@ -1342,6 +1482,7 @@ "[Infra resource] Cluster management" ], "summary": "List all Clusters or Clusters' ID", + "operationId": "GetAllCluster", "parameters": [ { "type": "string", @@ -1421,6 +1562,7 @@ "[Infra resource] Cluster management" ], "summary": "Create Cluster", + "operationId": "PostCluster", "parameters": [ { "type": "string", @@ -1482,6 +1624,7 @@ "[Infra resource] Cluster management" ], "summary": "Delete all Clusters", + "operationId": "DeleteAllCluster", "parameters": [ { "type": "string", @@ -1528,6 +1671,7 @@ "[Infra resource] Cluster management" ], "summary": "Get Cluster", + "operationId": "GetCluster", "parameters": [ { "type": "string", @@ -1579,6 +1723,7 @@ "[Infra resource] Cluster management" ], "summary": "Delete Cluster", + "operationId": "DeleteCluster", "parameters": [ { "type": "string", @@ -1625,6 +1770,7 @@ "[Infra resource] Cluster management" ], "summary": "Add a NodeGroup", + "operationId": "PostNodeGroup", "parameters": [ { "type": "string", @@ -1686,6 +1832,7 @@ "[Infra resource] Cluster management" ], "summary": "Remove a NodeGroup", + "operationId": "DeleteNodeGroup", "parameters": [ { "type": "string", @@ -1739,6 +1886,7 @@ "[Infra resource] Cluster management" ], "summary": "Change a NodeGroup's Autoscale Size", + "operationId": "PutChangeAutoscaleSize", "parameters": [ { "type": "string", @@ -1798,6 +1946,7 @@ "[Infra resource] Cluster management" ], "summary": "Set a NodeGroup's Autoscaling On/Off", + "operationId": "PutSetAutoscaling", "parameters": [ { "type": "string", @@ -1857,6 +2006,7 @@ "[Infra resource] Cluster management" ], "summary": "Upgrade a Cluster's version", + "operationId": "PutClusterUpgrade", "parameters": [ { "type": "string", @@ -8764,6 +8914,141 @@ "common.JSONResult": { "type": "object" }, + "common.K8sClusterDetail": { + "type": "object", + "properties": { + "node_images": { + "type": "array", + "items": { + "$ref": "#/definitions/common.K8sClusterNodeImageDetail" + } + }, + "nodegroups_with_cluster": { + "type": "boolean" + }, + "root_disks": { + "type": "array", + "items": { + "$ref": "#/definitions/common.K8sClusterRootDiskDetail" + } + }, + "versions": { + "type": "array", + "items": { + "$ref": "#/definitions/common.K8sClusterVersionDetail" + } + } + } + }, + "common.K8sClusterInfo": { + "type": "object", + "properties": { + "k8s_cluster": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/common.K8sClusterDetail" + } + } + } + }, + "common.K8sClusterNodeImageDetail": { + "type": "object", + "properties": { + "availables": { + "type": "array", + "items": { + "$ref": "#/definitions/common.K8sClusterNodeImageDetailAvailable" + } + }, + "region": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "common.K8sClusterNodeImageDetailAvailable": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + } + } + }, + "common.K8sClusterRootDiskDetail": { + "type": "object", + "properties": { + "region": { + "type": "array", + "items": { + "type": "string" + } + }, + "size": { + "$ref": "#/definitions/common.K8sClusterRootDiskDetailSize" + }, + "type": { + "type": "array", + "items": { + "$ref": "#/definitions/common.K8sClusterRootDiskDetailType" + } + } + } + }, + "common.K8sClusterRootDiskDetailSize": { + "type": "object", + "properties": { + "max": { + "type": "integer" + }, + "min": { + "type": "integer" + } + } + }, + "common.K8sClusterRootDiskDetailType": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + } + } + }, + "common.K8sClusterVersionDetail": { + "type": "object", + "properties": { + "availables": { + "type": "array", + "items": { + "$ref": "#/definitions/common.K8sClusterVersionDetailAvailable" + } + }, + "region": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "common.K8sClusterVersionDetailAvailable": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + } + } + }, "common.KeyValue": { "type": "object", "properties": { diff --git a/src/api/rest/docs/swagger.yaml b/src/api/rest/docs/swagger.yaml index ca50c0a26..58322d512 100644 --- a/src/api/rest/docs/swagger.yaml +++ b/src/api/rest/docs/swagger.yaml @@ -115,6 +115,93 @@ definitions: type: object common.JSONResult: type: object + common.K8sClusterDetail: + properties: + node_images: + items: + $ref: '#/definitions/common.K8sClusterNodeImageDetail' + type: array + nodegroups_with_cluster: + type: boolean + root_disks: + items: + $ref: '#/definitions/common.K8sClusterRootDiskDetail' + type: array + versions: + items: + $ref: '#/definitions/common.K8sClusterVersionDetail' + type: array + type: object + common.K8sClusterInfo: + properties: + k8s_cluster: + additionalProperties: + $ref: '#/definitions/common.K8sClusterDetail' + type: object + type: object + common.K8sClusterNodeImageDetail: + properties: + availables: + items: + $ref: '#/definitions/common.K8sClusterNodeImageDetailAvailable' + type: array + region: + items: + type: string + type: array + type: object + common.K8sClusterNodeImageDetailAvailable: + properties: + id: + type: string + name: + type: string + type: object + common.K8sClusterRootDiskDetail: + properties: + region: + items: + type: string + type: array + size: + $ref: '#/definitions/common.K8sClusterRootDiskDetailSize' + type: + items: + $ref: '#/definitions/common.K8sClusterRootDiskDetailType' + type: array + type: object + common.K8sClusterRootDiskDetailSize: + properties: + max: + type: integer + min: + type: integer + type: object + common.K8sClusterRootDiskDetailType: + properties: + id: + type: string + name: + type: string + type: object + common.K8sClusterVersionDetail: + properties: + availables: + items: + $ref: '#/definitions/common.K8sClusterVersionDetailAvailable' + type: array + region: + items: + type: string + type: array + type: object + common.K8sClusterVersionDetailAvailable: + properties: + id: + type: string + name: + type: string + type: object common.KeyValue: properties: key: @@ -2973,6 +3060,76 @@ paths: summary: Check resources' existence tags: - '[Infra resource] MCIR Common' + /availableK8sClusterNodeImage: + get: + consumes: + - application/json + description: Get available kubernetes cluster node image + operationId: GetAvailableK8sClusterNodeImage + parameters: + - description: Name of the CSP to retrieve + in: query + name: providerName + required: true + type: string + - description: Name of region to retrieve + in: query + name: regionName + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/common.K8sClusterNodeImageDetailAvailable' + "404": + description: Not Found + schema: + $ref: '#/definitions/common.SimpleMsg' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/common.SimpleMsg' + summary: Get available kubernetes cluster node image + tags: + - '[Infra resource] Cluster management' + /availableK8sClusterVersion: + get: + consumes: + - application/json + description: Get available kubernetes cluster version + operationId: GetAvailableK8sClusterVersion + parameters: + - description: Name of the CSP to retrieve + in: query + name: providerName + required: true + type: string + - description: Name of region to retrieve + in: query + name: regionName + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/common.K8sClusterVersionDetailAvailable' + "404": + description: Not Found + schema: + $ref: '#/definitions/common.SimpleMsg' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/common.SimpleMsg' + summary: Get available kubernetes cluster version + tags: + - '[Infra resource] Cluster management' /cloudInfo: get: consumes: @@ -3339,6 +3496,30 @@ paths: in CB-Tumblebug and CSP for all connections tags: - '[Admin] System management' + /k8sClusterInfo: + get: + consumes: + - application/json + description: Get kubernetes cluster information + operationId: GetK8sClusterInfo + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/common.K8sClusterInfo' + "404": + description: Not Found + schema: + $ref: '#/definitions/common.SimpleMsg' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/common.SimpleMsg' + summary: Get kubernetes cluster information + tags: + - '[Admin] Multi-Cloud environment configuration' /loadCommonResource: get: consumes: @@ -3858,6 +4039,7 @@ paths: consumes: - application/json description: Delete all Clusters + operationId: DeleteAllCluster parameters: - default: ns01 description: Namespace ID @@ -3888,6 +4070,7 @@ paths: consumes: - application/json description: List all Clusters or Clusters' ID + operationId: GetAllCluster parameters: - default: ns01 description: Namespace ID @@ -3938,6 +4121,7 @@ paths: consumes: - application/json description: Create Cluster + operationId: PostCluster parameters: - default: ns01 description: Namespace ID @@ -3981,6 +4165,7 @@ paths: consumes: - application/json description: Delete Cluster + operationId: DeleteCluster parameters: - default: ns01 description: Namespace ID @@ -4011,6 +4196,7 @@ paths: consumes: - application/json description: Get Cluster + operationId: GetCluster parameters: - default: ns01 description: Namespace ID @@ -4047,6 +4233,7 @@ paths: consumes: - application/json description: Add a NodeGroup + operationId: PostNodeGroup parameters: - default: ns01 description: Namespace ID @@ -4088,6 +4275,7 @@ paths: consumes: - application/json description: Remove a NodeGroup + operationId: DeleteNodeGroup parameters: - default: ns01 description: Namespace ID @@ -4124,6 +4312,7 @@ paths: consumes: - application/json description: Change a NodeGroup's Autoscale Size + operationId: PutChangeAutoscaleSize parameters: - default: ns01 description: Namespace ID @@ -4164,6 +4353,7 @@ paths: consumes: - application/json description: Set a NodeGroup's Autoscaling On/Off + operationId: PutSetAutoscaling parameters: - default: ns01 description: Namespace ID @@ -4204,6 +4394,7 @@ paths: consumes: - application/json description: Upgrade a Cluster's version + operationId: PutClusterUpgrade parameters: - default: ns01 description: Namespace ID diff --git a/src/api/rest/server/common/utility.go b/src/api/rest/server/common/utility.go index dd957c69f..55f95310c 100644 --- a/src/api/rest/server/common/utility.go +++ b/src/api/rest/server/common/utility.go @@ -318,6 +318,27 @@ func RestGetCloudInfo(c echo.Context) error { return common.EndRequestWithLog(c, reqID, err, content) } +// RestGetK8sClusterInfo func is a rest api wrapper for K8sClsuterInfo. +// RestGetK8sClusterInfo godoc +// @ID GetK8sClusterInfo +// @Summary Get kubernetes cluster information +// @Description Get kubernetes cluster information +// @Tags [Admin] Multi-Cloud environment configuration +// @Accept json +// @Produce json +// @Success 200 {object} common.K8sClusterInfo +// @Failure 404 {object} common.SimpleMsg +// @Failure 500 {object} common.SimpleMsg +// @Router /k8sClusterInfo [get] +func RestGetK8sClusterInfo(c echo.Context) error { + reqID, idErr := common.StartRequestWithLog(c) + if idErr != nil { + return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()}) + } + content, err := common.GetK8sClusterInfo() + return common.EndRequestWithLog(c, reqID, err, content) +} + // ObjectList struct consists of object IDs type ObjectList struct { Object []string `json:"object"` diff --git a/src/api/rest/server/mcis/cluster.go b/src/api/rest/server/mcis/cluster.go index 51c7625de..c5fa3cf2b 100644 --- a/src/api/rest/server/mcis/cluster.go +++ b/src/api/rest/server/mcis/cluster.go @@ -23,7 +23,60 @@ import ( "github.com/rs/zerolog/log" ) +// RestGetAvailableK8sClusterVersion func is a rest api wrapper for GetAvailableK8sClusterVersion. +// RestGetAvailableK8sClusterVersion godoc +// @ID GetAvailableK8sClusterVersion +// @Summary Get available kubernetes cluster version +// @Description Get available kubernetes cluster version +// @Tags [Infra resource] Cluster management +// @Accept json +// @Produce json +// @Param providerName query string true "Name of the CSP to retrieve" +// @Param regionName query string true "Name of region to retrieve" +// @Success 200 {object} common.K8sClusterVersionDetailAvailable +// @Failure 404 {object} common.SimpleMsg +// @Failure 500 {object} common.SimpleMsg +// @Router /availableK8sClusterVersion [get] +func RestGetAvailableK8sClusterVersion(c echo.Context) error { + reqID, idErr := common.StartRequestWithLog(c) + if idErr != nil { + return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()}) + } + providerName := c.QueryParam("providerName") + regionName := c.QueryParam("regionName") + + content, err := common.GetAvailableK8sClusterVersion(providerName, regionName) + return common.EndRequestWithLog(c, reqID, err, content) +} + +// RestGetAvailableK8sClusterNodeImage func is a rest api wrapper for GetAvailableK8sClusterNodeImage. +// RestGetAvailableK8sClusterNodeImage godoc +// @ID GetAvailableK8sClusterNodeImage +// @Summary Get available kubernetes cluster node image +// @Description Get available kubernetes cluster node image +// @Tags [Infra resource] Cluster management +// @Accept json +// @Produce json +// @Param providerName query string true "Name of the CSP to retrieve" +// @Param regionName query string true "Name of region to retrieve" +// @Success 200 {object} common.K8sClusterNodeImageDetailAvailable +// @Failure 404 {object} common.SimpleMsg +// @Failure 500 {object} common.SimpleMsg +// @Router /availableK8sClusterNodeImage [get] +func RestGetAvailableK8sClusterNodeImage(c echo.Context) error { + reqID, idErr := common.StartRequestWithLog(c) + if idErr != nil { + return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()}) + } + providerName := c.QueryParam("providerName") + regionName := c.QueryParam("regionName") + + content, err := common.GetAvailableK8sClusterNodeImage(providerName, regionName) + return common.EndRequestWithLog(c, reqID, err, content) +} + // RestPostCluster godoc +// @ID PostCluster // @Summary Create Cluster // @Description Create Cluster // @Tags [Infra resource] Cluster management @@ -64,6 +117,7 @@ func RestPostCluster(c echo.Context) error { function RestPutCluster not yet implemented // RestPutCluster godoc +// @ID PutCluster // @Summary Update Cluster // @Description Update Cluster // @Tags [Infra resource] Cluster management @@ -84,6 +138,7 @@ func RestPutCluster(c echo.Context) error { } // RestPostNodeGroup godoc +// @ID PostNodeGroup // @Summary Add a NodeGroup // @Description Add a NodeGroup // @Tags [Infra resource] Cluster management @@ -120,6 +175,7 @@ func RestPostNodeGroup(c echo.Context) error { } // RestDeleteNodeGroup godoc +// @ID DeleteNodeGroup // @Summary Remove a NodeGroup // @Description Remove a NodeGroup // @Tags [Infra resource] Cluster management @@ -157,6 +213,7 @@ func RestDeleteNodeGroup(c echo.Context) error { } // RestPutSetAutoscaling godoc +// @ID PutSetAutoscaling // @Summary Set a NodeGroup's Autoscaling On/Off // @Description Set a NodeGroup's Autoscaling On/Off // @Tags [Infra resource] Cluster management @@ -194,6 +251,7 @@ func RestPutSetAutoscaling(c echo.Context) error { } // RestPutChangeAutoscaleSize godoc +// @ID PutChangeAutoscaleSize // @Summary Change a NodeGroup's Autoscale Size // @Description Change a NodeGroup's Autoscale Size // @Tags [Infra resource] Cluster management @@ -231,6 +289,7 @@ func RestPutChangeAutoscaleSize(c echo.Context) error { } // RestGetCluster godoc +// @ID GetCluster // @Summary Get Cluster // @Description Get Cluster // @Tags [Infra resource] Cluster management @@ -262,6 +321,7 @@ type RestGetAllClusterResponse struct { } // RestGetAllCluster godoc +// @ID GetAllCluster // @Summary List all Clusters or Clusters' ID // @Description List all Clusters or Clusters' ID // @Tags [Infra resource] Cluster management @@ -311,6 +371,7 @@ func RestGetAllCluster(c echo.Context) error { } // RestDeleteCluster godoc +// @ID DeleteCluster // @Summary Delete Cluster // @Description Delete Cluster // @Tags [Infra resource] Cluster management @@ -346,6 +407,7 @@ func RestDeleteCluster(c echo.Context) error { } // RestDeleteAllCluster godoc +// @ID DeleteAllCluster // @Summary Delete all Clusters // @Description Delete all Clusters // @Tags [Infra resource] Cluster management @@ -374,6 +436,7 @@ func RestDeleteAllCluster(c echo.Context) error { } // RestPutClusterUpgrade godoc +// @ID PutClusterUpgrade // @Summary Upgrade a Cluster's version // @Description Upgrade a Cluster's version // @Tags [Infra resource] Cluster management diff --git a/src/api/rest/server/server.go b/src/api/rest/server/server.go index 86976040e..772222f23 100644 --- a/src/api/rest/server/server.go +++ b/src/api/rest/server/server.go @@ -172,6 +172,7 @@ func RunServer(port string) { e.GET("/tumblebug/provider", rest_common.RestGetProviderList) e.GET("/tumblebug/region", rest_common.RestGetRegionList) e.GET("/tumblebug/provider/:providerName/region/:regionName", rest_common.RestGetRegion) + e.GET("/tumblebug/k8sClusterInfo", rest_common.RestGetK8sClusterInfo) e.POST("/tumblebug/credential", rest_common.RestRegisterCredential) e.POST("/tumblebug/lookupSpecs", rest_mcir.RestLookupSpecList) @@ -303,6 +304,8 @@ func RunServer(port string) { g.PUT("/:nsId/monitoring/status/mcis/:mcisId/vm/:vmId", rest_mcis.RestPutMonitorAgentStatusInstalled) // Cluster + e.GET("/tumblebug/availableK8sClusterVersion", rest_mcis.RestGetAvailableK8sClusterVersion) + e.GET("/tumblebug/availableK8sClusterNodeImage", rest_mcis.RestGetAvailableK8sClusterNodeImage) g.POST("/:nsId/cluster", rest_mcis.RestPostCluster) g.POST("/:nsId/cluster/:clusterId/nodegroup", rest_mcis.RestPostNodeGroup) g.DELETE("/:nsId/cluster/:clusterId/nodegroup/:nodeGroupName", rest_mcis.RestDeleteNodeGroup) diff --git a/src/core/common/config.go b/src/core/common/config.go index 200efa3e1..575d03d37 100644 --- a/src/core/common/config.go +++ b/src/core/common/config.go @@ -65,6 +65,65 @@ type Credential struct { var RuntimeCredential = Credential{} +// K8sClusterInfo is structure for kubernetes cluster information +type K8sClusterInfo struct { + CSPs map[string]K8sClusterDetail `mapstructure:"k8scluster" json:"k8s_cluster"` +} + +// K8sClusterDetail is structure for kubernetes cluster detail information +type K8sClusterDetail struct { + NodeGroupsWithCluster bool `mapstructure:"nodegroupsWithCluster" json:"nodegroups_with_cluster"` + Version []K8sClusterVersionDetail `mapstructure:"version" json:"versions"` + NodeImage []K8sClusterNodeImageDetail `mapstructure:"nodeImage" json:"node_images"` + RootDisk []K8sClusterRootDiskDetail `mapstructure:"rootDisk" json:"root_disks"` +} + +// K8sClusterVersionDetail is structure for kubernetes cluster version detail information +type K8sClusterVersionDetail struct { + Region []string `mapstructure:"region" json:"region"` + Available []K8sClusterVersionDetailAvailable `mapstructure:"available" json:"availables"` +} + +// K8sClusterVersionDetailAvailable is structure for kubernetes cluster version detail's available information +type K8sClusterVersionDetailAvailable struct { + Name string `mapstructure:"name" json:"name"` + Id string `mapstructure:"id" json:"id"` +} + +// K8sClusterNodeImageDetail is structure for kubernetes cluster node image detail information +type K8sClusterNodeImageDetail struct { + Region []string `mapstructure:"region" json:"region"` + Available []K8sClusterNodeImageDetailAvailable `mapstructure:"available" json:"availables"` +} + +// K8sClusterNodeImageDetailAvailable is structure for kubernetes cluster node image detail's available information +type K8sClusterNodeImageDetailAvailable struct { + Name string `mapstructure:"name" json:"name"` + Id string `mapstructure:"id" json:"id"` +} + +// K8sClusterRootDiskDetail is structure for kubernetes cluster root disk detail information +type K8sClusterRootDiskDetail struct { + Region []string `mapstructure:"region" json:"region"` + Type []K8sClusterRootDiskDetailType `mapstructure:"type" json:"type"` + Size K8sClusterRootDiskDetailSize `mapstructure:"size" json:"size"` +} + +// K8sClusterRootDiskDetailType is structure for kubernetes cluster root disk detail's type information +type K8sClusterRootDiskDetailType struct { + Name string `mapstructure:"name" json:"name"` + Id string `mapstructure:"id" json:"id"` +} + +// K8sClusterRootDiskDetailSize is structure for kubernetes cluster root disk detail's size information +type K8sClusterRootDiskDetailSize struct { + Min uint `mapstructure:"min" json:"min"` + Max uint `mapstructure:"max" json:"max"` +} + +// RuntimeK8sClusterInfo is global variable for K8sClusterInfo +var RuntimeK8sClusterInfo = K8sClusterInfo{} + // AdjustKeysToLowercase adjusts the keys of nested maps to lowercase. func AdjustKeysToLowercase(cloudInfo *CloudInfo) { newCSPs := make(map[string]CSPDetail) diff --git a/src/core/common/utility.go b/src/core/common/utility.go index dd336931f..b8ecbfa7b 100644 --- a/src/core/common/utility.go +++ b/src/core/common/utility.go @@ -1279,3 +1279,170 @@ func GenerateNewRandomString(n int) string { } return string(b) } + +// GetK8sClusterInfo is func to get all kubernetes cluster info from the asset +func GetK8sClusterInfo() (K8sClusterInfo, error) { + return RuntimeK8sClusterInfo, nil +} + +func getK8sClusterDetail(providerName string) *K8sClusterDetail { + // Get K8sClusterDetail for providerName + var k8sClusterDetail *K8sClusterDetail = nil + for provider, detail := range RuntimeK8sClusterInfo.CSPs { + provider = strings.ToLower(provider) + if provider == providerName { + k8sClusterDetail = &detail + break + } + } + + return k8sClusterDetail +} + +// GetAvailableK8sClusterVersion is func to get available kubernetes cluster versions for provider and region from K8sClusterInfo +func GetAvailableK8sClusterVersion(providerName string, regionName string) (*[]K8sClusterVersionDetailAvailable, error) { + // + // Check available K8sCluster version and node image in k8sclusterinfo.yaml + // + + providerName = strings.ToLower(providerName) + + // Get K8sClusterDetail for providerName + k8sClusterDetail := getK8sClusterDetail(providerName) + if k8sClusterDetail == nil { + return nil, fmt.Errorf("unsupported provider(%s) for kubernetes cluster", providerName) + } + + // Get Available Versions for regionName + var availableVersion *[]K8sClusterVersionDetailAvailable = nil + for _, versionDetail := range k8sClusterDetail.Version { + for _, region := range versionDetail.Region { + region = strings.ToLower(region) + if region == "all" || region == regionName { + availableVersion = &versionDetail.Available + return availableVersion, nil + } + } + } + + return nil, fmt.Errorf("no available kubernetes cluster version for region(%s) of provider(%s)", regionName, providerName) +} + +// GetAvailableK8sClusterNodeImage is func to get available kubernetes cluster node images for provider and region from K8sClusterInfo +func GetAvailableK8sClusterNodeImage(providerName string, regionName string) (*[]K8sClusterNodeImageDetailAvailable, error) { + // + // Check available K8sCluster node image in k8sclusterinfo.yaml + // + + providerName = strings.ToLower(providerName) + + // Get K8sClusterDetail for providerName + k8sClusterDetail := getK8sClusterDetail(providerName) + if k8sClusterDetail == nil { + return nil, fmt.Errorf("unsupported provider(%s) for kubernetes cluster", providerName) + } + + // Get Available Node Image for regionName + var availableNodeImage *[]K8sClusterNodeImageDetailAvailable = nil + for _, nodeImageDetail := range k8sClusterDetail.NodeImage { + for _, region := range nodeImageDetail.Region { + region = strings.ToLower(region) + if region == "all" || region == regionName { + availableNodeImage = &nodeImageDetail.Available + return availableNodeImage, nil + } + } + } + + return nil, fmt.Errorf("no available kubernetes cluster node image for region(%s) of provider(%s)", regionName, providerName) +} + +/* +func isValidSpecForK8sCluster(spec *mcir.TbSpecInfo) bool { + // + // Check for Provider + // + + providerName := strings.ToLower(spec.ProviderName) + + var k8sClusterDetail *common.K8sClusterDetail = nil + for provider, detail := range common.RuntimeK8sClusterInfo.CSPs { + provider = strings.ToLower(provider) + if provider == providerName { + k8sClusterDetail = &detail + break + } + } + if k8sClusterDetail == nil { + return false + } + + // + // Check for Region + // + + regionName := strings.ToLower(spec.RegionName) + + // Check for Version + isExist := false + for _, versionDetail := range k8sClusterDetail.Version { + for _, region := range versionDetail.Region { + region = strings.ToLower(region) + if region == "all" || region == regionName { + if len(versionDetail.Available) > 0 { + isExist = true + break + } + } + } + if isExist == true { + break + } + } + if isExist == false { + return false + } + + // Check for NodeImage + isExist = false + for _, nodeImageDetail := range k8sClusterDetail.NodeImage { + for _, region := range nodeImageDetail.Region { + region = strings.ToLower(region) + if region == "all" || region == regionName { + if len(nodeImageDetail.Available) > 0 { + isExist = true + break + } + } + } + if isExist == true { + break + } + } + if isExist == false { + return false + } + + // Check for RootDisk + isExist = false + for _, rootDiskDetail := range k8sClusterDetail.RootDisk { + for _, region := range rootDiskDetail.Region { + region = strings.ToLower(region) + if region == "all" || region == regionName { + if len(rootDiskDetail.Type) > 0 { + isExist = true + break + } + } + } + if isExist == true { + break + } + } + if isExist == false { + return false + } + + return true +} +*/ diff --git a/src/main.go b/src/main.go index 0f695e6b8..ef333124e 100644 --- a/src/main.go +++ b/src/main.go @@ -177,7 +177,31 @@ func setConfig() { // fmt.Printf("%+v\n", common.RuntimeCloudInfo) common.PrintCloudInfoTable(common.RuntimeCloudInfo) + // + // Load k8sclusterinfo + // + k8sClusterInfoViper := viper.New() + fileName = "k8sclusterinfo" + k8sClusterInfoViper.AddConfigPath(".") + k8sClusterInfoViper.AddConfigPath("./assets/") + k8sClusterInfoViper.AddConfigPath("../assets/") + k8sClusterInfoViper.SetConfigName(fileName) + k8sClusterInfoViper.SetConfigType("yaml") + err = k8sClusterInfoViper.ReadInConfig() + if err != nil { + panic(fmt.Errorf("fatal error reading cloudinfo config file: %w", err)) + } + + log.Info().Msg(k8sClusterInfoViper.ConfigFileUsed()) + err = k8sClusterInfoViper.Unmarshal(&common.RuntimeK8sClusterInfo) + if err != nil { + log.Error().Err(err).Msg("") + panic(err) + } + + // // Wait until CB-Spider is ready + // maxAttempts := 60 // (3 mins) attempt := 0